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

Develop #719

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Develop #719

wants to merge 10 commits into from

Conversation

frezworx
Copy link

No description provided.

Updated the `USE_TZ` setting to `True` to enable timezone-aware datetimes. This ensures consistent datetime handling across the application and improves compatibility with databases and external systems.
Implemented user registration, login, and profile management endpoints using Django Rest Framework. Updated project URLs to include the new user app routes. Added necessary serializers and views to support user creation, authentication, and profile updates.
Implemented permission logic using `IsAdminOrIfAuthenticatedReadOnly` for finer access control across all viewsets in the `cinema` app. Refactored `user` app URLs for consistency in naming and functionality. Added a custom permission class to enforce role-based access.
Simplified the logic in `IsAdminOrIfAuthenticatedReadOnly` for better readability and maintainability. Added token authentication settings in Django REST framework to support secure API access.
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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 meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Endpoint Naming: The task specifies endpoints like POST api/user/register/ and POST api/user/login/. Please rename the create/ endpoint to register/ in the user/urls.py file to align with these requirements.

  2. Permission Handling: There are several instances where the get_permissions method allows actions for authenticated users that might be intended only for admins (e.g., CinemaHallViewSet, GenreViewSet, ActorViewSet, MovieSessionViewSet). Please review and adjust these permissions to ensure they align with the application's access control policy.

  3. Debug Toolbar: Ensure that the Debug Toolbar is only included in the URL patterns for development environments to prevent exposing sensitive information in production.

  4. File Endings and Duplicates: Ensure all files have a blank line at the end and remove any duplicate files to maintain a clean codebase.

These changes are important to ensure the functionality and security of the application. Once these issues are addressed, we can proceed with the approval. Keep up the great work, and don't hesitate to reach out if you have any questions! 😊

✨ 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.

cinema/views.py Outdated
Comment on lines 31 to 33
if self.action in ("list", "create"):
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_permissions method in GenreViewSet allows 'create' action for authenticated users, which might not be intended. Ensure that only admins can create new genres if that is the requirement.

cinema/views.py Outdated
Comment on lines 41 to 43
if self.action in ("list", "create"):
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to GenreViewSet, the get_permissions method in ActorViewSet allows 'create' action for authenticated users. Verify if this aligns with the intended permissions.

Comment on lines +51 to +53
if self.action in ("list", "create"):
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CinemaHallViewSet, the get_permissions method allows 'create' action for authenticated users. Confirm if this is the desired behavior or if it should be restricted to admins.

cinema/views.py Outdated
Comment on lines 61 to 63
if self.action in ("list", "create", "retrieve"):
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_permissions method in MovieViewSet includes 'retrieve' in the actions that allow read-only access for authenticated users. Ensure this is intended, as it might expose detailed movie information to all authenticated users.

Comment on lines +122 to +123
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In MovieSessionViewSet, the get_permissions method allows all actions for authenticated users. Double-check if actions like 'create', 'update', and 'destroy' should be restricted to admins.

cinema/views.py Outdated
Comment on lines 167 to 168
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_permissions method in OrderViewSet allows 'create' action for authenticated users, which might be intended for users to create their orders. Ensure this aligns with the application's access control policy.

@@ -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")),
path("__debug__/", include("debug_toolbar.urls")),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Debug Toolbar is included in the URL patterns. Ensure that this is only enabled in a development environment and not in production, as it can expose sensitive information.

