Merge pull request #188 from daboross/patch-5
Simplify permissions checking and only print value if user is in group
This commit is contained in:
commit
fb84e17e34
1 changed files with 12 additions and 21 deletions
|
@ -38,29 +38,20 @@ def sieve_suite(bot, input, func, kind, args):
|
||||||
groups = bot.config.get("permissions", [])
|
groups = bot.config.get("permissions", [])
|
||||||
|
|
||||||
allowed_permissions = args.get('permissions', [])
|
allowed_permissions = args.get('permissions', [])
|
||||||
allowed_groups = []
|
|
||||||
|
|
||||||
# loop over every group
|
|
||||||
for key, value in groups.iteritems():
|
|
||||||
# loop over every permission the command allows
|
|
||||||
for permission in allowed_permissions:
|
|
||||||
# see if the group has that permission
|
|
||||||
print value
|
|
||||||
if permission in value["perms"]:
|
|
||||||
# if so, add the group name to the allowed_groups list
|
|
||||||
allowed_groups.append(key)
|
|
||||||
|
|
||||||
if not allowed_groups:
|
|
||||||
print "Something is wrong. A hook requires {} but" \
|
|
||||||
" there are no groups with that permission!".format(str(allowed_permissions))
|
|
||||||
|
|
||||||
mask = input.mask.lower()
|
mask = input.mask.lower()
|
||||||
|
|
||||||
for group in allowed_groups:
|
# loop over every group
|
||||||
group_users = bot.config.get("permissions", {}).get(group, [])["users"]
|
for key, group in groups.iteritems():
|
||||||
group_users = [_mask.lower() for _mask in group_users]
|
# loop over every permission the command allows
|
||||||
|
for permission in allowed_permissions:
|
||||||
|
# see if the group has that permission
|
||||||
|
if permission in group["perms"]:
|
||||||
|
# if so, check it
|
||||||
|
group_users = [_mask.lower() for _mask in group["users"]]
|
||||||
for pattern in group_users:
|
for pattern in group_users:
|
||||||
if fnmatch(mask, pattern):
|
if fnmatch(mask, pattern):
|
||||||
|
print "Allowed group {}.".format(group)
|
||||||
return input
|
return input
|
||||||
|
|
||||||
input.notice("Sorry, you are not allowed to use this command.")
|
input.notice("Sorry, you are not allowed to use this command.")
|
||||||
|
|
Reference in a new issue