-
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
solution #698
base: master
Are you sure you want to change the base?
solution #698
Conversation
cinema/views.py
Outdated
mixins.UpdateModelMixin, | ||
mixins.DestroyModelMixin, | ||
GenericViewSet, | ||
): |
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.
You can leave MovieSessionViewSet as ModelViewSet as it already implements all these actions
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 you've made great progress, there are a few critical issues that need to be addressed before we can approve the pull request:
-
OrderViewSet Permissions: The
OrderViewSet
does not properly handle permissions for the 'create' action, which could lead to unauthorized access. Please ensure that theIsAuthenticated
permission is correctly applied when creating an order without overriding other permissions. -
MovieSessionViewSet Validation: The
MovieSessionViewSet
lacks proper validation for date and movie ID inputs. This could lead to errors if invalid data is provided. Adding validation will help ensure the application functions correctly and securely. -
Security Settings in
settings.py
: TheSECRET_KEY
is hardcoded and exposed, andDEBUG
is set toTrue
. These are not suitable for production environments. Please adjust these settings to enhance security. -
Namespace in URLs: Ensure that the 'cinema/urls.py' file defines an
app_name
variable to match the namespace specified in theinclude
function. This will help prevent URL name conflicts across different apps. -
Permission Handling: Raising a
NotAuthenticated
exception directly in thehas_permission
method might lead to inconsistent behavior. Consider returningFalse
instead to allow the framework to handle authentication failures uniformly.
Once these issues are resolved, your code will be in great shape! Keep up the excellent work, and feel free to reach out if you have any questions or need further assistance. 😊
✨ 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.
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 job on addressing most of the issues from the previous review! 🎉 Your code is progressing well, and it's clear that you're putting in a lot of effort. Here are some key points to focus on for future improvements:
-
OrderViewSet Permissions: Ensure that the
IsAuthenticated
permission is correctly applied when creating an order. This is crucial to prevent unauthorized access. -
Permission Handling: Instead of raising
PermissionDenied
orNotAuthenticated
exceptions directly in methods likeperform_create
,perform_update
, andperform_destroy
, consider using permission classes for more consistent behavior. -
Security Settings: The
SECRET_KEY
is still hardcoded insettings.py
. It's important to address this by using environment variables to enhance the security of your application. -
Namespace in URLs: Make sure the
app_name
variable is defined incinema/urls.py
to prevent URL name conflicts across different apps.
You've made significant progress, and with a few more adjustments, your code will be even stronger. Keep up the great work, and remember to review the comments to enhance your learning and coding skills. 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
def perform_create(self, serializer): | ||
if not self.request.user.is_staff: | ||
raise PermissionDenied( | ||
"You do not have permission to perform this action." | ||
) |
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.
Raising a PermissionDenied
exception directly in the perform_create
method might lead to inconsistent behavior. Consider using permission classes to handle these checks more uniformly.
def perform_update(self, serializer): | ||
if not self.request.user.is_staff: | ||
raise PermissionDenied( | ||
"You do not have permission to perform this action." | ||
) |
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.
Raising a PermissionDenied
exception directly in the perform_update
method might lead to inconsistent behavior. Consider using permission classes to handle these checks more uniformly.
def perform_destroy(self, instance): | ||
if not self.request.user.is_staff: | ||
raise PermissionDenied( | ||
"You do not have permission to perform this action." | ||
) |
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.
Raising a PermissionDenied
exception directly in the perform_destroy
method might lead to inconsistent behavior. Consider using permission classes to handle these checks more uniformly.
def get_permissions(self): | ||
if self.action == "create": | ||
return [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 get_permissions
method in OrderViewSet
should ensure that the IsAuthenticated
permission is correctly applied when creating an order without overriding other permissions. This could lead to unauthorized access.
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
path("api/token-auth/", views.obtain_auth_token, name="token-auth"), | ||
path("api/cinema/", include("cinema.urls", namespace="cinema")), |
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.
Ensure that the 'cinema/urls.py' file defines an app_name
variable to match the namespace specified here. This will help prevent URL name conflicts across different apps.
class IsAdminOrIfAuthenticatedReadOnly(BasePermission): | ||
def has_permission(self, request, view): | ||
if not request.user.is_authenticated: | ||
raise NotAuthenticated() |
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.
Raising a NotAuthenticated
exception directly in the has_permission
method might lead to inconsistent behavior. Consider returning False
instead to allow the framework to handle authentication failures uniformly.
No description provided.