New function flagging decorator class to keep track permissions

This commit is contained in:
shortcutme 2019-08-26 02:55:01 +02:00
parent 6750682e4f
commit adffbd1973
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 22 additions and 0 deletions

22
src/util/Flag.py Normal file
View File

@ -0,0 +1,22 @@
from collections import defaultdict
class Flag(object):
def __init__(self):
self.valid_flags = set([
"admin", # Only allowed to run sites with ADMIN permission
"async_run", # Action will be ran async with gevent.spawn
"no_multiuser" # Action disabled if Multiuser plugin running in open proxy mode
])
self.db = defaultdict(set)
def __getattr__(self, key):
def func(f):
if key not in self.valid_flags:
raise Exception("Invalid flag: %s (valid: %s)" % (key, self.valid_flags))
self.db[f.__name__].add(key)
return f
return func
flag = Flag()