Skip to content

Commit adffbd1

Browse files
committed
New function flagging decorator class to keep track permissions
1 parent 6750682 commit adffbd1

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/util/Flag.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from collections import defaultdict
2+
3+
4+
class Flag(object):
5+
def __init__(self):
6+
self.valid_flags = set([
7+
"admin", # Only allowed to run sites with ADMIN permission
8+
"async_run", # Action will be ran async with gevent.spawn
9+
"no_multiuser" # Action disabled if Multiuser plugin running in open proxy mode
10+
])
11+
self.db = defaultdict(set)
12+
13+
def __getattr__(self, key):
14+
def func(f):
15+
if key not in self.valid_flags:
16+
raise Exception("Invalid flag: %s (valid: %s)" % (key, self.valid_flags))
17+
self.db[f.__name__].add(key)
18+
return f
19+
return func
20+
21+
22+
flag = Flag()

0 commit comments

Comments
 (0)