Skip to content

Commit

Permalink
BUG: Update ssdl.accsess_level if depricated value (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbjorge authored Mar 19, 2024
1 parent c7a73dd commit f77f77a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
33 changes: 21 additions & 12 deletions src/fmu/dataio/datastructure/configuration/global_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ class Ssdl(BaseModel):
default=False,
)

@model_validator(mode="after")
def _migrate_asset_to_restricted(self) -> Ssdl:
if self.access_level == enums.AccessLevel.asset:
warnings.warn(
"The value 'asset' for access.ssdl.access_level is deprecated. "
"Please use 'restricted' in input arguments or global variables "
"to silence this warning.",
FutureWarning,
)
self.access_level = enums.AccessLevel.restricted
return self


class Asset(BaseModel):
"""
Expand All @@ -75,18 +87,15 @@ class Access(BaseModel):

asset: Asset
ssdl: Ssdl
classification: Optional[enums.AccessLevel] = Field(
default=enums.AccessLevel.internal,
)

@model_validator(mode="before")
@classmethod
def _classification_mirros_accesslevel(cls, values: Dict) -> Dict:
if isinstance(ssdl := values.get("ssdl", {}), dict):
values["classification"] = ssdl.get("access_level")
if values["classification"] == "asset":
values["classification"] = "restricted"
return values
classification: Optional[enums.AccessLevel] = Field(default=None)

@model_validator(mode="after")
def _classification_mirrors_accesslevel(self) -> Access:
# Ideally we want to only copy if the user has NOT
# set the classification.
# See: https://github.com/equinor/fmu-dataio/issues/540
self.classification = self.ssdl.access_level
return self


class StratigraphyElement(BaseModel):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_units/test_global_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def test_access_classification_mirrors():

# classification should be set to restricted if
# ssdl.access_level => asset
global_configuration.Access.model_validate(
gc = global_configuration.Access.model_validate(
{
"asset": {"name": "FakeName"},
"ssdl": {"access_level": "asset"},
}
).classification == "restricted"
)
assert gc.classification == "restricted"
assert gc.ssdl.access_level == "restricted"
15 changes: 9 additions & 6 deletions tests/test_units/test_metadata_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,18 @@ def test_metadata_access_deprecated_input(globalconfig1):
"""Test giving deprecated input."""
# Input is "asset". Is deprecated, shall work with warning.
# Output shall be "restricted".
edata = dio.ExportData(
config=globalconfig1, access_ssdl={"access_level": "asset"}, content="depth"
)
mymeta = MetaData("dummy", edata)
with pytest.warns(
UserWarning,
FutureWarning,
match="The value 'asset' for access.ssdl.access_level is deprec",
):
mymeta._populate_meta_access()
edata = dio.ExportData(
config=globalconfig1,
access_ssdl={"access_level": "asset"},
content="depth",
)

mymeta = MetaData("dummy", edata)
mymeta._populate_meta_access()
assert mymeta.meta_access["ssdl"]["access_level"] == "restricted"
assert mymeta.meta_access["classification"] == "restricted"

Expand Down

0 comments on commit f77f77a

Please sign in to comment.