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

Solution #725

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

Solution #725

wants to merge 4 commits into from

Conversation

yulia-pl
Copy link

No description provided.

Copy link

@dxrrkwm dxrrkwm left a comment

Choose a reason for hiding this comment

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

good overall but check comments please :)

also remove pushed images and fix your line separators to not replace every file in the project

cinema/models.py Outdated
genres = models.ManyToManyField(Genre)
actors = models.ManyToManyField(Actor)
image = models.ImageField(upload_to="uploads/movies/",
null=True, blank=True)
Copy link

Choose a reason for hiding this comment

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

blank true is enough here

cinema/models.py Outdated
Comment on lines 59 to 65
def save(self, *args, **kwargs):
if self.image:
ext = os.path.splitext(self.image.name)[1]
unique_id = uuid.uuid4()
self.image.name = f"{slugify(self.title)}-{unique_id}{ext}"
super().save(*args, **kwargs)

Copy link

Choose a reason for hiding this comment

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

use more descriptive name for method and use pathlib.Path instead of os

Comment on lines +75 to +81
def save(self, *args, **kwargs):
if isinstance(self.show_time, str):
self.show_time =\
datetime.strptime(self.show_time, "%Y-%m-%d %H:%M:%S")
if timezone.is_naive(self.show_time):
self.show_time = timezone.make_aware(self.show_time)
super().save(*args, **kwargs)
Copy link

Choose a reason for hiding this comment

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

? don't need it here, the error with naive timezone is ok in this task

Comment on lines +103 to +104
order = models.ForeignKey(Order, on_delete=models.CASCADE,
related_name="tickets")
Copy link

Choose a reason for hiding this comment

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

we don't have problem with long line here, why changing it?
same in other files and this one in particular

Comment on lines +113 to +115
def perform_create(self, serializer):
"""Ensure the image field is not set during movie creation"""
serializer.save(image=None)
Copy link

Choose a reason for hiding this comment

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

it's better to write upload image here with action decorator

Comment on lines +197 to +198
if serializer.is_valid():
serializer.save()
Copy link

Choose a reason for hiding this comment

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

i guess it's better to use raise_exception=True here

