feat: build access level labels from their bits and project names
Labels came from a fixed table matched by subset, so Storage (no bits) matched any level the table lacked, and a level was named after the first entry it contained: the server's Brain/MINDS 2.0 folders (0x10000) showed as Storage and 0x10104 as CBS or PW Open. Labels are now composed from the bits. Projects (bit 16 and up) take the names the server reports to their members through users/current/, and otherwise Project<n>; restrict slot 1 is CBS and any other Restrict<n>. A level with no meaning is shown as Unknown (0x...). chacl reads keys built the same way, refuses public and storage before any request, and lists the user's projects with their keys when given an invalid level.
This commit is contained in:
@@ -3,6 +3,7 @@ import re
|
||||
from unicodedata import normalize
|
||||
|
||||
from mdrsclient.api import DoiApi, FilesApi, FoldersApi, LaboratoriesApi, UsersApi
|
||||
from mdrsclient.api.utils import token_check
|
||||
from mdrsclient.cache import CacheInterface
|
||||
from mdrsclient.config import ConfigFile, ConfigInterface
|
||||
from mdrsclient.connection import MDRSConnection
|
||||
@@ -66,6 +67,17 @@ class MdrsService:
|
||||
def logout(self) -> None:
|
||||
self.connection.logout()
|
||||
|
||||
def project_names(self) -> dict[int, str]:
|
||||
"""
|
||||
Names of the logged-in user's projects by bit_position, for labelling access levels.
|
||||
|
||||
Empty when nobody is logged in: the server names a project only to its members.
|
||||
"""
|
||||
token_check(self.connection)
|
||||
if self.connection.token is None:
|
||||
return {}
|
||||
return UsersApi(self.connection).project_names()
|
||||
|
||||
def whoami(self) -> User:
|
||||
user_api = UsersApi(self.connection)
|
||||
return user_api.current()
|
||||
|
||||
Reference in New Issue
Block a user