Skip to content

Commit

Permalink
add delete support button
Browse files Browse the repository at this point in the history
  • Loading branch information
Sispheor committed Sep 20, 2023
1 parent 5373e26 commit 8ca93cb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions service_catalog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
# Support CRUD under instance
path('instance/<int:instance_id>/support/create/', views.support_create, name='support_create'),
path('instance/<int:instance_id>/support/<int:pk>/', views.support_details, name='support_details'),
path('instance/<int:instance_id>/support/<int:pk>/delete/', views.SupportDeleteView.as_view(), name='support_delete'),

# Support State Machine
path('instance/<int:instance_id>/support/<int:pk>/close/', views.CloseSupportView.as_view(), name='support_close'),
Expand Down
14 changes: 14 additions & 0 deletions service_catalog/views/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ def get_context_data(self, **kwargs):
return context


class SupportDeleteView(SquestDeleteView):
model = Support

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['breadcrumbs'] = [
{'text': 'Instances', 'url': reverse('service_catalog:instance_list')},
{'text': f"{self.object.instance.name} ({self.object.instance.id})",
'url': reverse('service_catalog:instance_details', args=[self.object.instance.id])},
{'text': f"Support - {self.object.title}", 'url': ''}
]
return context


class ReOpenSupportView(SquestDetailView):
model = Support
permission_required = "service_catalog.reopen_support"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{% has_perm request.user "service_catalog.reopen_support" instance as can_reopen_support %}
{% has_perm request.user "service_catalog.close_support" instance as can_close_support %}
{% has_perm request.user "service_catalog.change_support" instance as can_change_support %}
{% has_perm request.user "service_catalog.delete_support" instance as can_delete_support %}
<!-- Main content -->
<div class="content-wrapper">
<section class="content-header">
Expand All @@ -17,6 +18,12 @@
{% include "generics/breadcrumbs.html" %}
</div>
<div class="col-sm-6">
{% if can_delete_support %}
<a href="{% url 'service_catalog:support_delete' instance_id=instance.id pk=support.id %}"
class="float-sm-right btn btn-danger">
<i class="fas fa-trash"></i>
</a>
{% endif %}
<span title="state"
class="float-sm-right badge bg-{{ support.state |map_support_state }} p-1 mr-2">{{ support.get_state_display }}</span>
</div>
Expand Down
12 changes: 11 additions & 1 deletion tests/test_service_catalog/test_urls/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ def test_support_views(self):
url_kwargs={'instance_id': self.support_test.instance.id, 'pk': self.support_test.id},
expected_status_code=405,
expected_not_allowed_status_code=405
)
),
TestingGetContextView(
url='service_catalog:support_delete',
perm_str='service_catalog.delete_support',
url_kwargs={'instance_id': self.support_test.instance.id, 'pk': self.support_test.id},
),
TestingPostContextView(
url='service_catalog:support_delete',
perm_str='service_catalog.delete_support',
url_kwargs={'instance_id': self.support_test.instance.id, 'pk': self.support_test.id}
),
]
self.run_permissions_tests(testing_view_list)

0 comments on commit 8ca93cb

Please sign in to comment.