Repository URL to install this package:
|
Version:
0.6.6.dev0 ▾
|
from enum import Enum
# Trie definition using python dict with leafs encoded as keys
# pointing to None or elements of a list
ABILITIES_TRIE = {
"adminUser": [
"createEditDelete",
],
"user": {
"create": None,
"editDeleteAny": None,
"editDeleteOwn": None,
"listAll": None,
"listOwn": None,
"fullName": ["edit"],
"permission": [
"editAny",
"editOwn",
],
},
"group": [
"create",
"editAny",
"editOwn",
"listAll",
"listOwn",
],
"dataset": [
"listAll",
"listOwn",
"create",
"createFromFile",
"editAny",
"editOwn",
"use",
],
"dataconnection": [
"create",
"listAll",
"editAny",
],
"privacyPolicy": [
"createGlobal",
"editGlobal",
"createLocal",
"editOwn",
],
"sdk": [
"access",
],
}
def generate_values(trie, prefix=""):
"""
Build the list of abilities from the trie
"""
if isinstance(trie, list):
return [f"{prefix}{val}" for val in trie]
if not isinstance(trie, dict):
raise ValueError("Expecting either dict or list")
values = []
for k, v in trie.items():
if v is None:
values.append(f"{prefix}{k}")
else:
values.extend(generate_values(v, prefix=f"{prefix}{k}."))
return values
ABILITIES = generate_values(ABILITIES_TRIE)
# this enum type is just an enhanced string type. It should be used to
# ensure a string value is in the enumeration domain using indexing
# with the following syntax: AbilityEnum[ability_name] It inherits
# from the str class and the instances will be serialized by the json
# module as a string.
AbilityEnum = Enum("Ability", type=str, names=zip(ABILITIES, ABILITIES))