New function flagging decorator class to keep track permissions
This commit is contained in:
parent
6750682e4f
commit
adffbd1973
1 changed files with 22 additions and 0 deletions
22
src/util/Flag.py
Normal file
22
src/util/Flag.py
Normal 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()
|
Loading…
Reference in a new issue