Mercurial > libervia-backend
comparison sat/memory/memory.py @ 3319:3a15e76a694e
core (memory): `setFileAccessModel` implementation:
this method let change read permission using access model similar to what is used with
Pubsub.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Aug 2020 16:07:39 +0200 |
parents | 460606155bec |
children | 4f1fcee83d36 |
comparison
equal
deleted
inserted
replaced
3318:460606155bec | 3319:3a15e76a694e |
---|---|
1407 file_data=file_data, | 1407 file_data=file_data, |
1408 affiliations=affiliations | 1408 affiliations=affiliations |
1409 ), | 1409 ), |
1410 ) | 1410 ) |
1411 | 1411 |
1412 def _setFileAccessModelUpdate( | |
1413 self, | |
1414 access: dict, | |
1415 file_data: dict, | |
1416 access_model: str | |
1417 ) -> None: | |
1418 read_data = access.setdefault(C.ACCESS_PERM_READ, {}) | |
1419 if access_model == "open": | |
1420 requested_type = C.ACCESS_TYPE_PUBLIC | |
1421 elif access_model == "whitelist": | |
1422 requested_type = C.ACCESS_TYPE_WHITELIST | |
1423 else: | |
1424 raise ValueError(f"unknown access model: {access_model}") | |
1425 | |
1426 read_data['type'] = requested_type | |
1427 if requested_type == C.ACCESS_TYPE_WHITELIST and 'jids' not in read_data: | |
1428 read_data['jids'] = [] | |
1429 | |
1430 async def setFileAccessModel( | |
1431 self, | |
1432 client, | |
1433 file_data: dict, | |
1434 access_model: str, | |
1435 ) -> None: | |
1436 """Apply pubsub like access_model to file_data | |
1437 | |
1438 Only 2 access models are supported so far: | |
1439 - "open": set public access to file/dir | |
1440 - "whitelist": set whitelist to file/dir | |
1441 """ | |
1442 file_id = file_data['id'] | |
1443 await self.fileUpdate( | |
1444 file_id, | |
1445 'access', | |
1446 update_cb=partial( | |
1447 self._setFileAccessModelUpdate, | |
1448 file_data=file_data, | |
1449 access_model=access_model | |
1450 ), | |
1451 ) | |
1452 | |
1412 @defer.inlineCallbacks | 1453 @defer.inlineCallbacks |
1413 def getFiles( | 1454 def getFiles( |
1414 self, client, peer_jid, file_id=None, version=None, parent=None, path=None, | 1455 self, client, peer_jid, file_id=None, version=None, parent=None, path=None, |
1415 type_=None, file_hash=None, hash_algo=None, name=None, namespace=None, | 1456 type_=None, file_hash=None, hash_algo=None, name=None, namespace=None, |
1416 mime_type=None, public_id=None, owner=None, access=None, projection=None, | 1457 mime_type=None, public_id=None, owner=None, access=None, projection=None, |