my_groups returns groups that should be on the groups landing page
@@ -328,6 +328,26 @@ class UserAccess(models.Model):
return Group.objects.filter(g2ugp__user=self.user,
g2ugp__privilege=PrivilegeCodes.OWNER)
+ @property
+ def my_groups(self):
+ """
+ Get a list of groups that should appear in "my groups".
+
+ Inactive groups will be included only if self owns those groups.
+
+ :return: QuerySet evaluating to held groups.
+ """
+ if not self.user.is_active:
+ raise PermissionDenied("Requesting user is not active")
+
+ return Group.objects.filter(Q(g2ugp__user=self.user,
+ g2ugp__privilege__lte=PrivilegeCodes.VIEW,
+ gaccess__active=True) |
+ Q(g2ugp__user=self.user,
+ gaccess__active=False,
+ g2ugp__privilege=PrivilegeCodes.OWNER))\
+ .distinct()
+
#################################
# access checks for groups
#################################
