Skip to content

Commit

Permalink
Merge pull request #213 from elg/master
Browse files Browse the repository at this point in the history
Error listing access obtain by usergroups via targetgroups
  • Loading branch information
elg committed Nov 1, 2017
2 parents 1dec435 + 951b54d commit 05077b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion passhportd/app/models_mod/targetgroup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def accessible_target_list(self, parsed_targetgroups = None, style="object"):

def all_targetname_list(self, parsed_targetgroups = None):
"""Return a list with all the targets of this targetgroup"""
return accessible_target_list(parsed_targetgroups, style="names")
return self.accessible_target_list(parsed_targetgroups, style="names")


# Usergroup management
Expand Down
9 changes: 9 additions & 0 deletions passhportd/app/models_mod/usergroup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Usergroup(db.Model):
# Relations
members = db.relationship("User", secondary="group_user")
targets = db.relationship("Target", secondary="target_group")
tgmembers = db.relationship("Targetgroup", secondary="tgroup_group")
gmembers = db.relationship(
"Usergroup",
secondary=group_of_group,
Expand Down Expand Up @@ -248,6 +249,7 @@ def list_direct_usergroups(self):

return usergroups


def accessible_target_list(self, checked_usergroups = []):
"""Return all the targets this usergroups give access to"""
accessible_targets = []
Expand All @@ -265,8 +267,15 @@ def accessible_target_list(self, checked_usergroups = []):
if target not in self.targets:
accessible_targets.append(target)

# 3. list all the target accessible through targetgroups
for targetgroup in self.tgmembers:
for target in targetgroup.accessible_target_list():
if target not in self.targets:
accessible_targets.append(target)

return accessible_targets


def show_targets(self, indentation):
"""Return all targets the group gives access
First the targets with this group attached
Expand Down

0 comments on commit 05077b0

Please sign in to comment.