@@ -20,9 +20,8 @@
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = (
SECRET_KEY =\
Copy link

Choose a reason for hiding this comment

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

?

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 pull request! 😊 While your implementation is mostly on point, there are a few critical issues that need to be addressed before we can proceed:

  1. Security Concerns:

    • The DEBUG setting is currently set to True. This should be set to False in production to prevent exposing sensitive information.
    • The SECRET_KEY is hardcoded in the settings file. It's important to use environment variables to manage sensitive information securely, especially in production environments.
  2. Code Clarity:

    • In the authenticate function, the username parameter is used to pass the email. While this is technically correct, it can be confusing. Adding a comment to clarify that username is used for email-based authentication would improve code readability.

Please address these issues to ensure the security and clarity of your code. Once these changes are made, your pull request will be ready for approval. Keep up the great work! 🚀

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

@@ -20,9 +20,8 @@
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = (
SECRET_KEY =\
"django-insecure-6vubhk2$++agnctay_4pxy_8cq)mosmn(*-#2b^v4cgsh-^!i3"

Choose a reason for hiding this comment

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

The SECRET_KEY should not be hardcoded in the settings file for production environments. Consider using environment variables to securely manage sensitive information.

"django-insecure-6vubhk2$++agnctay_4pxy_8cq)mosmn(*-#2b^v4cgsh-^!i3"
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = 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 set to True. Ensure this is set to False in production to avoid exposing sensitive information.

if email and password:
user = authenticate(
request=self.context.get("request"),
username=email,

Choose a reason for hiding this comment

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

In the authenticate function, the username parameter is used to pass the email. This is correct since Django's authenticate function expects a username parameter, but it might be confusing. Consider adding a comment to clarify that username is used for email-based authentication.

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 implementing the required features and addressing previous issues! 🎉 Your code meets the task requirements, and the decision to approve the pull request is made to help you move forward with your learning journey. However, there are a few critical areas that need attention:

  1. Security Concerns:

    • The DEBUG setting is currently set to True. This should be set to False in production to prevent exposing sensitive information. Consider using environment variables to toggle this setting based on the environment.
    • The SECRET_KEY is hardcoded in the settings file. It's important to use environment variables to manage sensitive information securely, especially in production environments.
  2. Code Clarity and Functionality:

    • In the AuthTokenSerializer, the authenticate function uses username=email. While this is technically correct, it can be confusing. Consider adding a comment to clarify that username is used for email-based authentication.
    • The perform_create method in MovieViewSet sets the image field to None during movie creation. Ensure this behavior is intentional, as it prevents setting an image during the creation process.
    • The validate method in TicketSerializer calls Ticket.validate_ticket with three arguments, but the validate_ticket method in the Ticket model requires four arguments, including error_to_raise. Ensure that the correct number of arguments is passed to validate_ticket.
    • The method rename_image_and_save is not being called anywhere in the code. Ensure that you override the save method of the Movie model to call rename_image_and_save instead of super().save() directly.
  3. Model and Serializer Adjustments:

    • The image field in the Movie model is set to blank=True but not null=True. If you want to allow the field to be completely optional, consider adding null=True.
    • In MovieSessionDetailSerializer, ensure that the level of detail provided by MovieDetailSerializer is necessary for the use case, as it might include more data than needed.

Please review these comments to improve your code. Addressing these issues will enhance the security, clarity, and functionality of your application. 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! ✨

genres = models.ManyToManyField(Genre)
actors = models.ManyToManyField(Actor)
image = models.ImageField(upload_to="uploads/movies/", blank=True)

Choose a reason for hiding this comment

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

The image field in the Movie model is set to blank=True but not null=True. This means that the database will require a value for this field, even if it's an empty string. If you want to allow the field to be completely optional, consider adding null=True.

Comment on lines +58 to +63
def rename_image_and_save(self, *args, **kwargs):
if self.image:
ext = Path(self.image.name).suffix
unique_id = uuid.uuid4()
self.image.name = f"{slugify(self.title)}-{unique_id}{ext}"
super().save(*args, **kwargs)

Choose a reason for hiding this comment

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

The method rename_image_and_save is a custom save method for renaming the image file before saving. However, this method is not being called anywhere in the code. Ensure that you override the save method of the Movie model to call rename_image_and_save instead of super().save() directly.

Comment on lines +103 to +104
Ticket.validate_ticket(attrs["row"], attrs["seat"],
attrs["movie_session"])

Choose a reason for hiding this comment

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

The validate method in TicketSerializer calls Ticket.validate_ticket with three arguments, but the validate_ticket method in the Ticket model requires four arguments, including error_to_raise. Ensure that the correct number of arguments is passed to validate_ticket.

@@ -106,11 +120,10 @@


class MovieSessionDetailSerializer(MovieSessionSerializer):
movie = MovieListSerializer(many=False, read_only=True)
movie = MovieDetailSerializer(many=False, read_only=True)

Choose a reason for hiding this comment

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

In MovieSessionDetailSerializer, the movie field is using MovieDetailSerializer, which includes all fields of the movie. Ensure that this level of detail is necessary for the use case, as it might include more data than needed.

Comment on lines +113 to +115
def perform_create(self, serializer):
"""Ensure the image field is not set during movie creation"""
serializer.save(image=None)

Choose a reason for hiding this comment

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

The perform_create method in MovieViewSet sets the image field to None during movie creation. Ensure this behavior is intentional, as it prevents setting an image during the creation process. If you want to allow image uploads during creation, consider handling this differently.

"django-insecure-6vubhk2$++agnctay_4pxy_8cq)mosmn(*-#2b^v4cgsh-^!i3"
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = 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. This should be set to False in production to prevent exposing sensitive information. Consider using environment variables to toggle this setting based on the environment.

from .models import User


class UserAdmin(BaseUserAdmin):
ordering = ["email"]

Choose a reason for hiding this comment

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

The ordering attribute is set to email, which assumes that the User model has an email field. Ensure that the User model indeed has an email field, as this is not a default field in Django's AbstractUser model.

Comment on lines +13 to +16
migrations.AlterModelManagers(
name="user",
managers=[],
),

Choose a reason for hiding this comment

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

This migration removes all managers from the User model. Ensure this is intentional, as it will prevent standard query operations on the User model. If this is not the desired behavior, consider specifying a default manager.



class User(AbstractUser):
pass
email = models.EmailField(unique=True)
username = None

Choose a reason for hiding this comment

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

The username field is set to None, which is correct for removing the username field from the User model. Ensure that all parts of the application that rely on user authentication are updated to use email instead.

if email and password:
user = authenticate(
request=self.context.get("request"),
username=email,

Choose a reason for hiding this comment

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

In the AuthTokenSerializer, the authenticate function uses username=email. While this is technically correct, it can be confusing. Consider adding a comment to clarify that username is used for email-based authentication.

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.

3 participants