-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add create + update endpoints to message api, refactor api code
- Loading branch information
Showing
28 changed files
with
635 additions
and
386 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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,33 @@ | ||
from rest_framework import permissions | ||
from rest_framework.views import Request | ||
|
||
from froide.foirequest.models.attachment import FoiAttachment | ||
from froide.foirequest.models.message import FoiMessage | ||
from froide.foirequest.models.request import FoiRequest | ||
|
||
from ..auth import can_write_foirequest | ||
|
||
|
||
class WriteFoiRequestPermission(permissions.BasePermission): | ||
def get_foirequest(self, obj) -> FoiRequest: | ||
if isinstance(obj, FoiRequest): | ||
return obj | ||
elif isinstance(obj, FoiMessage): | ||
return obj.request | ||
elif isinstance(obj, FoiAttachment): | ||
return obj.belongs_to.request | ||
raise ValueError("Cannot determine request from object") | ||
|
||
def has_object_permission(self, request: Request, view, obj) -> bool: | ||
if request.method in permissions.SAFE_METHODS: | ||
return True | ||
foirequest = self.get_foirequest(obj) | ||
return can_write_foirequest(foirequest, request) | ||
|
||
|
||
class OnlyEditableWhenDraftPermission(permissions.BasePermission): | ||
def has_object_permission(self, request, view, obj): | ||
if request.method in permissions.SAFE_METHODS: | ||
return True | ||
else: | ||
return obj.is_draft |
This file contains 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .test_admin import * # noqa | ||
from .test_api import * # noqa | ||
from .test_api_request import * # noqa | ||
from .test_mail import * # noqa | ||
from .test_request import * # noqa | ||
from .test_web import * # noqa |
Oops, something went wrong.