-
Notifications
You must be signed in to change notification settings - Fork 681
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
base: master
Are you sure you want to change the base?
Solution #725
Conversation
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.
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) |
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.
blank true is enough here
cinema/models.py
Outdated
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) | ||
|
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.
use more descriptive name for method and use pathlib.Path instead of os
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) |
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.
? don't need it here, the error with naive timezone is ok in this task
order = models.ForeignKey(Order, on_delete=models.CASCADE, | ||
related_name="tickets") |
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.
we don't have problem with long line here, why changing it?
same in other files and this one in particular
def perform_create(self, serializer): | ||
"""Ensure the image field is not set during movie creation""" | ||
serializer.save(image=None) |
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.
it's better to write upload image here with action decorator
if serializer.is_valid(): | ||
serializer.save() |
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.
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 =\ |
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 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 pull request! 😊 While your implementation is mostly on point, there are a few critical issues that need to be addressed before we can proceed:
-
Security Concerns:
- The
DEBUG
setting is currently set toTrue
. This should be set toFalse
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.
- The
-
Code Clarity:
- In the
authenticate
function, theusername
parameter is used to pass the email. While this is technically correct, it can be confusing. Adding a comment to clarify thatusername
is used for email-based authentication would improve code readability.
- In the
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" |
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 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 |
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 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, |
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.
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.
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 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:
-
Security Concerns:
- The
DEBUG
setting is currently set toTrue
. This should be set toFalse
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.
- The
-
Code Clarity and Functionality:
- In the
AuthTokenSerializer
, theauthenticate
function usesusername=email
. While this is technically correct, it can be confusing. Consider adding a comment to clarify thatusername
is used for email-based authentication. - The
perform_create
method inMovieViewSet
sets theimage
field toNone
during movie creation. Ensure this behavior is intentional, as it prevents setting an image during the creation process. - The
validate
method inTicketSerializer
callsTicket.validate_ticket
with three arguments, but thevalidate_ticket
method in theTicket
model requires four arguments, includingerror_to_raise
. Ensure that the correct number of arguments is passed tovalidate_ticket
. - The method
rename_image_and_save
is not being called anywhere in the code. Ensure that you override thesave
method of theMovie
model to callrename_image_and_save
instead ofsuper().save()
directly.
- In the
-
Model and Serializer Adjustments:
- The
image
field in theMovie
model is set toblank=True
but notnull=True
. If you want to allow the field to be completely optional, consider addingnull=True
. - In
MovieSessionDetailSerializer
, ensure that the level of detail provided byMovieDetailSerializer
is necessary for the use case, as it might include more data than needed.
- The
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) |
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 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
.
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) |
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 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.
Ticket.validate_ticket(attrs["row"], attrs["seat"], | ||
attrs["movie_session"]) |
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 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) |
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.
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.
def perform_create(self, serializer): | ||
"""Ensure the image field is not set during movie creation""" | ||
serializer.save(image=None) |
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 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 |
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 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"] |
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 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.
migrations.AlterModelManagers( | ||
name="user", | ||
managers=[], | ||
), |
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.
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 |
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 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, |
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.
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.
No description provided.