Skip to content

Commit

Permalink
Preview workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
a-belhadj committed Jan 25, 2024
1 parent d39e5ff commit 0c5c7b4
Show file tree
Hide file tree
Showing 19 changed files with 449 additions and 123 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
- List related docs in OperationDetails and ServiceDetails view
- Add PROCESSING requests in the dashboard of the main page

## Feature

- Preview your workflow with a specific scope before using it.

# 2.5.0 2024-01-09

## Fix
Expand Down
22 changes: 22 additions & 0 deletions profiles/models/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def get_queryset(self):
def expand(self):
return self.get_queryset().expand()


class Scope(AbstractScope):
class Meta:
permissions = [
Expand Down Expand Up @@ -178,3 +179,24 @@ def get_q_filter(cls, user, perm):

def get_absolute_url(self):
return self.get_object().get_absolute_url()

def get_workflows(self):
from service_catalog.models import Operation, ApprovalWorkflow
operations = Operation.objects.filter(enabled=True)

# Teams
approval_workflow = ApprovalWorkflow.objects.filter(scopes__id=self.id, operation__in=operations, enabled=True)
operations = operations.exclude(id__in=approval_workflow.values_list('operation__id', flat=True))

# Org
if self.is_team:
approval_workflow = approval_workflow | ApprovalWorkflow.objects.filter(scopes__id=self.get_object().org.id,
operation__in=operations,
enabled=True)
operations = operations.exclude(id__in=approval_workflow.values_list('operation__id', flat=True))

# Default
approval_workflow = approval_workflow | ApprovalWorkflow.objects.filter(scopes__isnull=True,
operation__in=operations,
enabled=True)
return approval_workflow
1 change: 1 addition & 0 deletions profiles/tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .team_table import *
from .user_table import *
from .permission_table import *
from .approval_workflow import *
16 changes: 16 additions & 0 deletions profiles/tables/approval_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.utils.html import format_html
from django_tables2 import LinkColumn, TemplateColumn

from Squest.utils.squest_table import SquestTable
from profiles.models import Scope


class ApprovalWorkflowPreviewTable(SquestTable):

name = LinkColumn()
preview = TemplateColumn(template_name='profiles/custom_columns/preview_workflow.html', orderable=False)

class Meta:
model = Scope
attrs = {"id": "role_table", "class": "table squest-pagination-tables"}
fields = ("name", "preview")
7 changes: 6 additions & 1 deletion profiles/views/organization.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from Squest.utils.squest_table import SquestRequestConfig

from Squest.utils.squest_views import *
from profiles.api.serializers import scope_serializer
from profiles.filters import OrganizationFilter
from profiles.filters.user_filter import UserFilter
from profiles.forms import OrganizationForm
from profiles.models import Organization, Team
from profiles.tables import OrganizationTable, ScopeRoleTable, TeamTable, UserRoleTable
from profiles.tables.quota_table import QuotaTable
from service_catalog.tables.approval_workflow_table import ApprovalWorkflowPreviewTable


class OrganizationListView(SquestListView):
Expand Down Expand Up @@ -38,7 +40,10 @@ def get_context_data(self, **kwargs):
hide_fields=('org',), prefix="team-"
)
config.configure(context['teams'])

if self.request.user.has_perm("service_catalog.view_approvalworkflow"):
context["workflows"] = ApprovalWorkflowPreviewTable(self.get_object().get_workflows(), prefix="workflow-",
hide_fields=["enabled", "actions", "scopes"])
config.configure(context["workflows"])
context['roles'] = ScopeRoleTable(self.object.roles.distinct())
config.configure(context['roles'])

Expand Down
6 changes: 6 additions & 0 deletions profiles/views/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from profiles.models.team import Team
from profiles.tables import UserRoleTable, ScopeRoleTable, TeamTable
from profiles.tables.quota_table import QuotaTable
from service_catalog.tables.approval_workflow_table import ApprovalWorkflowPreviewTable


def get_organization_breadcrumbs(team):
Expand Down Expand Up @@ -44,6 +45,11 @@ def get_context_data(self, **kwargs):
context['roles'] = ScopeRoleTable(self.object.roles.distinct(), prefix="role-")
config.configure(context['roles'])

if self.request.user.has_perm("service_catalog.view_approvalworkflow"):
context["workflows"] = ApprovalWorkflowPreviewTable(self.get_object().get_workflows(), prefix="workflow-",
hide_fields=["enabled", "actions", "scopes"])
config.configure(context["workflows"])

return context


