-
Notifications
You must be signed in to change notification settings - Fork 87
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
base: main
Are you sure you want to change the base?
api for post upload #888
Changes from all commits
7519879
1f42757
90d2692
aba9dc5
e9bbc04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ( | ||
|
@@ -522,7 +523,6 @@ class MessageTagsFilter(MultiFilterMixin, TaggitListFilter): | |
class FoiMessageAdmin(admin.ModelAdmin): | ||
save_on_top = True | ||
list_display = ( | ||
"is_draft", | ||
"subject", | ||
"timestamp", | ||
"message_page", | ||
|
@@ -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") | ||
|
||
def save_model(self, request, obj, form, change): | ||
if ( | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also call |
||
|
||
|
||
@admin.register(MessageTag) | ||
class MessageTagAdmin(admin.ModelAdmin): | ||
prepopulated_fields = {"slug": ("name",)} | ||
|
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename to |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this can work with |
There was a problem hiding this comment.
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'sget_queryset
, like ordering..width_drafts(False)
is fancy but only works on the manager and not the queryset which makes it difficult to compose.