Skip to content

Commit

Permalink
fix cluster serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Nov 14, 2024
1 parent 6e0dc86 commit 5e69184
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/models-library/src/models_library/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from typing import Final, Literal, TypeAlias

from models_library.utils._original_fastapi_encoders import jsonable_encoder
from pydantic import (
AnyUrl,
BaseModel,
Expand Down Expand Up @@ -224,18 +225,24 @@ class Cluster(BaseCluster):
@model_validator(mode="before")
@classmethod
def check_owner_has_access_rights(cls, values):
values = jsonable_encoder(values)

is_default_cluster = bool(values["id"] == DEFAULT_CLUSTER_ID)
owner_gid = values["owner"]

# check owner is in the access rights, if not add it
access_rights = values.get("access_rights", values.get("accessRights", {}))
if owner_gid not in access_rights:
access_rights[owner_gid] = (
CLUSTER_USER_RIGHTS if is_default_cluster else CLUSTER_ADMIN_RIGHTS
CLUSTER_USER_RIGHTS.model_dump()
if is_default_cluster
else CLUSTER_ADMIN_RIGHTS.model_dump()
)
# check owner has the expected access
if access_rights[owner_gid] != (
CLUSTER_USER_RIGHTS if is_default_cluster else CLUSTER_ADMIN_RIGHTS
CLUSTER_USER_RIGHTS.model_dump()
if is_default_cluster
else CLUSTER_ADMIN_RIGHTS.model_dump()
):
msg = f"the cluster owner access rights are incorrectly set: {access_rights[owner_gid]}"
raise ValueError(msg)
Expand Down

0 comments on commit 5e69184

Please sign in to comment.