-
Notifications
You must be signed in to change notification settings - Fork 0
Implement public report endpoint with models and rate limiting #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Batirro
wants to merge
11
commits into
main
Choose a base branch
from
feat/public-report-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d1030f9
feat: add issue models and public report endpoint
Batirro 1d9fd6d
feat: register report models in django admin
Batirro 98be648
feat: add IP rate limiting for public report endpoint
Batirro d19a060
feat: secure report creation and add admin interface
Batirro b319b99
chore: Add IDE config folder to .gitignore
Batirro 5f1d0d3
test: fix rate limits logic and add API test suite
Batirro 678dc55
style: apply ruff formatting
Batirro db1aa28
refactor: optimize attachment processing and improve API configuration
Batirro 363d6b8
refactor: clean up models, serializers and test configuration
Batirro 1d4d748
chore: add missing database migration for filename rename
Batirro 52071cf
style: applied ruff formating for migration
Batirro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,4 +179,7 @@ cython_debug/ | |
| db.json | ||
|
|
||
| # macOS | ||
| .DS_Store | ||
| .DS_Store | ||
|
|
||
| # Zed | ||
| .zed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from django.contrib import admin | ||
|
|
||
| from .models import Application, Issue, IssueAttachment | ||
|
|
||
|
|
||
| @admin.register(Application) | ||
| class ApplicationAdmin(admin.ModelAdmin): | ||
| list_display = ("name", "is_active", "repo_url") | ||
| list_filter = ("is_active",) | ||
| search_fields = ("name", "repo_url") | ||
|
|
||
|
|
||
| @admin.register(Issue) | ||
| class IssueAdmin(admin.ModelAdmin): | ||
| list_display = ("title", "application", "status", "created_at") | ||
| list_filter = ("status", "application") | ||
| search_fields = ("title", "description") | ||
| readonly_fields = ("created_at", "updated_at") | ||
|
|
||
|
|
||
| @admin.register(IssueAttachment) | ||
| class IssueAttachmentAdmin(admin.ModelAdmin): | ||
| list_display = ("filename", "issue", "content_type", "size", "created_at") | ||
| search_fields = ("filename", "issue__title") | ||
| readonly_fields = ("created_at",) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class ReportsConfig(AppConfig): | ||
| name = "reports" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| # Generated by Django 6.0.3 on 2026-03-31 18:50 | ||
|
|
||
| import django.core.validators | ||
| import django.db.models.deletion | ||
| import uuid | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="Application", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.UUIDField( | ||
| default=uuid.uuid4, | ||
| editable=False, | ||
| primary_key=True, | ||
| serialize=False, | ||
| ), | ||
| ), | ||
| ("name", models.CharField(max_length=120, unique=True)), | ||
| ("repo_url", models.URLField(max_length=500)), | ||
| ("is_active", models.BooleanField(default=True)), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name="Issue", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ( | ||
| "title", | ||
| models.CharField( | ||
| max_length=200, | ||
| validators=[django.core.validators.MinLengthValidator(3)], | ||
| ), | ||
| ), | ||
| ( | ||
| "description", | ||
| models.TextField( | ||
| validators=[django.core.validators.MinLengthValidator(10)] | ||
| ), | ||
| ), | ||
| ("diagnostics", models.JSONField(blank=True, null=True)), | ||
| ( | ||
| "status", | ||
| models.CharField( | ||
| choices=[ | ||
| ("NEW", "New"), | ||
| ("VERIFIED", "Verified"), | ||
| ("GITHUB_CREATED", "GitHub created"), | ||
| ("REJECTED", "Rejected"), | ||
| ], | ||
| db_index=True, | ||
| default="NEW", | ||
| max_length=20, | ||
| ), | ||
| ), | ||
| ( | ||
| "github_issue_number", | ||
| models.PositiveIntegerField(blank=True, null=True), | ||
| ), | ||
| ( | ||
| "github_issue_url", | ||
| models.URLField(blank=True, max_length=500, null=True), | ||
| ), | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ("updated_at", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "application", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="issues", | ||
| to="reports.application", | ||
| ), | ||
| ), | ||
| ( | ||
| "author", | ||
| models.ForeignKey( | ||
| blank=True, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="reported_issues", | ||
| to=settings.AUTH_USER_MODEL, | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "ordering": ["-created_at"], | ||
| }, | ||
| ), | ||
| migrations.CreateModel( | ||
| name="IssueAttachment", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ("original_filename", models.CharField(max_length=255)), | ||
| ("s3_key", models.CharField(max_length=500)), | ||
| ("file_url", models.URLField(max_length=1000)), | ||
| ("content_type", models.CharField(max_length=100)), | ||
| ("size", models.PositiveIntegerField(help_text="File size in bytes")), | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ( | ||
| "issue", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="attachments", | ||
| to="reports.issue", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "ordering": ["created_at"], | ||
| }, | ||
| ), | ||
| ] |
17 changes: 17 additions & 0 deletions
17
reports/migrations/0002_rename_original_filename_issueattachment_filename.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Generated by Django 6.0.3 on 2026-03-31 20:49 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("reports", "0001_initial"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RenameField( | ||
| model_name="issueattachment", | ||
| old_name="original_filename", | ||
| new_name="filename", | ||
| ), | ||
| ] |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import uuid | ||
|
|
||
| from django.conf import settings | ||
| from django.core.validators import MinLengthValidator | ||
| from django.db import models | ||
|
|
||
|
|
||
| class IssueStatus(models.TextChoices): | ||
| NEW = "NEW", "New" | ||
| VERIFIED = "VERIFIED", "Verified" | ||
| GITHUB_CREATED = "GITHUB_CREATED", "GitHub created" | ||
| REJECTED = "REJECTED", "Rejected" | ||
|
|
||
|
|
||
| class Application(models.Model): | ||
| id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) | ||
| name = models.CharField(max_length=120, unique=True) | ||
| repo_url = models.URLField(max_length=500) | ||
| is_active = models.BooleanField(default=True) | ||
|
|
||
| def __str__(self) -> str: | ||
| return self.name | ||
|
|
||
|
|
||
| class Issue(models.Model): | ||
| application = models.ForeignKey( | ||
| Application, | ||
| on_delete=models.CASCADE, | ||
| related_name="issues", | ||
| ) | ||
| author = models.ForeignKey( | ||
| settings.AUTH_USER_MODEL, | ||
| on_delete=models.SET_NULL, | ||
| null=True, | ||
| blank=True, | ||
| related_name="reported_issues", | ||
| ) | ||
| title = models.CharField(max_length=200, validators=[MinLengthValidator(3)]) | ||
| description = models.TextField(validators=[MinLengthValidator(10)]) | ||
| diagnostics = models.JSONField(blank=True, null=True) | ||
| status = models.CharField( | ||
| max_length=20, | ||
| choices=IssueStatus.choices, | ||
| default=IssueStatus.NEW, | ||
| db_index=True, | ||
| ) | ||
| github_issue_number = models.PositiveIntegerField(null=True, blank=True) | ||
| github_issue_url = models.URLField(max_length=500, null=True, blank=True) | ||
| created_at = models.DateTimeField(auto_now_add=True) | ||
| updated_at = models.DateTimeField(auto_now=True) | ||
|
|
||
| class Meta: | ||
| ordering = ["-created_at"] | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"[{self.status}] {self.title}" | ||
|
|
||
|
|
||
| class IssueAttachment(models.Model): | ||
| issue = models.ForeignKey( | ||
| Issue, | ||
| on_delete=models.CASCADE, | ||
| related_name="attachments", | ||
| ) | ||
| filename = models.CharField(max_length=255) | ||
| s3_key = models.CharField(max_length=500) | ||
| file_url = models.URLField(max_length=1000) | ||
| content_type = models.CharField(max_length=100) | ||
| size = models.PositiveIntegerField(help_text="File size in bytes") | ||
| created_at = models.DateTimeField(auto_now_add=True) | ||
|
|
||
| class Meta: | ||
| ordering = ["created_at"] | ||
|
|
||
| def __str__(self) -> str: | ||
| return self.filename |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.