Skip to content

Commit 1f69e8a

Browse files
add access levels and public groups
1 parent 3cdf3ff commit 1f69e8a

5 files changed

Lines changed: 74 additions & 19 deletions

File tree

dsms/core/configuration.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,33 @@ class Loglevel(Enum):
4343
WARNING = logging.WARNING
4444

4545

46-
class Configuration(BaseSettings):
46+
class BaseConfiguration(BaseSettings):
47+
"""Base Configuration for DSMS-SDK"""
48+
49+
label_internally_public: str = Field(
50+
"Internally Public",
51+
description="Label to use for KItems marked as `internally_public`.",
52+
)
53+
54+
label_externally_public: str = Field(
55+
"Externally Public",
56+
description="Label to use for KItems marked as `externally_public`.",
57+
)
58+
59+
id_internally_public: str = Field(
60+
"dsms:internally-public",
61+
description="ID to use for KItems marked as `internally_public`.",
62+
)
63+
64+
id_externally_public: str = Field(
65+
"dsms:externally-public",
66+
description="ID to use for KItems marked as `externally_public`.",
67+
)
68+
69+
model_config = ConfigDict(use_enum_values=True)
70+
71+
72+
class Configuration(BaseConfiguration):
4773
"""General config for DSMS-SDK"""
4874

4975
host_url: AnyUrl = Field(

dsms/knowledge/groups/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""DSMS User Groups Module."""
2+
3+
from .models import Group, GroupList, GroupListBase
4+
from .public import INTERNALLY_PUBLIC_GROUP, EXTERNALLY_PUBLIC_GROUP
5+
6+
__all__ = ["Group", "GroupList", "GroupListBase", "INTERNALLY_PUBLIC_GROUP", "EXTERNALLY_PUBLIC_GROUP"]
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""DSMS User Groups Module."""
22

3-
from enum import Enum
43
from typing import List, Optional
54

65
import yaml
@@ -9,13 +8,6 @@
98
from dsms.core.session import Session
109

1110

12-
class PublicGroupType(str, Enum):
13-
"""Enumeration for Public Group Types."""
14-
15-
INTERNAL = "dsms:internally-public"
16-
EXTERNAL = "dsms:externally-public"
17-
18-
1911
class User(BaseModel):
2012
"""User Model"""
2113

@@ -76,3 +68,7 @@ def _flatten(groups: List[Group]):
7668

7769

7870
Group.model_rebuild()
71+
interally_public = Group(id="dsms:internally_public", name="Internally Public")
72+
externally_public = Group(
73+
id="dsms:externally_public", name="Externally Public"
74+
)

dsms/knowledge/groups/public.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""DSMS Public User Groups Module."""
2+
3+
from .models import Group
4+
5+
from dsms.core.session import Session
6+
from dsms.core.configuration import BaseConfiguration
7+
8+
9+
if not Session.dsms:
10+
config = BaseConfiguration()
11+
else:
12+
config = Session.dsms.config
13+
14+
# The internally/externally public group objects will generally
15+
# be served by the user-service, but we define them here for uniquely
16+
# setting the ids and names in a common place.
17+
# They can be adapted through environment variables anyway.
18+
# A common place is needed because the group objects are used in various places
19+
# such as internally within the knowledge service, the user service, and the SDK itself.
20+
# If the IDs and names of these public groups are only delivered in the user service,
21+
# we cannot distinguish them from the ones which come from keycloak - indicating only organizational groups.
22+
23+
INTERNALLY_PUBLIC_GROUP = Group(
24+
id=config.id_internally_public,
25+
name=config.label_internally_public,
26+
)
27+
28+
EXTERNALLY_PUBLIC_GROUP = Group(
29+
id=config.id_externally_public,
30+
name=config.label_externally_public,
31+
)

dsms/knowledge/properties/access.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,18 @@ def get_operations(cls, role: Role) -> List[OperationType]:
5252
def min_access_level(cls, operation: OperationType) -> Role:
5353
"""Get minimum role required for an operation"""
5454
return min(
55-
[
56-
role.value
57-
for role in Role
58-
if operation in cls.get_operations(role)
59-
]
55+
role.value
56+
for role in Role
57+
if operation in cls.get_operations(role)
6058
)
6159

6260
@classmethod
6361
def max_access_level(cls, operation: OperationType) -> Role:
6462
"""Get maximum role required for an operation"""
6563
return max(
66-
[
67-
role.value
68-
for role in Role
69-
if operation in cls.get_operations(role)
70-
]
64+
role.value
65+
for role in Role
66+
if operation in cls.get_operations(role)
7167
)
7268

7369

0 commit comments

Comments
 (0)