Skip to content

Commit

Permalink
[Fixes GeoNode#12639] Adds all assigned group permissions to user (Ge…
Browse files Browse the repository at this point in the history
…oNode#12640) (GeoNode#12660)

* Adds all assigned group permissions to user

* make set json serializable

(cherry picked from commit fbd853d)

Co-authored-by: Henning Bredel <[email protected]>
  • Loading branch information
github-actions[bot] and ridoo authored Oct 18, 2024
1 parent 84b0207 commit 74080cb
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions geonode/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,29 @@ def location(self):

@property
def perms(self):
perms = set()
if self.is_superuser or self.is_staff:
# return all permissions for admins
perms = PERMISSIONS.values()
else:
user_groups = self.groups.values_list("name", flat=True)
group_perms = (
Permission.objects.filter(group__name__in=user_groups).distinct().values_list("codename", flat=True)
)
# return constant names defined by GeoNode
perms = [PERMISSIONS[db_perm] for db_perm in group_perms]
perms.update(PERMISSIONS.values())

user_groups = self.groups.values_list("name", flat=True)
group_perms = (
Permission.objects.filter(group__name__in=user_groups).distinct().values_list("codename", flat=True)
)
for p in group_perms:
if p in PERMISSIONS:
# return constant names defined by GeoNode
perms.add(PERMISSIONS[p])
else:
# add custom permissions
perms.add(p)

# check READ_ONLY mode
config = Configuration.load()
if config.read_only:
# exclude permissions affected by readonly
perms = [perm for perm in perms if perm not in READ_ONLY_AFFECTED_PERMISSIONS]
return perms
return list(perms)

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Expand Down

0 comments on commit 74080cb

Please sign in to comment.