add UI selector for user ratings (group or own)

Allow a user to access their own dataset.
Add a route for admins to give users access to groups.
This commit is contained in:
ducklet 2021-08-05 15:53:27 +02:00
parent fb059ae5d1
commit 69eb68a9a4
4 changed files with 111 additions and 14 deletions

View file

@ -276,6 +276,13 @@ class Rating:
)
Access = Literal[
"r", # read
"i", # index
"w", # write
]
@dataclass
class User:
_table: ClassVar[str] = "users"
@ -286,9 +293,18 @@ class User:
secret: str = None
groups: list[dict[str, str]] = field(default_factory=list)
def has_access(self, group_id: Union[ULID, str], access: Literal["r", "w"] = "r"):
def has_access(self, group_id: Union[ULID, str], access: Access = "r"):
group_id = group_id if isinstance(group_id, str) else str(group_id)
return any(g["id"] == group_id and access in g["access"] for g in self.groups)
return any(g["id"] == group_id and access == g["access"] for g in self.groups)
def set_access(self, group_id: Union[ULID, str], access: Access):
group_id = group_id if isinstance(group_id, str) else str(group_id)
for g in self.groups:
if g["id"] == group_id:
g["access"] = access
break
else:
self.groups.append({"id": group_id, "access": access})
@dataclass