From adffbd1973a24f139ca92bb0353e2380b8185909 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Mon, 26 Aug 2019 02:55:01 +0200 Subject: [PATCH] New function flagging decorator class to keep track permissions --- src/util/Flag.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/util/Flag.py diff --git a/src/util/Flag.py b/src/util/Flag.py new file mode 100644 index 00000000..37cfdfba --- /dev/null +++ b/src/util/Flag.py @@ -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()