Skip to content

Commit

Permalink
Refactor permissions and configure token authentication.
Browse files Browse the repository at this point in the history
Simplified the logic in `IsAdminOrIfAuthenticatedReadOnly` for better readability and maintainability. Added token authentication settings in Django REST framework to support secure API access.
  • Loading branch information
frezworx committed Dec 26, 2024
1 parent adbb56e commit 072eb27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions cinema_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
}
14 changes: 7 additions & 7 deletions user/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

class IsAdminOrIfAuthenticatedReadOnly(BasePermission):
def has_permission(self, request, view):
if (
request.method in SAFE_METHODS
and request.user
and request.user.is_authenticated
):
return True
return request.user and request.user.is_staff
return bool(
request.method in SAFE_METHODS and
request.user and
request.user.is_authenticated
) or (
request.user and request.user.is_staff
)

0 comments on commit 072eb27

Please sign in to comment.