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

not Solution #715

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

Conversation

Roman-Sokolov-V
Copy link

No description provided.

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.


Hello! 😊 It looks like there are a few critical issues that need to be addressed before we can approve this pull request:

  1. Critical Syntax Error: There's a syntax error in permitions.py where a slash is used instead of a comma in the import statement. This will prevent the code from running correctly.

  2. Missing Permission Class: The IsAuthenticatedReadOrCreate permission class is not defined, which is essential for the OrderViewSet to function as intended.

  3. Endpoints Implementation: The ManageUserView path is commented out, which means the endpoint api/user/me/ is not accessible. This is a core requirement that needs to be addressed.

  4. Action Limitations: The OrderViewSet should only allow list and create actions, but it's currently implemented as a ModelViewSet, allowing all CRUD operations.

These issues are critical as they impact the functionality and core requirements of your application. Once these are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you need any help. 🚀

✨ 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,30 @@
from rest_framework.permissions import BasePermission, SAFE_METHODS

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. Replace the slash / with a comma , to correctly import SAFE_METHODS.


class IsAuthenticatedReadOrCreate(BasePermission):
"""
The user is authenticated and can create read request.

Choose a reason for hiding this comment

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

There is a typo in the docstring: 'create read request' should be 'create or read request'.

cinema/urls.py Outdated
router.register("movies", MovieViewSet)
router.register("movie_sessions", MovieSessionViewSet)
router.register("orders", OrderViewSet)
#router = routers.DefaultRouter()

Choose a reason for hiding this comment

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

The DefaultRouter is commented out. If you intend to use it for registering viewsets, you should uncomment this line and the relevant lines below.

cinema/urls.py Outdated
router.register("orders", OrderViewSet)
#router = routers.DefaultRouter()
actors = ActorViewSet.as_view({'get': 'list', 'post': 'create'})
# router.register("genres", GenreViewSet)

Choose a reason for hiding this comment

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

Consider uncommenting this line if you want to register the GenreViewSet with the router.

cinema/urls.py Outdated
#router = routers.DefaultRouter()
actors = ActorViewSet.as_view({'get': 'list', 'post': 'create'})
# router.register("genres", GenreViewSet)
# router.register("movies", MovieViewSet)

Choose a reason for hiding this comment

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

Consider uncommenting this line if you want to register the MovieViewSet with the router.

cinema/urls.py Outdated
# router.register("cinema_halls", CinemaHallViewSet)
# router.register("movies", MovieViewSet)
# router.register("movie_sessions", MovieSessionViewSet)
# router.register("orders", OrderViewSet)

Choose a reason for hiding this comment

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

Consider uncommenting this line if you want to register the OrderViewSet with the router.

cinema/urls.py Outdated
urlpatterns = [path("", include(router.urls))]
urlpatterns = [
path("actors/", actors, name="actor-list"),
#path("", include(router.urls)),

Choose a reason for hiding this comment

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

Uncomment this line to include the router's URLs in your urlpatterns if you decide to use the router.

@@ -1,10 +1,16 @@
from datetime import datetime

from django.db.models import F, Count
from rest_framework import viewsets
from django.template.context_processors import request

Choose a reason for hiding this comment

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

The import statement for request is incorrect. request should not be imported from django.template.context_processors. Consider removing this line if request is not needed.

cinema/views.py Outdated
Comment on lines 147 to 149
def get_queryset(self):
return Order.objects.filter(user=self.request.user)
if self.request.user:
return Order.objects.filter(user=self.request.user)

Choose a reason for hiding this comment

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

The get_queryset method should handle cases where self.request.user might be None. Consider adding a check to ensure self.request.user is authenticated before filtering by user.

user/urls.py Outdated
urlpatterns = [
path("register/", CreateUserView.as_view(), name="create"),
path("login/", LoginUserView.as_view(), name="login"),
#path("me/", ManageUserView.as_view(), name="manage"),

Choose a reason for hiding this comment

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

The ManageUserView path is commented out. If this view is implemented and should be accessible, consider uncommenting this line.

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 making significant progress with your code! 🎉 While there are still some areas that need attention, the decision to approve this pull request is made to help you move forward with your learning journey. Here are some important points to consider:

  1. Missing Permission Class: Ensure that the IsAuthenticatedReadOrCreate permission class is defined. This is crucial for the OrderViewSet to function as intended, allowing only authenticated users to create orders.

  2. Critical Syntax Error: There's a syntax error in the import statement. Make sure to use a comma , instead of a slash / to separate imported modules: from rest_framework.permissions import BasePermission, SAFE_METHODS.

  3. Order Permission Logic: Verify that the OrderPermission logic aligns with the requirement that only authenticated users can create orders and only owners can observe them. Adjust the has_object_permission method if necessary.

  4. Environment Variables: Ensure that the DJANGO_SECRET_KEY is set in your .env file for security in production, and remember to set DEBUG to False in a production environment.

  5. URL Configurations: Make sure the user.urls module exists and is correctly configured with necessary URL patterns. Also, review the OrderViewSet path to ensure it only allows list and create actions.

  6. Commented Views: If MovieDetailView and MovieSessionDetailView are required for your application, uncomment them and ensure they are correctly implemented.

Keep up the good work, and make sure to address these issues in the future to avoid similar problems. Use this opportunity to improve your code and learn from any mistakes. Happy coding! 🚀

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

@@ -0,0 +1,40 @@
from rest_framework.permissions import BasePermission, SAFE_METHODS

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. You should use a comma , instead of a slash / to separate imported modules: from rest_framework.permissions import BasePermission, SAFE_METHODS.

Comment on lines +28 to +30
(request.method == "POST" or request.method in SAFE_METHODS)
and request.user
and (request.user.is_authenticated or 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 for OrderPermission seems to allow any authenticated user to create or perform safe methods, but it doesn't restrict observation to only the owner as described in the class docstring. You might want to ensure that only the owner can observe, which should be reflected in the has_object_permission method.

Comment on lines +13 to +14
# MovieDetailView,
# MovieSessionDetailView,

Choose a reason for hiding this comment

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

The MovieDetailView and MovieSessionDetailView are commented out. If these views are required for your application, you should uncomment them and ensure they are correctly implemented in your views.

movie_session_detail,
name="moviesession-detail",
),
path("orders/", OrderViewSet.as_view(), name="order-list"),

Choose a reason for hiding this comment

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

The OrderViewSet is included as a path, but ensure that it only allows list and create actions as per the task requirements. If not, you might need to adjust the viewset or the URL configuration accordingly.

queryset = Order.objects.prefetch_related(
"tickets__movie_session__movie", "tickets__movie_session__cinema_hall"
)
serializer_class = OrderSerializer
pagination_class = OrderPagination
authentication_classes = (TokenAuthentication,)
permission_classes = (OrderPermission,)

Choose a reason for hiding this comment

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

The OrderViewSet uses OrderPermission, which should ensure that only authenticated users can create orders and only owners can observe them. Verify that the OrderPermission logic aligns with this requirement.


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.getenv("DJANGO_DEBUG", "True") == "True"

Choose a reason for hiding this comment

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

The DEBUG setting is currently set to True by default. Remember to set this to False in a production environment to avoid exposing sensitive information.

SECRET_KEY = (
"django-insecure-6vubhk2$++agnctay_4pxy_8cq)mosmn(*-#2b^v4cgsh-^!i3"
)
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", "your_secret_key")

Choose a reason for hiding this comment

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

Ensure that the DJANGO_SECRET_KEY environment variable is set in your .env file to maintain security in production.

@@ -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")),

Choose a reason for hiding this comment

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

Ensure that the user.urls module exists and is correctly configured with the necessary URL patterns for the user-related endpoints. This is crucial for the functionality of the api/user/ path.

urlpatterns = [
path("register/", CreateUserView.as_view(), name="create"),
path("login/", LoginUserView.as_view(), name="login"),
path("me/", ManageUserView.as_view(), name="manage"),

Choose a reason for hiding this comment

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

Ensure that the ManageUserView is implemented and correctly handles requests to the me/ endpoint. This is crucial for user management functionality.

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