Skip to content

Commit f0ac693

Browse files
Merge pull request #367 from fasrc/cp_allocationuseredit_hotfix
merge is_allowed_to_update_project with user_can_manage_allocation
2 parents 214f828 + 94aadcd commit f0ac693

5 files changed

Lines changed: 17 additions & 25 deletions

File tree

coldfront/core/allocation/models.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,12 @@ def user_permissions(self, user):
540540
if ProjectPermission.DATA_MANAGER in project_perms:
541541
return [AllocationPermission.USER, AllocationPermission.MANAGER]
542542

543+
managed_resources = [
544+
resource for resource in self.resources.all() if user in resource.allowed_users.all()]
545+
546+
if managed_resources:
547+
return [AllocationPermission.USER, AllocationPermission.MANAGER]
548+
543549
if self.project.projectuser_set.filter(user=user, status__name='Active').exists():
544550
return [AllocationPermission.USER]
545551
if self.allocationuser_set.filter(user=user, status__name__in=['Active', 'New']).exists():
@@ -561,13 +567,8 @@ def has_perm(self, user, perm):
561567
return perm in perms
562568

563569
def user_can_manage_allocation(self, user):
564-
is_manager = False
565-
if self.project.pi == user:
566-
is_manager = True
567-
for resource in self.resources.all():
568-
if resource.user_can_manage_resource(user):
569-
is_manager = True
570-
return is_manager
570+
return self.has_perm(user, AllocationPermission.MANAGER)
571+
571572

572573
def __str__(self):
573574
tmp = self.get_parent_resource

coldfront/core/allocation/templates/allocation/allocation_detail.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h2>Allocation Detail</h2>
5050
<div class="col">
5151
<h3><i class="fas fa-list" aria-hidden="true"></i> Allocation Information</h3>
5252
</div>
53-
{% if allocation.is_changeable and not allocation.is_locked and is_allowed_to_update_project and allocation.status.name in 'Active, Renewal Requested, Payment Pending, Payment Requested, Paid' and 'Cluster' not in allocation.get_parent_resource.resource_type.name %}
53+
{% if allocation.is_changeable and not allocation.is_locked and user_can_manage_allocation and allocation.status.name in 'Active, Renewal Requested, Payment Pending, Payment Requested, Paid' and 'Cluster' not in allocation.get_parent_resource.resource_type.name %}
5454
<div class="col">
5555
<a class="btn btn-primary" href="{% url 'allocation-change' allocation.pk %}" role="button" style="float: right;">
5656
Request Change
@@ -210,7 +210,7 @@ <h3><i class="fas fa-list" aria-hidden="true"></i> Allocation Information</h3>
210210
<i class="far fa-clock" aria-hidden="true"></i>
211211
Expires in {{allocation.expires_in}} day{{allocation.expires_in|pluralize}} - Not renewable
212212
</span>
213-
{% elif is_allowed_to_update_project and ALLOCATION_ENABLE_ALLOCATION_RENEWAL and allocation.status.name == 'Active' and allocation.expires_in <= 60 and allocation.expires_in >= 0 %}
213+
{% elif user_can_manage_allocation and ALLOCATION_ENABLE_ALLOCATION_RENEWAL and allocation.status.name == 'Active' and allocation.expires_in <= 60 and allocation.expires_in >= 0 %}
214214
<a href="{% url 'allocation-renew' allocation.pk %}">
215215
<span class="badge badge-warning">
216216
<i class="fas fa-redo-alt" aria-hidden="true"></i>
@@ -409,7 +409,7 @@ <h4 class="card-title">{{attribute}}</h4>
409409
<h3 class="d-inline">
410410
<i class="fas fa-info-circle" aria-hidden="true"></i> Allocation Change Requests
411411
</h3> <span class="badge badge-secondary">{{allocation_changes.count}}</span>
412-
{% if allocation.is_changeable and not allocation.is_locked and is_allowed_to_update_project and allocation.status.name in 'Active, Renewal Requested, Payment Pending, Payment Requested, Paid' %}
412+
{% if allocation.is_changeable and not allocation.is_locked and user_can_manage_allocation and allocation.status.name in 'Active, Renewal Requested, Payment Pending, Payment Requested, Paid' %}
413413
<a class="btn btn-primary" href="{% url 'allocation-change' allocation.pk %}" role="button" style="float: right;">
414414
Request Change
415415
</a>
@@ -473,7 +473,7 @@ <h3 class="d-inline"><i class="fas fa-users" aria-hidden="true"></i> Users in Al
473473
<span class="last_sync_users">Last Sync: {{user_sync_dt}}</span>
474474
{% endif %}
475475
<div class="float-right">
476-
{% if allocation.project.status.name != 'Archived' and is_allowed_to_update_project and allocation.status.name in 'Active,New,Renewal Requested' and user_can_manage_allocation and allocation.is_cluster_allocation %}
476+
{% if allocation.project.status.name != 'Archived' and allocation.status.name in 'Active,New,Renewal Requested' and user_can_manage_allocation and allocation.is_cluster_allocation %}
477477
<a class="btn btn-success" href="{% url 'allocation-add-users' allocation.pk %}" role="button">
478478
<i class="fas fa-user-plus" aria-hidden="true"></i> Add Users
479479
</a>

