follow-up recent specification changes about foldeer access level.

This commit is contained in:
Yoshihiro OKUMURA 2023-10-04 12:49:13 +09:00
parent 79f1b708cb
commit ac34a26b02
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2

View File

@ -8,28 +8,37 @@ from mdrsclient.models.utils import iso8601_to_user_friendly
class FolderAccessLevelItem(NamedTuple):
id: int
mask: int
key: str
label: str
class FolderAccessLevel:
# Bit Mask
# - bit 0: Storage or Repository
# - bit 1: Is Public
# - bit 2: With Password
# - bit 3-7: (Reserved)
# - bit 8-15: Restricted Open
ACCESS_LEVELS: Final[list[FolderAccessLevelItem]] = [
FolderAccessLevelItem(-1, "storage", "Storage"),
FolderAccessLevelItem(0, "private", "Private"),
FolderAccessLevelItem(1, "cbs_open", "CBS Open"),
FolderAccessLevelItem(2, "pw_open", "PW Open"),
FolderAccessLevelItem(3, "public", "Public"),
FolderAccessLevelItem(0x0204, "5kikan_or_pw_open", "5Kikan or PW Open"),
FolderAccessLevelItem(0x0104, "cbs_or_pw_open", "CBS or PW Open"),
FolderAccessLevelItem(0x0200, "5kikan_open", "5Kikan Open"),
FolderAccessLevelItem(0x0100, "cbs_open", "CBS Open"),
FolderAccessLevelItem(0x0004, "pw_open", "PW Open"),
FolderAccessLevelItem(0x0002, "public", "Public"),
FolderAccessLevelItem(0x0001, "private", "Private"),
FolderAccessLevelItem(0x0000, "storage", "Storage"),
]
@staticmethod
def key2id(key: str) -> int | None:
acl = next((x for x in FolderAccessLevel.ACCESS_LEVELS if x.key == key), None)
return acl.id if acl is not None else None
return acl.mask if acl is not None else None
@staticmethod
def id2label(id: int) -> str | None:
acl = next((x for x in FolderAccessLevel.ACCESS_LEVELS if x.id == id), None)
acl = next((x for x in FolderAccessLevel.ACCESS_LEVELS if (x.mask & id) == x.mask), None)
return acl.label if acl is not None else None