Comment on lines 6 to 12
return bool(
request.method in SAFE_METHODS and
request.user and
request.user.is_authenticated
) or (
request.user and request.user.is_staff
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in has_permission could be simplified for clarity. Consider checking if the user is authenticated first, then checking if they are a staff member. This would make the intent of the permission class clearer.

Comment on lines +15 to +23
def update(self, instance, validated_data):
password = validated_data.pop("password", None)
user = super().update(instance, validated_data)

if password:
user.set_password(password)
user.save()

return user

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the update method, ensure that the password is only updated if a new password is provided. The current implementation correctly handles this, but make sure to document this behavior clearly for future reference.

Adjusted line breaks and indentation in various files to enhance the code's readability and maintain consistency across the project. No logic or functional changes were made.
Updated the URL pattern to improve clarity and align with common conventions. This change ensures better readability and consistency across the API.
Replaced `ModelViewSet` with specific mixins to streamline functionality and reduce overhead. Updated the custom permission `IsAdminOrIfAuthenticatedReadOnly` for clearer behavior and stricter access control. Commented out the debug toolbar URL for better production compatibility.
Replaced `ModelViewSet` with specific mixins to streamline functionality and reduce overhead. Updated the custom permission `IsAdminOrIfAuthenticatedReadOnly` for clearer behavior and stricter access control. Commented out the debug toolbar URL for better production compatibility.
Previously, only safe methods were allowed for authenticated users. This update adds support for POST requests while maintaining restrictions on other methods like PUT, PATCH, and DELETE. These changes ensure better flexibility without compromising security.
Refactored `get_permissions` in `cinema/views.py` to streamline behavior and rely more on `super()`. Updated comments in `user/permissions.py` for clarity and removed redundant code, improving maintainability and readability.
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on your submission! 🎉 Your code is well-structured and aligns with the task requirements in many areas. However, there are a few critical issues that need attention:

  1. Permission Handling: Ensure that the get_permissions method in your viewsets, such as CinemaHallViewSet, MovieSessionViewSet, and OrderViewSet, correctly restricts actions like 'create', 'update', and 'destroy' to admins if that's the intended policy. This is crucial for maintaining proper access control.

  2. Debug Toolbar: The Debug Toolbar should only be active in development environments. Make sure to conditionally include it in your settings and URL patterns based on the environment to prevent exposing sensitive information in production.

  3. Code Cleanliness: Remove any redundant commented-out code, such as the one above the IsAdminOrIfAuthenticatedReadOnly class, to keep your codebase clean and maintainable.

  4. Duplicate Files: Address any duplicate files, like user/urls.py and user/views.py, to ensure a tidy codebase.

These adjustments will not only improve your current project but also enhance your coding skills for future tasks. Keep up the great work and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +55 to +58
def get_permissions(self):
if self.action in ("list", "create"):
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_permissions method in CinemaHallViewSet allows both 'list' and 'create' actions for authenticated users. Ensure that this aligns with the application's access control policy, as 'create' actions might be intended only for admins.

Comment on lines +118 to +128
def get_permissions(self):
if self.action in (
"list",
"create",
"retrieve",
"update",
"partial_update",
"destroy"
):
return (IsAdminOrIfAuthenticatedReadOnly(),)
return (IsAuthenticated(),)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_permissions method in MovieSessionViewSet allows actions like 'create', 'update', and 'destroy' for authenticated users. Review and adjust these permissions to ensure they align with the application's access control policy, as these actions might be intended only for admins.

Comment on lines +172 to +175
def get_permissions(self):
if self.action == "create":
return [IsAuthenticated()]
return super().get_permissions()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In OrderViewSet, the get_permissions method allows the 'create' action for authenticated users, which seems appropriate. However, ensure that other actions are restricted as needed by the application's access control policy.

@@ -4,5 +4,6 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("api/cinema/", include("cinema.urls", namespace="cinema")),
path("__debug__/", include("debug_toolbar.urls")),
path("api/user/", include("user.urls", namespace="user")),
# path("__debug__/", include("debug_toolbar.urls")),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Debug Toolbar URL pattern is commented out. Ensure that this is conditionally included only in development environments to avoid exposing it in production. You can use an environment check to include this URL pattern when DEBUG is True.

Comment on lines +4 to +24
# class IsAdminOrIfAuthenticatedReadOnly(BasePermission):
# def has_permission(self, request, view):
# # If the user is an admin, we allow everything.
# if request.user and request.user.is_staff:
# return True
#
# # If the request is "read" (GET/HEAD/OPTIONS),
# # then we allow authenticated
# if request.method in SAFE_METHODS:
# return bool(request.user and request.user.is_authenticated)
#
# # Allow POST to regular authenticated users
# if (
# request.method == "POST"
# and request.user
# and request.user.is_authenticated
# ):
# return True
#
# # Everything else (POST, PUT, PATCH, DELETE) is prohibited
# return False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out code for the IsAdminOrIfAuthenticatedReadOnly class is redundant and should be removed to maintain a clean codebase. The active implementation below is sufficient and correctly implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants