Skip to content

Commit

Permalink
Update Scope format (#570)
Browse files Browse the repository at this point in the history
* update ScopeField

* update function call

* update test data

* update match_user_scopes
  • Loading branch information
fsimonjetz authored Jul 22, 2024
1 parent 05b282c commit 3d31567
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ def fetch_scopes(self, number: MuseumNumber) -> List[Scope]:
{},
)
return [
Scope.from_string(f"read:{value}-fragments")
for value in fragment.get("authorizedScopes", [])
Scope.from_string(value) for value in fragment.get("authorizedScopes", [])
]

def fetch_names(self, name_query: str) -> List[str]:
Expand Down
4 changes: 1 addition & 3 deletions ebl/fragmentarium/infrastructure/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def match_user_scopes(user_scopes: Sequence[Scope] = tuple()) -> dict:
]

if user_scopes:
allowed_scopes.extend(
{"authorizedScopes": scope.scope_name} for scope in user_scopes
)
allowed_scopes.extend({"authorizedScopes": str(scope)} for scope in user_scopes)

return {"$or": allowed_scopes}

Expand Down
4 changes: 2 additions & 2 deletions ebl/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def __init__(self, **kwargs):
super().__init__(Scope, **kwargs)

def _serialize_enum(self, value: Scope) -> str:
return value.scope_name
return str(value)

def _deserialize_enum(self, value: str) -> Enum:
return Scope.from_string(f"read:{value}-fragments")
return Scope.from_string(value)


class ResearchProjectField(EnumField):
Expand Down
4 changes: 2 additions & 2 deletions ebl/tests/fragmentarium/test_fragment_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
Scope.READ_SIPPARLIBRARY_FRAGMENTS,
]
SERIALIZED_SCOPES = [
"ITALIANNINEVEH",
"SIPPARLIBRARY",
"read:ITALIANNINEVEH-fragments",
"read:SIPPARLIBRARY-fragments",
]


Expand Down

0 comments on commit 3d31567

Please sign in to comment.