-
Notifications
You must be signed in to change notification settings - Fork 693
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
Develop #683
base: master
Are you sure you want to change the base?
Develop #683
Conversation
Introduce `IsAdminOrIfAuthenticatedReadOnly` permission class to differentiate access levels. Admin users receive full access, while authenticated non-admin users are granted read-only access. This class enhances security by ensuring proper access controls based on user roles.
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.
Thank you for your hard work on this project! 🌟 While your code is mostly well-implemented, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Import Statement Syntax Error: There's a syntax error in your import statement. Ensure you use the correct syntax:
from rest_framework.permissions import BasePermission, SAFE_METHODS
. -
Permission Classes in
OrderViewSet
: TheOrderViewSet
is missing the custom permission classIsAdminOrIfAuthenticatedReadOnly
. This is crucial for ensuring the correct access control as per the task requirements. -
Namespace in
urls.py
: Thenamespace
should be defined in theapp_name
variable within theurls.py
files of the respective apps (cinema
anduser
). This is important for proper URL namespacing. -
Redundant Permission in
GenreViewSet
: Thepermission_classes
forGenreViewSet
includes bothIsAdminOrIfAuthenticatedReadOnly
andIsAuthenticated
. This redundancy should be resolved by removingIsAuthenticated
. -
File Organization: There are duplicate or unnecessary files in your project. Please clean up any duplicate files to maintain a clean and organized codebase.
Once these issues are resolved, your code will be in great shape! Keep up the great work, and I'm looking forward to seeing the improvements. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
@@ -0,0 +1,21 @@ | |||
from rest_framework.permissions import BasePermission, SAFE_METHODS |
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.
There is a syntax error in the import statement. The correct syntax should be from rest_framework.permissions import BasePermission, SAFE_METHODS
without the slash (/
).
cinema/views.py
Outdated
@@ -24,21 +29,29 @@ | |||
class GenreViewSet(viewsets.ModelViewSet): | |||
queryset = Genre.objects.all() | |||
serializer_class = GenreSerializer | |||
authentication_classes = (TokenAuthentication,) | |||
permission_classes = (IsAdminOrIfAuthenticatedReadOnly, IsAuthenticated) |
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 permission_classes
for GenreViewSet
includes both IsAdminOrIfAuthenticatedReadOnly
and IsAuthenticated
. This is redundant because IsAdminOrIfAuthenticatedReadOnly
already handles both admin and authenticated user permissions. You can remove IsAuthenticated
from this tuple.
@@ -4,5 +4,6 @@ | |||
urlpatterns = [ | |||
path("admin/", admin.site.urls), | |||
path("api/cinema/", include("cinema.urls", namespace="cinema")), | |||
path("api/user/", include("user.urls", namespace="user")), |
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 include
function is used with a namespace
argument, but the namespace
should be defined in the included urls.py
files of the respective apps (cinema
and user
). Ensure that the urls.py
files in these apps have a namespace
defined in their app_name
variable.
Refactor ViewSets to use specific mixins for improved code clarity and maintainability. Adjust authentication and permissions in settings, adding TokenAuthentication as the default and setting a new custom permission class for the project. This change helps streamline operations and ensures appropriate access control.
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.
Great effort on your submission! 🎉 While the code has been approved to help you move forward with your learning, there are a few critical issues that need attention:
-
Import Statement Syntax Error: In
cinema/permissions.py
, ensure the import statement is correct:from rest_framework.permissions import BasePermission, SAFE_METHODS
. -
Permission Classes in
OrderViewSet
: Update theOrderViewSet
incinema/views.py
to use the custom permission classIsAdminOrIfAuthenticatedReadOnly
for proper access control. -
Namespace in
urls.py
: Verify that theapp_name
variable is correctly set in theurls.py
files for both thecinema
anduser
apps to avoid namespace-related issues. -
File Organization: Remove any duplicate files to maintain a clean and organized codebase.
Addressing these issues will enhance the functionality and maintainability of your project. Keep up the good work, and continue to learn and improve! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -0,0 +1,21 @@ | |||
from rest_framework.permissions import BasePermission, SAFE_METHODS |
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.
There is a syntax error in the import statement. The correct syntax should be: from rest_framework.permissions import BasePermission, SAFE_METHODS
.
queryset = Order.objects.prefetch_related( | ||
"tickets__movie_session__movie", "tickets__movie_session__cinema_hall" | ||
) | ||
serializer_class = OrderSerializer | ||
pagination_class = OrderPagination | ||
permission_classes = (IsAuthenticated,) |
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 OrderViewSet
is missing the custom permission class IsAdminOrIfAuthenticatedReadOnly
. This is crucial for ensuring the correct access control as per the task requirements. Please add it to the permission_classes
.
@@ -4,5 +4,6 @@ | |||
urlpatterns = [ | |||
path("admin/", admin.site.urls), | |||
path("api/cinema/", include("cinema.urls", namespace="cinema")), | |||
path("api/user/", include("user.urls", namespace="user")), |
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 namespace
argument in the include
function requires that the app_name
variable is defined in the urls.py
files of the respective apps (cinema
and user
). Please ensure that the app_name
is correctly set in those files to avoid any namespace-related issues.
No description provided.