coldfront/core/allocation/templates/allocation/allocation_invoice_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h3><i class="fas fa-list" aria-hidden="true"></i> Usage Summary For: {{ allocat
168168
<h3 class="d-inline"><i class="fas fa-users" aria-hidden="true"></i> Users in Allocation</h3>
169169
<span class="badge badge-secondary">{{allocation_users.count}}</span>
170170
{% comment %} <div class="float-right">
171-
<!-- {% if allocation.project.status.name != 'Archived' and is_allowed_to_update_project and allocation.status.name in 'Active,New,Renewal Requested' %}
171+
<!-- {% if allocation.project.status.name != 'Archived' and user_can_manage_allocation and allocation.status.name in 'Active,New,Renewal Requested' %}
172172
<a class="btn btn-success" href="{% url 'allocation-add-users' allocation.pk %}" role="button">
173173
<i class="fas fa-user-plus" aria-hidden="true"></i> Add Users
174174
</a>

coldfront/core/allocation/templates/allocation/allocation_user_attributes_edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ <h2>Edit User Attributes for {{allocation.project.title}} {{allocation.get_paren
121121

122122
</table>
123123
</form>
124-
{% if is_allowed_to_update_project and request.user.is_superuser %}
124+
{% if user_can_manage_allocation and request.user.is_superuser %}
125125
<div class="text-left">
126126
<a class="btn btn-secondary" href="{% url 'allocation-detail' allocation.pk %}" role="button">
127127
<i class="fas fa-long-arrow-left" aria-hidden="true"></i>

coldfront/core/allocation/views.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,14 @@ def get_context_data(self, **kwargs):
267267
context['attributes'] = attributes
268268
context['allocation_changes'] = allocation_changes
269269

270-
# Can the user update the project?
271-
project_update_perm = allocation_obj.project.has_perm(
272-
self.request.user, ProjectPermission.DATA_MANAGER
273-
)
274-
context['is_allowed_to_update_project'] = project_update_perm
270+
context['user_can_manage_allocation'] = allocation_obj.user_can_manage_allocation(self.request.user)
275271
context['allocation_non_project_users'] = allocation_obj.get_non_project_users
276272
non_project_users_list = [allocation_user.user for allocation_user in context['allocation_non_project_users']]
277273
context['allocation_users'] = allocation_users.exclude(user__in=non_project_users_list)
278274
context['note_update_link'] = 'allocation-note-update'
279275

280276
context['notes'] = self.return_visible_notes(allocation_obj)
281277
context['ALLOCATION_ENABLE_ALLOCATION_RENEWAL'] = ALLOCATION_ENABLE_ALLOCATION_RENEWAL
282-
context['user_can_manage_allocation'] = allocation_obj.user_can_manage_allocation(self.request.user)
283278
return context
284279

285280
def return_visible_notes(self, allocation_obj):
@@ -1397,11 +1392,7 @@ def get_context_data(self, **kwargs):
13971392
inactive_status = AllocationUserStatusChoice.objects.get(name='Removed')
13981393
allocation_users = allocation_obj.allocationuser_set.exclude(status=inactive_status).order_by('user__username')
13991394

1400-
# Can the user update the project?
1401-
project_update_perm = allocation_obj.project.has_perm(
1402-
self.request.user, ProjectPermission.DATA_MANAGER
1403-
)
1404-
context['is_allowed_to_update_project'] = project_update_perm
1395+
context['user_can_manage_allocation'] = allocation_obj.user_can_manage_allocation(self.request.user)
14051396
context['allocation_users'] = allocation_users
14061397
context['allocation'] = allocation_obj
14071398
return context
@@ -1834,7 +1825,7 @@ def get_context_data(self, **kwargs):
18341825
project_update_perm = allocation_obj.project.has_perm(
18351826
self.request.user, ProjectPermission.DATA_MANAGER
18361827
)
1837-
context['is_allowed_to_update_project'] = project_update_perm
1828+
context['user_can_manage_allocation'] = allocation_obj.user_can_manage_allocation(self.request.user)
18381829
context['allocation_users'] = allocation_users
18391830
context['note_update_link'] = 'allocation-note-update'
18401831

0 commit comments

Comments
 (0)