Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Apply group-ownership stuff to packages-of-user in addition to packag…
Browse files Browse the repository at this point in the history
…ers-of-package.
  • Loading branch information
ralphbean committed Aug 21, 2014
1 parent 7d50e57 commit 23a469e
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions fmn/rules/utils.py
Expand Up @@ -104,9 +104,18 @@ def get_packages_of_user(config, username):
if not hasattr(_cache, 'backend'):
_cache.configure(**config['fmn.rules.cache'])

key = cache_key_generator(get_packages_of_user, username)
creator = lambda: _get_pkgdb2_packages_for(config, username)
return _cache.get_or_create(key, creator)
packages = []

groups = get_groups_of_user(config, get_fas(config), username)
owners = [username] + ['group::' + group for group in groups]

for owner in owners:
key = cache_key_generator(get_packages_of_user, owner)
creator = lambda: _get_pkgdb2_packages_for(config, owner)
subset = _cache.get_or_create(key, creator)
packages.extend(subset)

return set(packages)


def cache_key_generator(fn, arg):
Expand Down Expand Up @@ -161,3 +170,26 @@ def get_user_of_group(config, fas, groupname):
creator = lambda: fas.group_members(groupname)
return _cache.get_or_create(key, creator)

def get_groups_of_user(config, fas, username):
''' Return the list of groups to which the user belongs.
:arg config: a dict containing the fedmsg config
:arg fas: a fedora.client.fas2.AccountSystem object instanciated and loged
into FAS.
:arg username: the name of a user for which we want to retrieve groups
:return: a list of FAS groups to which the user belongs.
'''

if not hasattr(_cache, 'backend'):
cache.configure(**config['fmn.rules.cache'])

key = cache_key_generator(get_groups_of_user, username)

def creator():
results = []
for group in fas.person_by_username(username).get('memberships', []):
results.append(group.name)
return results

return _cache.get_or_create(key, creator)

0 comments on commit 23a469e

Please sign in to comment.