Expand Down
4 changes: 4 additions & 0 deletions project-static/squest/css/squest.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ input.form-control[disabled] {
.popover {
max-width: 100%;
}

.callout a{
color: unset;
}
10 changes: 10 additions & 0 deletions service_catalog/tables/approval_workflow_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ def render_scopes(self, value, record):
for scope in scopes:
html += f"<span class=\"badge bg-primary\">{scope}</span> "
return format_html(html)


class ApprovalWorkflowPreviewTable(SquestTable):
class Meta:
model = ApprovalWorkflow
attrs = {"id": "approval_workflow_table", "class": "table squest-pagination-tables "}
fields = ("name", "operation", "preview")

name = LinkColumn()
preview = TemplateColumn(template_name='service_catalog/custom_columns/preview_workflow.html', orderable=False)
1 change: 1 addition & 0 deletions service_catalog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
# Approval Workflow CRUD
path('administration/approval/', views.ApprovalWorkflowListView.as_view(), name='approvalworkflow_list'),
path('administration/approval/<int:pk>/', views.ApprovalWorkflowDetailView.as_view(), name='approvalworkflow_details'),
path('administration/approval/<int:pk>/scope/<int:scope_id>', views.ApprovalWorkflowPreviewView.as_view(), name='approvalworkflow_preview'),
path('administration/approval/create/', views.ApprovalWorkflowCreateView.as_view(), name='approvalworkflow_create'),
path('administration/approval/<int:pk>/edit/', views.ApprovalWorkflowEditView.as_view(), name='approvalworkflow_edit'),
path('administration/approval/<int:pk>/delete/', views.ApprovalWorkflowDeleteView.as_view(), name='approvalworkflow_delete'),
Expand Down
48 changes: 44 additions & 4 deletions service_catalog/views/approval_workflow_views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from django.shortcuts import get_object_or_404

from Squest.utils.squest_table import SquestRequestConfig
from Squest.utils.squest_views import SquestListView, SquestDetailView, SquestCreateView, SquestUpdateView, \
SquestDeleteView, SquestConfirmView
from profiles.models import Scope, Organization, Team
from profiles.tables import ApprovalWorkflowPreviewTable
from service_catalog.filters.approval_workflow_filter import ApprovalWorkflowFilter
from service_catalog.forms.approval_workflow_form import ApprovalWorkflowForm, ApprovalWorkflowFormEdit
from service_catalog.models import ApprovalWorkflow
from service_catalog.models import ApprovalWorkflow, Request
from service_catalog.tables.approval_workflow_table import ApprovalWorkflowTable
from service_catalog.tables.request_tables import RequestTablesForApprovalWorkflow

Expand All @@ -27,10 +31,46 @@ def get_context_data(self, **kwargs):
"operation__service", "approval_workflow_state", "approval_workflow_state__approval_workflow",
"approval_workflow_state__current_step",
"approval_workflow_state__current_step__approval_step", "approval_workflow_state__approval_step_states"
))
context['request_table'].exclude = ("selection","last_updated","date_submitted")

).filter(id__in=Request.get_queryset_for_user(self.request.user, "service_catalog.view_request")),
hide_fields=["selection", "last_updated", "date_submitted"])
config.configure(context['request_table'])

context["scope_table"] = ApprovalWorkflowPreviewTable(
Scope.objects.filter(id__in=Organization.get_queryset_for_user(self.request.user, 'profiles.view_organization').values_list("id",flat=True)) |
Scope.objects.filter(id__in=Team.get_queryset_for_user(self.request.user, 'profiles.view_team')).values_list("id", flat=True)
)
config.configure(context['scope_table'])

return context


class ApprovalWorkflowPreviewView(SquestDetailView):
model = ApprovalWorkflow
template_name = "service_catalog/approvalworkflow_preview.html"

def get_permission_required(self):
return "service_catalog.view_approvalworkflow"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
scope = get_object_or_404(Scope, id=self.kwargs.get("scope_id"))
context["current_workflow"] = scope.get_workflows().filter(operation=self.get_object().operation).first()
context['scope'] = scope
context['breadcrumbs'] = [
{
'text': self.django_content_type.name.capitalize(),
'url': self.get_generic_url('list')
},
{
'text': str(self.get_object()),
'url': self.get_object().get_absolute_url()
},
{
'text': scope,
'url': ''
},
]

return context


Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
{% include "generics/breadcrumbs.html" %}
</div>
<div class="col-sm-6">
<div class="float-right">
<div class="d-flex flex-wrap-reverse justify-content-end" style="gap: 4px">
{% block extra_header_button %}
{% if extra_html_button_path %}
{% include extra_html_button_path %}
Expand Down
3 changes: 3 additions & 0 deletions templates/profiles/custom_columns/preview_workflow.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="{% url "service_catalog:approvalworkflow_preview" object.id record.id %}">
Preview
</a>
10 changes: 10 additions & 0 deletions templates/profiles/organization_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ <h3 class="card-title"><b>{{ object.name }}</b></h3>
<a class="nav-link" href="#teams" data-toggle="tab">Teams</a>
</li>
{% endif %}
{% if workflows %}
<li class="nav-item">
<a class="nav-link" href="#workflows" data-toggle="tab">Workflows</a>
</li>
{% endif %}
</ul>
</div>
<div class="card-body">
Expand All @@ -112,6 +117,11 @@ <h3 class="card-title"><b>{{ object.name }}</b></h3>
{% render_table quotas %}
{% endif %}
</div>
<div class="tab-pane" id="workflows">
{% if workflows %}
{% render_table workflows %}
{% endif %}
</div>
</div>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions templates/profiles/team_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ <h3 class="card-title"><b>{{ object.name }}</b></h3>
<a class="nav-link" href="#users" data-toggle="tab">Users</a>
</li>
{% endif %}


{% if workflows %}
<li class="nav-item">
<a class="nav-link" href="#workflows" data-toggle="tab">Workflows</a>
</li>
{% endif %}
</ul>
</div>
<div class="card-body">
Expand All @@ -96,6 +99,11 @@ <h3 class="card-title"><b>{{ object.name }}</b></h3>
{% render_table quotas %}
{% endif %}
</div>
<div class="tab-pane" id="workflows">
{% if workflows %}
{% render_table workflows %}
{% endif %}
</div>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 0c5c7b4

Please sign in to comment.