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

Update permissions.py #72

Merged
merged 2 commits into from
Oct 30, 2024
Merged
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
40 changes: 40 additions & 0 deletions drf_simple_apikey/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,43 @@ def has_object_permission(
self, request: HttpRequest, view: typing.Any, obj
) -> bool:
return request.user.is_active


class ReadOnlyEntity(BasePermission):

message = "This resource is read only."

def has_permission(self, request: HttpRequest, view: typing.Any) -> bool:
return request.method == "GET"

def has_object_permission(
self, request: HttpRequest, view: typing.Any, obj
) -> bool:
return request.method == "GET"


class CreateOnlyEntity(BasePermission):

message = "This resource is create only."

def has_permission(self, request: HttpRequest, view: typing.Any) -> bool:
return request.method == "POST"

def has_object_permission(
self, request: HttpRequest, view: typing.Any, obj
) -> bool:
return request.method == "POST"


class UpdateOnlyEntity(BasePermission):

message = "This resource is update only."

def has_permission(self, request: HttpRequest, view: typing.Any) -> bool:
return request.method == "PUT"

def has_object_permission(
self, request: HttpRequest, view: typing.Any, obj
) -> bool:
return request.method == "PUT"

Loading