oldaplib 0.3.30__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -168,6 +168,45 @@ class Connection(IConnection):
168
168
  if userId is None:
169
169
  logger.error("Connection with wrong credentials")
170
170
  raise OldapError("Wrong credentials")
171
+
172
+ auth = HTTPBasicAuth(self._dbuser, self._dbpassword) if self._dbuser and self._dbpassword else None
173
+ #
174
+ # Get projects and add to Context
175
+ #
176
+ sparql = context.sparql_context
177
+ sparql += """
178
+ SELECT ?sname ?ns
179
+ FROM oldap:onto
180
+ FROM shared:onto
181
+ FROM NAMED oldap:admin
182
+ WHERE {
183
+ GRAPH oldap:admin {
184
+ ?proj a oldap:Project .
185
+ ?proj oldap:projectShortName ?sname .
186
+ ?proj oldap:namespaceIri ?ns .
187
+ }
188
+ }
189
+ """
190
+ headers = {
191
+ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
192
+ "Accept": "application/x-sparqlstar-results+json, application/sparql-results+json;q=0.9, */*;q=0.8",
193
+ }
194
+ data = {
195
+ 'query': sparql,
196
+ }
197
+ res = requests.post(url=self._query_url, headers=headers, data=data, auth=auth)
198
+ if res.status_code == 200:
199
+ jsonobj = res.json()
200
+ else:
201
+ logger.error(f"Could not connect to triplestore: {res.text}")
202
+ raise OldapError(res.status_code, res.text)
203
+ res = QueryProcessor(context=context, query_result=jsonobj)
204
+ for r in res:
205
+ context[r['sname']] = r['ns']
206
+
207
+ #
208
+ # Query the user data
209
+ #
171
210
  sparql = UserData.sparql_query(context=context, userId=userId)
172
211
  headers = {
173
212
  "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
@@ -179,7 +218,6 @@ class Connection(IConnection):
179
218
  #
180
219
  # if we have protected the triplestore by a user/password, add it to the request
181
220
  #
182
- auth = HTTPBasicAuth(self._dbuser, self._dbpassword) if self._dbuser and self._dbpassword else None
183
221
  res = requests.post(url=self._query_url, headers=headers, data=data, auth=auth)
184
222
  if res.status_code == 200:
185
223
  jsonobj = res.json()
@@ -209,39 +247,6 @@ class Connection(IConnection):
209
247
  payload=payload,
210
248
  key=self.__jwtkey,
211
249
  algorithm="HS256")
212
- #
213
- # Get projects and add to Context
214
- #
215
- sparql = context.sparql_context
216
- sparql += """
217
- SELECT ?sname ?ns
218
- FROM oldap:onto
219
- FROM shared:onto
220
- FROM NAMED oldap:admin
221
- WHERE {
222
- GRAPH oldap:admin {
223
- ?proj a oldap:Project .
224
- ?proj oldap:projectShortName ?sname .
225
- ?proj oldap:namespaceIri ?ns .
226
- }
227
- }
228
- """
229
- headers = {
230
- "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
231
- "Accept": "application/x-sparqlstar-results+json, application/sparql-results+json;q=0.9, */*;q=0.8",
232
- }
233
- data = {
234
- 'query': sparql,
235
- }
236
- res = requests.post(url=self._query_url, headers=headers, data=data, auth=auth)
237
- if res.status_code == 200:
238
- jsonobj = res.json()
239
- else:
240
- logger.error(f"Could not connect to triplestore: {res.text}")
241
- raise OldapError(res.status_code, res.text)
242
- res = QueryProcessor(context=context, query_result=jsonobj)
243
- for r in res:
244
- context[r['sname']] = r['ns']
245
250
  logger.info(f'Connection established. User "{str(self._userdata.userId)}".')
246
251
 
247
252
  @staticmethod
