Skip to content
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

api for post upload #888

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ messagesde:
requirements: pyproject.toml
uv pip compile -o requirements.txt pyproject.toml
uv pip compile -o requirements-test.txt --extra test pyproject.toml

openapi:
python manage.py generateschema --file froide/openapi-schema.yaml
pnpm run openapi
12 changes: 8 additions & 4 deletions froide/foirequest/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from froide.account.models import UserTag
from froide.comments.models import FroideComment
from froide.foirequest.models.message import FoiMessageDraft
from froide.guide.models import Action
from froide.guide.utils import assign_guidance_action
from froide.helper.admin_utils import (
Expand Down Expand Up @@ -522,7 +523,6 @@ class MessageTagsFilter(MultiFilterMixin, TaggitListFilter):
class FoiMessageAdmin(admin.ModelAdmin):
save_on_top = True
list_display = (
"is_draft",
"subject",
"timestamp",
"message_page",
Expand Down Expand Up @@ -600,9 +600,7 @@ def get_urls(self):
return my_urls + urls

def get_queryset(self, request):
qs = super(FoiMessageAdmin, self).get_queryset(request)
qs = qs.prefetch_related("deliverystatus")
return qs
return self.model.objects.with_drafts(False).prefetch_related("deliverystatus")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The super().get_queryset(request) should be kept and extended with the filter, right? There's more happening in Django ModelAdmin's get_queryset, like ordering. .width_drafts(False) is fancy but only works on the manager and not the queryset which makes it difficult to compose.


def save_model(self, request, obj, form, change):
if (
Expand Down Expand Up @@ -752,6 +750,12 @@ def add_comment(
)


@admin.register(FoiMessageDraft)
class FoiMessageDraftAdmin(FoiMessageAdmin):
def get_queryset(self, request):
return self.model.objects.all().prefetch_related("deliverystatus")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also call super and possibly just show drafts?



@admin.register(MessageTag)
class MessageTagAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("name",)}
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions froide/foirequest/api/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from rest_framework import permissions
from rest_framework.views import Request

from ..auth import can_write_foirequest


class OwnsFoiRequestPermission(permissions.BasePermission):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to WriteFoiRequestPermission? The concept of owning is not clearly defined in the code base apart from request.user == object.user which is not what is checked here.

def __init__(self, request_field: str = "request") -> None:
self.request_field = request_field
super().__init__()

def has_object_permission(self, request: Request, view, obj):
if request.method in permissions.SAFE_METHODS:
return True

return can_write_foirequest(getattr(obj, self.request_field), request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this can work with belongs_to__request used in the FoiAttachmentViewSet as this is just attribute access.

Loading