nsarchive 3.0.0a3__tar.gz → 3.0.0a4__tar.gz
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.
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/PKG-INFO +1 -1
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/__init__.py +1 -1
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/cls/entities.py +21 -11
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/instances/_entities.py +71 -17
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/pyproject.toml +1 -1
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/LICENSE +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/README.md +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/assets/default_avatar.png +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/cls/archives.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/cls/base.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/cls/economy.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/cls/republic.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/instances/_economy.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/instances/_republic.py +0 -0
- {nsarchive-3.0.0a3 → nsarchive-3.0.0a4}/nsarchive/utils.py +0 -0
@@ -71,10 +71,28 @@ class Position:
|
|
71
71
|
self.name: str = "Inconnue"
|
72
72
|
self.id = id
|
73
73
|
self.permissions: PositionPermissions = PositionPermissions()
|
74
|
+
self.manager_permissions: PositionPermissions = PositionPermissions()
|
75
|
+
|
76
|
+
self._url: str = ""
|
74
77
|
|
75
78
|
def __repr__(self):
|
76
79
|
return self.id
|
77
80
|
|
81
|
+
def update_permisions(self, **permissions: str):
|
82
|
+
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in permissions.items())
|
83
|
+
|
84
|
+
res = requests.post(f"{self._url}/update_permissions?{query}", headers = default_headers)
|
85
|
+
|
86
|
+
if res.status_code == 200:
|
87
|
+
self.permissions.merge(permissions)
|
88
|
+
else:
|
89
|
+
res.raise_for_status()
|
90
|
+
|
91
|
+
def _load(self, _data: dict):
|
92
|
+
self.name = _data['name']
|
93
|
+
self.permissions.merge(_data['permissions'])
|
94
|
+
self.manager_permissions.merge(_data['manager_permissions'])
|
95
|
+
|
78
96
|
class Entity:
|
79
97
|
"""
|
80
98
|
Classe de référence pour les entités
|
@@ -285,19 +303,14 @@ class Organization(Entity):
|
|
285
303
|
super().__init__(NSID(id))
|
286
304
|
|
287
305
|
self.owner: Entity = User(NSID(0x0))
|
288
|
-
self.
|
306
|
+
self.avatar_url: str = self._url + '/avatar'
|
289
307
|
|
290
308
|
self.certifications: dict = {}
|
291
309
|
self.members: list[GroupMember] = []
|
292
310
|
self.invites: dict[GroupInvite] = []
|
293
311
|
|
294
312
|
def _load(self, _data: dict):
|
295
|
-
|
296
|
-
|
297
|
-
if res.status_code == 200:
|
298
|
-
self.avatar = res.content
|
299
|
-
else:
|
300
|
-
warnings.warn(f"Failed to get avatar for {self.id}")
|
313
|
+
self.avatar_url = self._url + '/avatar'
|
301
314
|
|
302
315
|
for _member in _data['members']:
|
303
316
|
member = GroupMember(_member['id'])
|
@@ -356,7 +369,4 @@ class Organization(Entity):
|
|
356
369
|
return [ member.__getattribute__(attribute) for member in self.members ]
|
357
370
|
|
358
371
|
def save_avatar(self, data: bytes = None):
|
359
|
-
|
360
|
-
return
|
361
|
-
|
362
|
-
self.avatar = data
|
372
|
+
pass
|
@@ -51,29 +51,34 @@ class EntityInstance(Instance):
|
|
51
51
|
|
52
52
|
if _data is None: # ID inexistant chez les entités
|
53
53
|
return None
|
54
|
-
elif "xp" in _data.keys():
|
55
|
-
_data['_type'] = 'user'
|
56
|
-
elif "members" in _data.keys():
|
57
|
-
_data['_type'] = 'organization'
|
58
|
-
else:
|
59
|
-
_data['_type'] = 'entity'
|
60
54
|
|
61
|
-
if _data['
|
55
|
+
if _data['_class'] == 'user':
|
62
56
|
entity = User(id)
|
63
57
|
entity._url = f"{self.url}/model/individuals/{id}"
|
64
58
|
|
65
59
|
entity._load(_data)
|
66
|
-
elif _data['
|
60
|
+
elif _data['_class'] == 'organization':
|
67
61
|
entity = Organization(id)
|
68
62
|
entity._url = f"{self.url}/model/organizations/{id}"
|
69
|
-
|
63
|
+
|
64
|
+
_owner = _data['owner']
|
65
|
+
|
66
|
+
if _owner['_class'] == 'individuals':
|
67
|
+
entity.owner = User(_owner['id'])
|
68
|
+
entity.owner._load(_owner)
|
69
|
+
elif _owner['class'] == 'organizations':
|
70
|
+
entity.owner = Organization(_owner['id'])
|
71
|
+
entity.owner._load(_owner)
|
72
|
+
else:
|
73
|
+
entity.owner = self.get_entity(0x0)
|
70
74
|
|
71
75
|
entity._load(_data)
|
72
76
|
else:
|
73
77
|
entity = Entity(id)
|
78
|
+
entity._url = f"{self.url}/model/entities/{id}"
|
74
79
|
|
75
80
|
entity.name = _data['name']
|
76
|
-
entity.position
|
81
|
+
entity.position._load(_data['position']) # Métier si c'est un utilisateur, domaine professionnel si c'est un collectif
|
77
82
|
entity.registerDate = _data['register_date']
|
78
83
|
|
79
84
|
for key, value in _data.get('additional', {}).items():
|
@@ -82,6 +87,8 @@ class EntityInstance(Instance):
|
|
82
87
|
else:
|
83
88
|
entity.additional[key] = value
|
84
89
|
|
90
|
+
entity.position._url = f"{self.url}/positions/{id}"
|
91
|
+
|
85
92
|
return entity
|
86
93
|
|
87
94
|
def get_entity_groups(self, entity: User) -> list[Organization]:
|
@@ -176,20 +183,65 @@ class EntityInstance(Instance):
|
|
176
183
|
- `list[.Entity | .User | .Organization]`
|
177
184
|
"""
|
178
185
|
|
179
|
-
if "
|
180
|
-
if query["
|
181
|
-
del query["
|
186
|
+
if "_class" in query.keys():
|
187
|
+
if query["_class"] == "individuals":
|
188
|
+
del query["_class"]
|
182
189
|
_res = self.fetch('individuals', **query)
|
183
|
-
elif query["
|
184
|
-
del query["
|
190
|
+
elif query["_class"] == "organizations":
|
191
|
+
del query["_class"]
|
185
192
|
_res = self.fetch('organizations', **query)
|
186
193
|
else:
|
187
|
-
del query["
|
194
|
+
del query["_class"]
|
188
195
|
_res = self.fetch('entities', **query)
|
189
196
|
else:
|
190
197
|
_res = self.fetch('entities', **query)
|
191
198
|
|
192
|
-
|
199
|
+
res = []
|
200
|
+
|
201
|
+
for _entity in _res:
|
202
|
+
if _entity is None: continue
|
203
|
+
|
204
|
+
if _entity['_class'] == 'individuals':
|
205
|
+
entity = User(_entity["id"])
|
206
|
+
entity._url = f"{self.url}/model/individuals/{_entity['id']}"
|
207
|
+
|
208
|
+
entity._load(_entity)
|
209
|
+
elif _entity['_class'] == 'organizations':
|
210
|
+
entity = Organization(_entity["id"])
|
211
|
+
entity._url = f"{self.url}/model/organizations/{_entity['id']}"
|
212
|
+
|
213
|
+
_owner = _entity['owner']
|
214
|
+
if _owner['_class'] == 'individuals':
|
215
|
+
entity.owner = User(_owner['id'])
|
216
|
+
entity.owner._load(_owner)
|
217
|
+
elif _owner['class'] == 'organizations':
|
218
|
+
entity.owner = Organization(_owner['id'])
|
219
|
+
entity.owner._load(_owner)
|
220
|
+
else:
|
221
|
+
entity.owner = self.get_entity(0x0)
|
222
|
+
|
223
|
+
entity._load(_entity)
|
224
|
+
else:
|
225
|
+
entity = Entity(_entity["id"])
|
226
|
+
entity._url = f"{self.url}/model/organizations/{_entity['id']}"
|
227
|
+
|
228
|
+
entity.name = _entity['name']
|
229
|
+
entity.position._load(_entity['position'])
|
230
|
+
entity.registerDate = _entity['register_date']
|
231
|
+
|
232
|
+
for key, value in _entity.get('additional', {}).items():
|
233
|
+
if isinstance(value, str) and value.startswith('\n'):
|
234
|
+
entity.additional[key] = int(value[1:])
|
235
|
+
else:
|
236
|
+
entity.additional[key] = value
|
237
|
+
|
238
|
+
entity.position._url = f"{self.url}/positions/{_entity['id']}"
|
239
|
+
|
240
|
+
res.append(entity)
|
241
|
+
|
242
|
+
return res
|
243
|
+
|
244
|
+
|
193
245
|
|
194
246
|
def get_position(self, id: str) -> Position:
|
195
247
|
"""
|
@@ -209,7 +261,9 @@ class EntityInstance(Instance):
|
|
209
261
|
return None
|
210
262
|
|
211
263
|
position = Position(id)
|
264
|
+
position._url = f"{self.url}/positions/{id}"
|
212
265
|
position.name = _data['name']
|
213
266
|
position.permissions.merge(_data['permissions'])
|
267
|
+
position.manager_permissions.merge(_data['manager_permissions'])
|
214
268
|
|
215
269
|
return position
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|