mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-30 03:50:40 +00:00
delete groups
Whoops, forgot to add this functionality earlier. - allow owner to delete a group - change all group lists to closed curation with group=False when group deleted
This commit is contained in:
parent
85784f07d2
commit
2a31bf2f0c
5 changed files with 30 additions and 11 deletions
|
@ -32,7 +32,7 @@ class List(OrderedCollectionMixin, BookWyrmModel):
|
||||||
)
|
)
|
||||||
group = models.ForeignKey(
|
group = models.ForeignKey(
|
||||||
"Group",
|
"Group",
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.SET_NULL,
|
||||||
default=None,
|
default=None,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block modal-footer %}
|
{% block modal-footer %}
|
||||||
<div>
|
<form name="delete-group-{{ group.id }}" action="{% url 'delete-group' group.id %}" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="id" value="{{ group.id }}">
|
<input type="hidden" name="id" value="{{ group.id }}">
|
||||||
<button class="button is-danger" type="submit">
|
<button class="button is-danger" type="submit">
|
||||||
{% trans "Delete" %}
|
{% trans "Delete" %}
|
||||||
</button>
|
</button>
|
||||||
{% trans "Cancel" as button_text %}
|
{% trans "Cancel" as button_text %}
|
||||||
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="delete_list" controls_uid=list.id %}
|
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="delete_group" controls_uid=group.id %}
|
||||||
</div>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,7 @@ urlpatterns = [
|
||||||
re_path(
|
re_path(
|
||||||
r"^group/(?P<group_id>\d+)(.json)?/?$", views.Group.as_view(), name="group"
|
r"^group/(?P<group_id>\d+)(.json)?/?$", views.Group.as_view(), name="group"
|
||||||
),
|
),
|
||||||
|
re_path(r"^group/delete/(?P<group_id>\d+)/?$", views.delete_group, name="delete-group"),
|
||||||
re_path(
|
re_path(
|
||||||
r"^group/(?P<group_id>\d+)/add-users/?$",
|
r"^group/(?P<group_id>\d+)/add-users/?$",
|
||||||
views.FindUsers.as_view(),
|
views.FindUsers.as_view(),
|
||||||
|
|
|
@ -45,6 +45,7 @@ from .group import (
|
||||||
Group,
|
Group,
|
||||||
UserGroups,
|
UserGroups,
|
||||||
FindUsers,
|
FindUsers,
|
||||||
|
delete_group,
|
||||||
invite_member,
|
invite_member,
|
||||||
remove_member,
|
remove_member,
|
||||||
accept_membership,
|
accept_membership,
|
||||||
|
|
|
@ -79,7 +79,7 @@ class UserGroups(View):
|
||||||
"""create a user group"""
|
"""create a user group"""
|
||||||
form = forms.GroupForm(request.POST)
|
form = forms.GroupForm(request.POST)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return redirect(request.user.local_path + "groups")
|
return redirect(request.user.local_path + "/groups")
|
||||||
group = form.save()
|
group = form.save()
|
||||||
# add the creator as a group member
|
# add the creator as a group member
|
||||||
models.GroupMember.objects.create(group=group, user=request.user)
|
models.GroupMember.objects.create(group=group, user=request.user)
|
||||||
|
@ -134,6 +134,22 @@ class FindUsers(View):
|
||||||
return TemplateResponse(request, "groups/find_users.html", data)
|
return TemplateResponse(request, "groups/find_users.html", data)
|
||||||
|
|
||||||
|
|
||||||
|
@require_POST
|
||||||
|
@login_required
|
||||||
|
def delete_group(request, group_id):
|
||||||
|
"""delete a group"""
|
||||||
|
group = get_object_or_404(models.Group, id=group_id)
|
||||||
|
|
||||||
|
# only the owner can delete a group
|
||||||
|
group.raise_not_deletable(request.user)
|
||||||
|
|
||||||
|
# deal with any group lists
|
||||||
|
models.List.objects.filter(group=group).update(curation="closed", group=None)
|
||||||
|
|
||||||
|
group.delete()
|
||||||
|
return redirect(request.user.local_path + "/groups")
|
||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
def invite_member(request):
|
def invite_member(request):
|
||||||
|
@ -268,3 +284,4 @@ def reject_membership(request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return redirect(request.user.local_path)
|
return redirect(request.user.local_path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue