AareDAQ: Handle p-groups correctly (as a list) in the server
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import base64
|
||||
import io
|
||||
import json
|
||||
from typing import Tuple
|
||||
from typing import Tuple, List
|
||||
|
||||
import numpy as np
|
||||
import redis
|
||||
@@ -296,9 +296,9 @@ class BeamlineConfig:
|
||||
data_dict = json.loads(tmp)
|
||||
return SampleShortInfoList(**data_dict)
|
||||
|
||||
def spreadsheet_pgroup(self, pgroup: str) -> SampleShortInfoList:
|
||||
def spreadsheet_pgroup(self, pgroups: List[str]) -> SampleShortInfoList:
|
||||
sample = self.spreadsheet
|
||||
sample.s = list(filter(lambda x: x.user == pgroup, sample.s))
|
||||
sample.s = list(filter(lambda x: x.user in pgroups, sample.s))
|
||||
return sample
|
||||
|
||||
@spreadsheet.setter
|
||||
|
||||
@@ -183,7 +183,7 @@ async def sample(token: str = Depends(oauth2_scheme)) -> SampleShortInfo:
|
||||
token_data = auth.parse_token(token)
|
||||
auth.check_jwt_ro(cfg, auth.parse_token(token))
|
||||
s = daq.sample
|
||||
if token_data.staff or token_data.group == s.user:
|
||||
if token_data.staff or s.user in token_data.pgroups:
|
||||
return daq.sample
|
||||
else:
|
||||
return SampleShortInfo(
|
||||
@@ -209,7 +209,7 @@ async def mount(dbid: int, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
if index == -1:
|
||||
raise RuntimeError("Sample not found")
|
||||
if token_data.staff or token_data.group == st.s[index].user:
|
||||
if token_data.staff or st.s[index].user in token_data.pgroups:
|
||||
daq.sample = st.s[index]
|
||||
return "OK"
|
||||
else:
|
||||
@@ -239,7 +239,7 @@ def get_spreadsheet(data: TokenData) -> SampleShortInfoList:
|
||||
if data.staff:
|
||||
return cfg.spreadsheet
|
||||
else:
|
||||
return cfg.spreadsheet_pgroup(data.group)
|
||||
return cfg.spreadsheet_pgroup(data.pgroups)
|
||||
|
||||
|
||||
async def spreadsheet_event_stream(data: TokenData) -> AsyncGenerator[str, None]:
|
||||
|
||||
Reference in New Issue
Block a user