Skip to content

Commit 82c618a

Browse files
NRL-2099 Generalise add and remove permission functions to allow any permission to be added or removed once we know the full list of available items e.g. for interactions, all consumer interactions etc. Left in an example for categories - a currently unsupported permission key
1 parent b993da5 commit 82c618a

File tree

2 files changed

+264
-198
lines changed

2 files changed

+264
-198
lines changed

layer/nrlf/core/constants.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,61 @@ def list():
6565
return [control.value for control in AccessControls]
6666

6767

68+
class SupplierType(Enum):
69+
PRODUCER = "producer"
70+
CONSUMER = "consumer"
71+
72+
@staticmethod
73+
def list():
74+
return [supplier.value for supplier in SupplierType]
75+
76+
77+
class V2PermissionKey(Enum):
78+
ACCESS_CONTROLS = "access_controls"
79+
TYPES = "types"
80+
CATEGORIES = "categories"
81+
INTERACTIONS = "interactions"
82+
PRODUCE_FOR_AUTHORS = "produce_for_authors"
83+
PRODUCE_FOR_CUSTODIANS = "produce_for_custodians"
84+
85+
@staticmethod
86+
def list():
87+
return [permission_key.value for permission_key in V2PermissionKey]
88+
89+
def human_readable(self, plural=False):
90+
human_lookup = {
91+
V2PermissionKey.ACCESS_CONTROLS.value: {
92+
"singular": "access control",
93+
"plural": "access controls",
94+
},
95+
V2PermissionKey.TYPES.value: {
96+
"singular": "pointer type",
97+
"plural": "pointer types",
98+
},
99+
V2PermissionKey.CATEGORIES.value: {
100+
"singular": "category",
101+
"plural": "categories",
102+
},
103+
V2PermissionKey.INTERACTIONS.value: {
104+
"singular": "interaction",
105+
"plural": "interactions",
106+
},
107+
V2PermissionKey.PRODUCE_FOR_AUTHORS.value: {
108+
"singular": "produce for author",
109+
"plural": "produce for authors",
110+
},
111+
V2PermissionKey.PRODUCE_FOR_CUSTODIANS.value: {
112+
"singular": "produce for custodian",
113+
"plural": "produce for custodians",
114+
},
115+
}
116+
117+
if plural:
118+
return human_lookup.get(self.value)["plural"]
119+
120+
return human_lookup.get(self.value)["singular"]
121+
122+
68123
NHSD_REQUEST_ID_HEADER = "NHSD-Request-Id"
69124
NHSD_CORRELATION_ID_HEADER = "NHSD-Correlation-Id"
70125
X_REQUEST_ID_HEADER = "X-Request-Id"

0 commit comments

Comments
 (0)