Skip to content

Commit

Permalink
Merge pull request fedora-infra#44 from fedora-infra/feature/fas-grou…
Browse files Browse the repository at this point in the history
…p-member-rule

Add a rule to match members of a FAS group.
  • Loading branch information
ralphbean committed Mar 19, 2015
2 parents ed33664 + efcc105 commit 01d0556
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fmn/rules/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ def not_user_filter(config, message, fasnick=None, *args, **kw):
return valid


def _get_users_of_group(config, group):
""" Utility to query fas for users of a group. """
if not group:
return set()
fas = fmn.rules.utils.get_fas(config)
return fmn.rules.utils.get_user_of_group(config, fas, group)


@hint(callable=_get_users_of_group)
def fas_group_member_filter(config, message, group=None, *args, **kw):
""" Messages regarding any member of a FAS group
Use this rule to include messages that have anything to do with **any
user** belonging to a particular fas group. You might want to use this
to monitor the activity of a group for which you are responsible.
"""
if not group:
return False
fasusers = _get_users_of_group(config, group)
msgusers = fedmsg.meta.msg2usernames(message, **config)
return bool(fasusers.intersection(msgusers))


def _user_package_filter_hint(config, fasnick):
packages = fmn.rules.utils.get_packages_of_user(config, fasnick)
return dict(packages=packages)
Expand Down

0 comments on commit 01d0556

Please sign in to comment.