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

Allow Wharton Council officers to manage associated clubs #778

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
22 changes: 16 additions & 6 deletions backend/clubs/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
# user must be in club or parent club to perform non-view actions
membership = find_membership_helper(request.user, obj)
Copy link
Member

Choose a reason for hiding this comment

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

Skimming this and memory not the best of the code base... but isn't this already supported? MUSE for example has WC as a parent org and the tree traversal in find_membership_helper should catch this case (are parent orgs synced?)

image

Copy link
Member

@rohangpta rohangpta Feb 17, 2025

Choose a reason for hiding this comment

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

(old PR that came to mind #241)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the catch, definitely is supported (sync apparently wasn't a cron: f608990 but that's a separate story) ... will repurpose this PR for the minor change to approved club version viewing and adding a test for the find_membership_helper behavior

if membership is None:
if obj.is_wharton:
return WhartonApplicationPermission.check_wharton_council_officer(

Check warning on line 167 in backend/clubs/permissions.py

View check run for this annotation

Codecov / codecov/patch

backend/clubs/permissions.py#L167

Added line #L167 was not covered by tests
self, request
)
return False
# user has to be an owner to delete a club, an officer to edit it
if view.action in {"destroy"}:
Expand Down Expand Up @@ -278,8 +282,8 @@

class ClubItemPermission(permissions.BasePermission):
"""
Officers and above can create/update/delete events or testimonials.
Everyone else can view and list events or testimonials.
Officers and above can create/update/delete applications or testimonials.
Everyone else can view and list applications or testimonials.
"""

def has_permission(self, request, view):
Expand All @@ -298,7 +302,14 @@
return True
obj = Club.objects.get(code=view.kwargs["club_code"])
membership = find_membership_helper(request.user, obj)
return membership is not None and membership.role <= Membership.ROLE_OFFICER
return (

Check warning on line 305 in backend/clubs/permissions.py

View check run for this annotation

Codecov / codecov/patch

backend/clubs/permissions.py#L305

Added line #L305 was not covered by tests
membership is not None and membership.role <= Membership.ROLE_OFFICER
) or (
obj.is_wharton
and WhartonApplicationPermission.check_wharton_council_officer(
self, request
)
)
else:
return True

Expand Down Expand Up @@ -338,15 +349,14 @@
Grants permission if the user is an officer of Wharton Council
"""

WHARTON_COUNCIL_CLUB_CODE = "wharton-council"

def check_wharton_council_officer(self, request):
WHARTON_COUNCIL_CLUB_CODE = "wharton-council"
if not request.user.is_authenticated:
return False
user = get_user_model().objects.filter(username=request.user).first()
if user is not None:
membership = Membership.objects.filter(
club__code=self.WHARTON_COUNCIL_CLUB_CODE, person=user
club__code=WHARTON_COUNCIL_CLUB_CODE, person=user
).first()
if membership is not None:
return membership.role <= Membership.ROLE_OFFICER
Expand Down
Loading