show groups on member pages if allowed

- display groups on user pages when not the logged in user
- restrict visibility of groups on user pages and group pages themselves according to privacy settings
This commit is contained in:
Hugh Rundle 2021-09-27 17:51:18 +10:00
parent 277c033fda
commit 81e5ff5b76
3 changed files with 11 additions and 3 deletions

View file

@ -75,8 +75,7 @@
<a href="{{ url }}">{% trans "Lists" %}</a>
</li>
{% endif %}
<!-- TODO: fix this: user.groups_set isn't what you think! -->
{% if is_self or user.groups_set.exists %}
{% if is_self or has_groups %}
{% url 'user-groups' user|username as url %}
<li{% if url in request.path %} class="is-active"{% endif %}>
<a href="{{ url }}">{% trans "Groups" %}</a>

View file

@ -23,9 +23,17 @@ class Group(View):
def get(self, request, group_id):
"""display a group"""
# TODO: use get_or_404?
# TODO: what is the difference between privacy filter and visible to user?
# get_object_or_404(models.Group, id=group_id)
group = models.Group.objects.get(id=group_id)
lists = models.List.objects.filter(group=group).order_by("-updated_date")
lists = privacy_filter(request.user, lists)
# don't show groups to users who shouldn't see them
if not group.visible_to_user(request.user):
return HttpResponseNotFound()
data = {
"group": group,
"lists": lists,
@ -58,7 +66,7 @@ class UserGroups(View):
data = {
"user": user,
"is_self": request.user.id == user.id, # CHECK is this relevant here?
"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",

View file

@ -83,6 +83,7 @@ class User(View):
data = {
"user": user,
"is_self": is_self,
"has_groups": models.GroupMember.objects.filter(user=user).exists(),
"shelves": shelf_preview,
"shelf_count": shelves.count(),
"activities": paginated.get_page(request.GET.get("page", 1)),