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

fixed offer permissions #343

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

Conversation

minghansun1
Copy link
Contributor

No description provided.

@minghansun1 minghansun1 changed the title fixed offer permissions and wrote tests fixed offer permissions Mar 2, 2025
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.00%. Comparing base (f13f141) to head (d99c7a1).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #343      +/-   ##
==========================================
+ Coverage   88.89%   89.00%   +0.10%     
==========================================
  Files          73       73              
  Lines        3171     3183      +12     
==========================================
+ Hits         2819     2833      +14     
+ Misses        352      350       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@minghansun1 minghansun1 requested a review from vcai122 March 3, 2025 03:41
Copy link
Contributor

@vcai122 vcai122 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -299,5 +308,6 @@ def destroy(self, request, *args, **kwargs):
def list(self, request, *args, **kwargs):
if not Item.objects.filter(pk=int(self.kwargs["item_id"])).exists():
raise exceptions.NotFound("No Item matches the given query")
self.check_object_permissions(request, Item.objects.get(pk=int(self.kwargs["item_id"])))
for offer in self.get_queryset():
self.check_object_permissions(request, offer)
Copy link
Contributor

Choose a reason for hiding this comment

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

i dont think you need to check manually... won't setting the permission class already check?

@@ -299,5 +308,6 @@ def destroy(self, request, *args, **kwargs):
def list(self, request, *args, **kwargs):
if not Item.objects.filter(pk=int(self.kwargs["item_id"])).exists():
raise exceptions.NotFound("No Item matches the given query")
self.check_object_permissions(request, Item.objects.get(pk=int(self.kwargs["item_id"])))
for offer in self.get_queryset():
Copy link
Contributor

Choose a reason for hiding this comment

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

On another note, do you have to manually raise NotFound exception? If you do, shouldn't you be raising in the queryset?

@@ -299,5 +308,6 @@ def destroy(self, request, *args, **kwargs):
def list(self, request, *args, **kwargs):
if not Item.objects.filter(pk=int(self.kwargs["item_id"])).exists():
raise exceptions.NotFound("No Item matches the given query")
self.check_object_permissions(request, Item.objects.get(pk=int(self.kwargs["item_id"])))
for offer in self.get_queryset():
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we don't need to manually override list if we do the queryset and object permissions right

@@ -299,5 +308,6 @@ def destroy(self, request, *args, **kwargs):
def list(self, request, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the destroy code on line 303, it seems like you are doing some manual checks to see if the object can be destroyed. Again, I think if we get the permissions right (which I think they are) and the queryset right (which I think you have correct as well), Django's built in destroy should be able to handle all of it for us?

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