Skip to content

Commit

Permalink
Add view who can accept
Browse files Browse the repository at this point in the history
  • Loading branch information
a-belhadj committed Nov 21, 2023
1 parent 6aebd8f commit 9d88f27
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
17 changes: 17 additions & 0 deletions service_catalog/migrations/0035_alter_request_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.6 on 2023-11-16 13:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('service_catalog', '0034_alter_request_approval_workflow_state'),
]

operations = [
migrations.AlterModelOptions(
name='request',
options={'default_permissions': ('add', 'change', 'delete', 'view', 'list'), 'ordering': ['-last_updated'], 'permissions': [('accept_request', 'Can accept request'), ('cancel_request', 'Can cancel request'), ('reject_request', 'Can reject request'), ('archive_request', 'Can archive request'), ('unarchive_request', 'Can unarchive request'), ('re_submit_request', 'Can re-submit request'), ('process_request', 'Can process request'), ('need_info_request', 'Can ask info request'), ('view_admin_survey', 'Can view admin survey'), ('list_approvers', 'Can view who can accept')]},
),
]
7 changes: 5 additions & 2 deletions service_catalog/models/approval_step_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class ApprovalStepState(SquestModel):

class Meta:
unique_together = ('approval_workflow_state', 'approval_step')
ordering = ("approval_step__position",)
Expand Down Expand Up @@ -61,7 +60,11 @@ def get_scopes(self):
return self.approval_workflow_state.get_scopes()

def who_can_approve(self):
return self.approval_workflow_state.request.instance.quota_scope.who_has_perm(self.approval_step.permission.permission_str)
return self.approval_workflow_state.request.instance.quota_scope.who_has_perm(
self.approval_step.permission.permission_str)

def who_can_accept(self):
return self.who_can_approve()

@classmethod
def get_q_filter(cls, user, perm):
Expand Down
1 change: 1 addition & 0 deletions service_catalog/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Meta:
("process_request", "Can process request"),
("need_info_request", "Can ask info request"),
("view_admin_survey", "Can view admin survey"),
("list_approvers", "Can view who can accept"),
]
default_permissions = ('add', 'change', 'delete', 'view', 'list')

Expand Down
6 changes: 6 additions & 0 deletions service_catalog/views/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import markdown as md
from django.conf import settings
from django.contrib.auth.models import User
from django.template.defaultfilters import stringfilter
from django.template.defaulttags import register
from django.utils.safestring import mark_safe
Expand Down Expand Up @@ -181,3 +182,8 @@ def display_boolean(boolean_value):
return mark_safe('<i class="fas fa-circle text-success"></i>')
else:
return mark_safe('<i class="fas fa-circle text-secondary"></i>')


@register.simple_tag()
def who_can_approve(object):
return object.who_can_accept()
30 changes: 29 additions & 1 deletion templates/service_catalog/request_details/approval.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
{% has_perm request.user "service_catalog.re_submit_request" object as can_re_submit_request %}
{% has_perm request.user "service_catalog.reject_request" object as can_reject_request %}
{% has_perm request.user "service_catalog.accept_request" object as can_accept_request %}
{% has_perm request.user "service_catalog.process_request" object as can_process_request %}
{% has_perm request.user "service_catalog.list_approvers" object as list_approvers %}
{% has_perm request.user "service_catalog.view_admin_spec_instance" object.instance as can_view_admin_spec_instance %}


<div class="timeline">
<div>
<i class="fas fa-shopping-cart bg-success"></i>
Expand Down Expand Up @@ -56,6 +57,21 @@ <h3 class="timeline-header">Requested by <a
</span>
<h3 class="timeline-header text-success">{{ step.approval_step.name }}</h3>
<div class="timeline-body">

{% if list_approvers %}
{% who_can_approve step as list_who_can_approve %}
<details>
<summary>Approvers</summary>
<table class="row">
{% for user in list_who_can_approve %}
<tr>
<td class="col-sm-2"><b>{{ user.username }}</b></td>
</tr>
{% endfor %}
</table>
</details>
{% endif %}

{% if step.get_state_display == "APPROVED" %}
<details>
<summary>Survey</summary>
Expand Down Expand Up @@ -143,6 +159,18 @@ <h3 class="timeline-header text-success">{{ step.approval_step.name }}</h3>
<div class="timeline-item">
<h3 class="timeline-header">Admin review</h3>
<div class="timeline-body">
{% if list_approvers %}
<details>
<summary>Approvers</summary>
<table class="row">
{% for user in list_who_can_approve %}
<tr>
<td class="col-sm-2"><b>{{ user.username }}</b></td>
</tr>
{% endfor %}
</table>
</details>
{% endif %}
{% if object.get_state_display == "SUBMITTED" %}
<div class="callout callout-info">
<i class="fas fa-pause text-info"></i> This request is waiting for an approval
Expand Down

0 comments on commit 9d88f27

Please sign in to comment.