mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
add button for project-delete in UI
Implement delete functionality with confirmation modals for projects. cherry picked (by Klaas) from commit 6764fbf343fb; but: * projects only * `delete_deferred` * flake8 See #84 for the original PR
This commit is contained in:
committed by
Klaas van Schelven
parent
cb3168133e
commit
72479fe982
@@ -5,13 +5,32 @@
|
||||
{% block title %}Edit {{ project.name }} · {{ site_title }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{# div class="text-cyan-800" here in an attempt to trigger tailwind, which does not pick up Pyhton code #}
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div id="deleteModal" class="hidden fixed inset-0 bg-slate-600 bg-opacity-50 overflow-y-auto h-full w-full z-50 flex items-center justify-center">
|
||||
<div class="relative p-6 border border-slate-300 w-96 shadow-lg rounded-md bg-white">
|
||||
<div class="text-center m-4">
|
||||
<h3 class="text-2xl font-semibold text-slate-800 mt-3 mb-4">Delete Project</h3>
|
||||
<div class="mt-4 mb-6">
|
||||
<p class="text-slate-700">
|
||||
Are you sure you want to delete this project? This action cannot be undone and will delete all associated data.
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center justify-center space-x-4 mb-4">
|
||||
<button id="cancelDelete" class="text-cyan-500 font-bold">Cancel</button>
|
||||
<form method="post" action="." id="deleteForm">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<button type="submit" class="font-bold py-2 px-4 rounded bg-red-500 text-white border-2 border-red-600 hover:bg-red-600 active:ring">Confirm</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-center">
|
||||
|
||||
<div class="m-4 max-w-4xl flex-auto">
|
||||
<form action="." method="post">
|
||||
<form action="." method="post" id="projectForm">
|
||||
{% csrf_token %}
|
||||
|
||||
<div>
|
||||
@@ -27,11 +46,20 @@
|
||||
{% tailwind_formfield form.retention_max_event_count %}
|
||||
{% tailwind_formfield form.dsn %}
|
||||
|
||||
<button name="action" value="invite" class="font-bold text-slate-800 border-slate-500 pl-4 pr-4 pb-2 pt-2 border-2 bg-cyan-200 hover:bg-cyan-400 active:ring rounded-md">Save</button>
|
||||
<a href="{% url "project_list" %}" class="text-cyan-500 font-bold ml-2">Cancel</a>
|
||||
<div class="flex items-center mt-4">
|
||||
<button name="action" value="save" class="font-bold py-2 px-4 rounded bg-cyan-200 text-slate-800 border-2 border-slate-500 hover:bg-cyan-400 active:ring">Save</button>
|
||||
<a href="{% url "project_list" %}" class="text-cyan-500 font-bold ml-4">Cancel</a>
|
||||
<button type="button" id="deleteButton" class="font-bold py-2 px-4 rounded bg-red-500 text-white border-2 border-red-600 hover:bg-red-600 active:ring ml-auto">Delete Project</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
var csrftoken = '{{ csrf_token }}';
|
||||
</script>
|
||||
<script src="{% static 'js/entity_edit.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -163,8 +163,23 @@ def project_edit(request, project_pk):
|
||||
_check_project_admin(project, request.user)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ProjectForm(request.POST, instance=project)
|
||||
action = request.POST.get('action')
|
||||
|
||||
if action == 'delete':
|
||||
# Double-check that the user is an admin or superuser
|
||||
if (not request.user.is_superuser
|
||||
and not ProjectMembership.objects.filter(
|
||||
project=project, user=request.user, role=ProjectRole.ADMIN, accepted=True).exists()
|
||||
and not TeamMembership.objects.filter(
|
||||
team=project.team, user=request.user, role=TeamRole.ADMIN, accepted=True).exists()):
|
||||
raise PermissionDenied("Only project or team admins can delete projects")
|
||||
|
||||
# Delete the project
|
||||
project.delete_deferred()
|
||||
messages.success(request, f'Project "{project.name}" has been deleted successfully.')
|
||||
return redirect('project_list')
|
||||
|
||||
form = ProjectForm(request.POST, instance=project)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('project_members', project_pk=project.id)
|
||||
|
||||
Reference in New Issue
Block a user