@@ -21,7 +21,7 @@ class AdminPermission(Enum):
21
21
  """
22
22
  ADMIN_OLDAP = 'oldap:ADMIN_OLDAP' # Quasi root permission. This user can do everything (**dangerous!**)
23
23
  ADMIN_USERS = 'oldap:ADMIN_USERS' # Allows to add/modify/delete users for the project this permission is given for
24
- ADMIN_PERMISSION_SETS = 'oldap:ADMIN_PERMISSION_SETS' # Allows to add/modify/delete PermissionSets
24
+ ADMIN_ROLES = 'oldap:ADMIN_ROLES' # Allows to add/modify/delete Roles
25
25
  ADMIN_RESOURCES = 'oldap:ADMIN_RESOURCES' # Override resources permission for the resources in the given project
26
26
  ADMIN_MODEL = 'oldap:ADMIN_MODEL' # Change the data model
27
27
  ADMIN_CREATE = 'oldap:ADMIN_CREATE' # Create new resources in the given project
@@ -35,10 +35,14 @@ class PermissionWithValue(Enum):
35
35
  def numeric(self) -> Xsd_integer:
36
36
  return self._numeric
37
37
 
38
- def __eq__(self, other: Self) -> bool:
38
+ def __eq__(self, other: Self | None) -> bool:
39
+ if other is None:
40
+ return False
39
41
  return self._numeric == other._numeric
40
42
 
41
- def __ne__(self, other: Self) -> bool:
43
+ def __ne__(self, other: Self | None) -> bool:
44
+ if other is None:
45
+ return True
42
46
  return self._numeric != other._numeric
43
47
 
44
48
  def __gt__(self, other: Self) -> bool:
@@ -76,15 +80,20 @@ class DataPermission(PermissionWithValue):
76
80
  DATA_DELETE = ('oldap:DATA_DELETE', 5) # Allow to delete complete resource
77
81
  DATA_PERMISSIONS = ('oldap:DATA_PERMISSIONS', 6) # Allow to modify permissions of resource
78
82
 
83
+ def __str__(self) -> str:
84
+ return self.to_string()
85
+
79
86
  @property
80
87
  def toRdf(self):
81
88
  return self.value
82
89
 
83
- def to_string(self):
90
+ def to_string(self) -> str:
84
91
  return self.name.removeprefix("oldap:")
85
92
 
86
93
  @classmethod
87
- def from_string(cls, permission_string: str) -> Self:
94
+ def from_string(cls, permission_string: str | None) -> Self | None:
95
+ if permission_string is None:
96
+ return None
88
97
  if not permission_string.startswith('oldap:'):
89
98
  permission_string = f'oldap:{permission_string}'
90
99
  for member in cls:
@@ -92,3 +101,14 @@ class DataPermission(PermissionWithValue):
92
101
  return member
93
102
  raise ValueError(f'{permission_string} is not in DataPermission enum.')
94
103
 
104
+ @classmethod
105
+ def from_qname(cls, permission_string: Xsd_QName | None) -> Self | None:
106
+ if permission_string is None:
107
+ return None
108
+ permission_string = str(permission_string)
109
+ for member in cls:
110
+ if f'oldap:{member.name}' == permission_string:
111
+ return member
112
+ raise ValueError(f'{permission_string} is not in DataPermission enum.')
113
+
114
+
@@ -9,10 +9,9 @@ from oldaplib.src.xsd.xsd_ncname import Xsd_NCName
9
9
 
10
10
 
11
11
  @unique
12
- class PermissionSetAttr(AttributeClass):
12
+ class RoleAttr(AttributeClass):
13
13
  # order: (QName, mandatory, immutable, datatype)
14
- PERMISSION_SET_ID = ('virtual:permissionSetId', True, True, Xsd_NCName) # virtual property, no equivalent in RDF
14
+ ROLE_ID = ('virtual:roleId', True, True, Xsd_NCName) # virtual property, no equivalent in RDF
15
15
  DEFINED_BY_PROJECT = ('oldap:definedByProject', True, True, IriOrNCName)
16
- GIVES_PERMISSION = ('oldap:givesPermission', True, False, DataPermission)
17
16
  LABEL = ('rdfs:label', False, False, LangString)
18
17
  COMMENT = ('rdfs:comment', False, False, LangString)
@@ -1,6 +1,7 @@
1
1
  from enum import unique, Enum
2
2
 
3
3
  from oldaplib.src.enums.attributeclass import AttributeClass
4
+ from oldaplib.src.helpers.observable_dict import ObservableDict
4
5
  from oldaplib.src.helpers.observable_set import ObservableSet
5
6
  from oldaplib.src.helpers.serializeableset import SerializeableSet
6
7
  from oldaplib.src.in_project import InProjectClass
@@ -22,7 +23,7 @@ class UserAttr(AttributeClass):
22
23
  - _UserFields.CREDENTIALS_ (RDF: 'oldap:credentials')
23
24
  - _UserFields.ACTIVE_ (RDF: 'oldap:isActive')
24
25
  - _UserFields.IN_PROJECT_ (RDF: 'oldap:inProject')
25
- - _UserFields.HAS_PERMISSIONS_ (RDF: 'oldap:hasPermissions')
26
+ - _UserFields.HAS_ROLE_ (RDF: 'oldap:hasRole')
26
27
  """
27
28
  # order: (QName, mandatory, immutable, datatype)
28
29
  USER_IRI = ('oldap:userIri', False, True, Iri)
@@ -33,5 +34,5 @@ class UserAttr(AttributeClass):
33
34
  CREDENTIALS = ('oldap:credentials', True, False, Xsd_string)
34
35
  ACTIVE = ('oldap:isActive', False, False, Xsd_boolean)
35
36
  IN_PROJECT = ('oldap:inProject', False, False, InProjectClass)
36
- HAS_PERMISSIONS = ('oldap:hasPermissions', False, False, ObservableSet)
37
+ HAS_ROLE = ('oldap:hasRole', False, False, ObservableDict)
37
38
 
@@ -6,6 +6,7 @@ from typing import Callable, Self, Iterable, Mapping
6
6
  from oldaplib.src.enums.action import Action
7
7
  from oldaplib.src.helpers.attributechange import AttributeChange
8
8
  from oldaplib.src.helpers.serializer import serializer
9
+ from oldaplib.src.xsd.xsd_qname import Xsd_QName
9
10
 
10
11
 
11
12
  @serializer
@@ -24,7 +24,6 @@ from oldaplib.src.helpers.serializer import serializer
24
24
  import json
25
25
 
26
26
 
27
- #@strict
28
27
  @serializer
29
28
  class InProjectClass(Notify):
30
29
  """