Skip to content

Commit

Permalink
Add check to refetch project membership if changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Powers committed Jun 26, 2024
1 parent 72ac1ea commit 1c00c19
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ def view_project(request, project_id):
keycloak_client, request.user.username, project
)

# Users list may be stale if we update the membership list
users_is_stale = False
if (
request.POST
and can_manage_project_membership
Expand All @@ -365,6 +367,7 @@ def view_project(request, project_id):
if "add_user" in request.POST:
form = ProjectAddUserForm(request.POST)
if form.is_valid():
users_is_stale = True
if _add_users_to_project(
request,
project,
Expand All @@ -382,6 +385,7 @@ def view_project(request, project_id):
)
elif "del_user" in request.POST:
try:
users_is_stale = True
del_username = request.POST["user_ref"]
# Ensure that it's not possible to remove the PI
if del_username in [project.pi.username, project.pi.email]:
Expand Down Expand Up @@ -481,6 +485,7 @@ def view_project(request, project_id):
)
elif "accept_join_request" in request.POST:
try:
users_is_stale = True
join_request = JoinRequest.objects.get(
id=int(request.POST.get("join_request"))
)
Expand Down Expand Up @@ -522,6 +527,7 @@ def view_project(request, project_id):
elif "pi_username" in request.POST:
pi_form = edit_pi(request, project_id)
elif "add_bulk_users" in request.POST:
users_is_stale = True
bulk_user_form = ProjectAddBulkUserForm(request.POST)
if bulk_user_form.is_valid():
usernames = [
Expand All @@ -534,6 +540,7 @@ def view_project(request, project_id):
if _add_users_to_project(request, project, project_id, usernames):
bulk_user_form = ProjectAddBulkUserForm()
elif "remove_bulk_users" in request.POST:
users_is_stale = True
non_managers = [
user
for user in get_project_members(project)
Expand Down Expand Up @@ -564,6 +571,9 @@ def view_project(request, project_id):
if isinstance(a.end, str):
a.end = datetime.strptime(a.end, "%Y-%m-%dT%H:%M:%SZ")

if users_is_stale:
users = get_project_members(project)

if not project_member_or_admin_or_superuser(request.user, project, users):
raise PermissionDenied

Expand Down

0 comments on commit 1c00c19

Please sign in to comment.