Merge pull request #2180 from bookwyrm-social/set-access-level-user

Fixes setting access level to "user"
This commit is contained in:
Mouse Reeve 2022-07-05 12:08:30 -07:00 committed by GitHub
commit 97b53d4998
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 9 deletions

View file

@ -10,3 +10,4 @@ from .landing import *
from .links import *
from .lists import *
from .status import *
from .user_admin import *

View file

@ -4,12 +4,6 @@ from .custom_form import CustomForm
# pylint: disable=missing-class-docstring
class UserGroupForm(CustomForm):
class Meta:
model = models.User
fields = ["groups"]
class GroupForm(CustomForm):
class Meta:
model = models.Group

View file

@ -0,0 +1,10 @@
""" using django model forms """
from bookwyrm import models
from .custom_form import CustomForm
# pylint: disable=missing-class-docstring
class UserGroupForm(CustomForm):
class Meta:
model = models.User
fields = ["groups"]

View file

@ -77,8 +77,13 @@ class UserAdmin(View):
def post(self, request, user):
"""update user group"""
user = get_object_or_404(models.User, id=user)
form = forms.UserGroupForm(request.POST, instance=user)
if form.is_valid():
form.save()
if request.POST.get("groups") == "":
user.groups.set([])
form = forms.UserGroupForm(instance=user)
else:
form = forms.UserGroupForm(request.POST, instance=user)
if form.is_valid():
form.save()
data = {"user": user, "group_form": form}
return TemplateResponse(request, "settings/users/user.html", data)