Skip to content

Commit

Permalink
make it possible to delete a room
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlydial committed Nov 17, 2023
1 parent c39f863 commit 1cc1f18
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions chat/templates/chat/partials/room_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ <h3 class="mb-4 text-lg">Chat</h3>
>
Join</a
>
<a
href="{% url 'chat:delete_room' room.uuid %}"
class="mt-4 inline-block py-2 px-6 bg-rose-800 text-white rounded-xl"
>
Delete</a
>
</div>
{% endfor %}
</div>
3 changes: 2 additions & 1 deletion chat/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
path('chat-admin/add-user/', views.add_user, name='add_user'),
path('chat-admin/users/<uuid:uuid>/', views.user_detail, name='user_detail'),
path('chat-admin/users/<uuid:uuid>/edit/', views.user_edit, name='edit_user'),
path('chat-admin/<str:uuid>/', views.room, name='room'),
path('chat-admin/<str:uuid>/', views.room, name='room'),
path('chat-admin/<str:uuid>/delete/', views.delete_room, name='delete_room'),
]
13 changes: 13 additions & 0 deletions chat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def room(request, uuid):
'room': room
})

@login_required
def delete_room(request, uuid):
if request.user.has_perm('room.delete_room'):
room = Room.objects.get(uuid=uuid)
room.delete()
messages.error(request, 'The room was deleted!')
return redirect('/chat-admin/')

else:
messages.error(request, 'You do not have access to delete rooms!')
return redirect('/chat-admin/')


@login_required
def user_detail(request, uuid):
user = User.objects.get(pk=uuid)
Expand Down
Binary file modified db.sqlite3
Binary file not shown.

0 comments on commit 1cc1f18

Please sign in to comment.