diff --git a/bookwyrm/models/group.py b/bookwyrm/models/group.py index 4d9d28156..ea162b2a4 100644 --- a/bookwyrm/models/group.py +++ b/bookwyrm/models/group.py @@ -21,7 +21,7 @@ class Group(BookWyrmModel): symmetrical=False, through="GroupMember", through_fields=("group", "user"), - related_name="members" + related_name="bookwyrm_groups" ) def get_remote_id(self): diff --git a/bookwyrm/templates/groups/user_groups.html b/bookwyrm/templates/groups/user_groups.html index f99abc695..6b4cef1be 100644 --- a/bookwyrm/templates/groups/user_groups.html +++ b/bookwyrm/templates/groups/user_groups.html @@ -3,7 +3,7 @@ {% load interaction %}
- {% for group in groups %} + {% for group in user.bookwyrm_groups.all %}
diff --git a/bookwyrm/templates/user/groups.html b/bookwyrm/templates/user/groups.html index 6b64e4b79..36736e013 100644 --- a/bookwyrm/templates/user/groups.html +++ b/bookwyrm/templates/user/groups.html @@ -34,7 +34,7 @@ {% include 'groups/form.html' %} - {% include 'groups/user_groups.html' with groups=groups %} + {% include 'groups/user_groups.html' %}
{% include 'snippets/pagination.html' with page=user_groups path=path %} diff --git a/bookwyrm/templates/user/layout.html b/bookwyrm/templates/user/layout.html index 0d07b199b..a1a5289d5 100755 --- a/bookwyrm/templates/user/layout.html +++ b/bookwyrm/templates/user/layout.html @@ -75,7 +75,7 @@ {% trans "Lists" %} {% endif %} - {% if is_self or has_groups %} + {% if is_self or user.bookwyrm_groups %} {% url 'user-groups' user|username as url %} {% trans "Groups" %} diff --git a/bookwyrm/templates/user/user.html b/bookwyrm/templates/user/user.html index f360a30af..676161d8e 100755 --- a/bookwyrm/templates/user/user.html +++ b/bookwyrm/templates/user/user.html @@ -22,6 +22,9 @@ {% block panel %} {% if user.bookwyrm_user %} +{% for group in user.bookwyrm_groups.all %} +
{{ group.name }}
+{% endfor %}

{% include 'user/shelf/books_header.html' %} diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py index 4d91be67d..3e1785cce 100644 --- a/bookwyrm/views/group.py +++ b/bookwyrm/views/group.py @@ -1,4 +1,5 @@ """group views""" +from django.apps import apps from django.contrib.auth.decorators import login_required from django.db import IntegrityError from django.core.paginator import Paginator @@ -62,8 +63,6 @@ class UserGroups(View): data = { "user": user, - "has_groups": models.GroupMember.objects.filter(user=user).exists(), - "groups": paginated.get_page(request.GET.get("page")), "group_form": forms.GroupForm(), "path": user.local_path + "/group", } @@ -144,6 +143,21 @@ def add_member(request): except IntegrityError: pass +# TODO: actually this needs to be associated with the user ACCEPTING AN INVITE!!! DOH! + + """create a notification too""" + # notify all team members when a user is added to the group + model = apps.get_model("bookwyrm.Notification", require_ready=True) + for team_member in group.members.all(): + if team_member.local and team_member != request.user: + model.objects.create( + user=team_member, + related_user=request.user, + related_group_member=user, + related_group=group, + notification_type="ADD", + ) + return redirect(user.local_path) @require_POST @@ -151,8 +165,12 @@ def add_member(request): def remove_member(request): """remove a member from the group""" + # TODO: send notification to user telling them they have been removed + # TODO: remove yourself from a group!!!! (except owner) + # FUTURE TODO: transfer ownership of group + # TODO: if groups become AP values we need something like get_group_from_group_fullname - # group = get_object_or_404(models.Group, id=request.POST.get("group")) + # group = get_object_or_404(models.Group, id=request.POST.get("group")) # NOTE: does this not work? group = models.Group.objects.get(id=request.POST["group"]) if not group: return HttpResponseBadRequest()