Skip to content

Commit

Permalink
Fix allocation list results for resource allowed_users; fix allocatio…
Browse files Browse the repository at this point in the history
…nedituserview issue; fix AllocationUserAttributesEditView display for Storage allocations; limit AllocationUserAttributesEditView access to Managers
  • Loading branch information
claire-peters committed Feb 18, 2025
1 parent 712bdb9 commit a1f287c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions coldfront/core/allocation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def get_queryset(self):
# Q(project__projectuser__status__name='Active') &
# Q(project__projectuser__user=self.request.user) &
(
Q(resources__allowed_users=self.request.user) |
Q(project__projectuser__user=self.request.user) |
Q(project__pi=self.request.user) |
(
Expand Down Expand Up @@ -1002,12 +1003,14 @@ def post(self, request, *args, **kwargs):
allocationuser_obj = get_object_or_404(AllocationUser, pk=self.kwargs.get('userid'))

initial_data = {'allocationuser_pk': allocationuser_obj.pk, 'value': allocationuser_obj.get_slurm_spec_value('RawShares')}
post_data = request.POST.copy()
post_data['allocationuser_pk'] = allocationuser_obj.pk

form = AllocationUserAttributeUpdateForm(request.POST, initial=initial_data)
form = AllocationUserAttributeUpdateForm(post_data, initial=initial_data)

if form.is_valid():
form_data = form.cleaned_data
if float(form_data['value']) == initial_data.get('value'):
if str(form_data['value']) == str(initial_data.get('value')):
messages.error(request, "Form not modified")
return HttpResponseRedirect(
reverse('allocation-edit-user', kwargs=self.kwargs)
Expand Down Expand Up @@ -1355,15 +1358,15 @@ def test_func(self):
allocation_obj = get_object_or_404(Allocation, pk=self.kwargs.get('pk'))
if allocation_obj.user_can_manage_allocation(self.request.user):
return True
elif 'Storage' in allocation_obj.resources.resource_type.name:
elif 'Storage' in allocation_obj.get_parent_resource.resource_type.name:
messages.error(
self.request, 'You cannot edit storage allocation user attributes.'
)
return HttpResponseRedirect(
reverse('allocation-detail', kwargs={'pk': allocation_obj.pk})
)
allocation_obj = get_object_or_404(Allocation, pk=self.kwargs.get('pk'))
return allocation_obj.has_perm(self.request.user, AllocationPermission.USER)
return allocation_obj.has_perm(self.request.user, AllocationPermission.MANAGER)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down

0 comments on commit a1f287c

Please sign in to comment.