Skip to content

Commit

Permalink
support both objects and group dicts in has_access and `require_acc…
Browse files Browse the repository at this point in the history
…ess`
  • Loading branch information
Omer Lachish committed Mar 27, 2019
1 parent 5ef2031 commit 1f16998
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions redash/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@


def has_access(obj, user, need_view_only):
groups = obj.groups if hasattr(obj, 'groups') else obj

if 'admin' in user.permissions:
return True

matching_groups = set(obj.groups.keys()).intersection(user.group_ids)
matching_groups = set(groups.keys()).intersection(user.group_ids)

if not matching_groups:
return False

required_level = 1 if need_view_only else 2

group_level = 1 if all(flatten([obj.groups[group] for group in matching_groups])) else 2
group_level = 1 if all(flatten([groups[group] for group in matching_groups])) else 2

return required_level <= group_level

Expand Down

0 comments on commit 1f16998

Please sign in to comment.