-
Notifications
You must be signed in to change notification settings - Fork 25
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
Rework org perms again #5657
base: main
Are you sure you want to change the base?
Rework org perms again #5657
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ def derive_queryset(self, **kwargs): | |
|
||
# don't filter by org for staff users but let OrgObjPermsMixin provide a redirect | ||
if not self.request.user.is_staff: | ||
qs = qs.filter(org=self.request.org) | ||
qs = qs.filter(org__users=self.request.user) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we were brave we could just not filter by org at all and trust |
||
|
||
if hasattr(self.model, "is_active"): | ||
qs = qs.filter(is_active=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ def test_has_permission(self): | |
self.assertEqual(200, self.client.get(create_url).status_code) | ||
|
||
# staff still can't POST | ||
self.assertLoginRedirect(self.client.post(create_url, {"name": "Sales"})) | ||
self.assertEqual(403, self.client.post(create_url, {"name": "Sales"}).status_code) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ericnewcomer ok so this is changing again.. but I think this is safer. You POST as staff, the request just fails. No redirecting to login and then maybe back and wondering what happened with the original form submission. |
||
|
||
# but superuser can | ||
self.customer_support.is_superuser = True | ||
|
@@ -64,9 +64,10 @@ def test_has_permission(self): | |
self.assertEqual(200, self.client.get(create_url).status_code) | ||
self.assertRedirect(self.client.post(create_url, {"name": "Support"}), "hide") | ||
|
||
def test_org_obj_perms_mixin(self): | ||
def test_obj_perms_mixin(self): | ||
contact1 = self.create_contact("Bob", phone="+18001234567", org=self.org) | ||
contact2 = self.create_contact("Zob", phone="+18001234567", org=self.org2) | ||
self.org2.add_user(self.admin, OrgRole.ADMINISTRATOR) | ||
|
||
contact1_url = reverse("contacts.contact_update", args=[contact1.id]) | ||
contact2_url = reverse("contacts.contact_update", args=[contact2.id]) | ||
|
@@ -80,11 +81,16 @@ def test_org_obj_perms_mixin(self): | |
self.assertLoginRedirect(self.client.get(contact1_url)) | ||
self.assertLoginRedirect(self.client.get(contact2_url)) | ||
|
||
# editor role does have access tho.. when the URL is for a group in their org | ||
# editor does have access tho.. when the URL is for a contact in their org | ||
self.login(self.editor) | ||
self.assertEqual(200, self.client.get(contact1_url).status_code) | ||
self.assertLoginRedirect(self.client.get(contact2_url)) | ||
|
||
# admin belongs to both orgs | ||
self.login(self.admin, choose_org=self.org) | ||
self.assertEqual(200, self.client.get(contact1_url).status_code) | ||
self.assertRedirect(self.client.get(contact2_url), reverse("orgs.org_choose")) | ||
|
||
# staff can't access without org | ||
self.login(self.customer_support) | ||
self.assertRedirect(self.client.get(contact1_url), "/staff/org/service/") | ||
|
@@ -94,7 +100,7 @@ def test_org_obj_perms_mixin(self): | |
self.assertRedirect(self.client.get(contact2_url), "/staff/org/service/") # wrong org | ||
|
||
# staff still can't POST | ||
self.assertLoginRedirect(self.client.post(contact1_url, {"name": "Bob"})) | ||
self.assertEqual(403, self.client.post(contact1_url, {"name": "Bob"}).status_code) | ||
self.assertRedirect(self.client.get(contact2_url), "/staff/org/service/") | ||
|
||
|
||
|
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.
really gotta figure out a consistent behavior for when you hit an object specific URL for an object you don't have access to (but might by switching orgs). Here we're changing to a 404 from a login redirect.