diff --git a/dsp_permissions_scripts/doap/doap_serialize.py b/dsp_permissions_scripts/doap/doap_serialize.py index d7eadc0b..1df59eb0 100644 --- a/dsp_permissions_scripts/doap/doap_serialize.py +++ b/dsp_permissions_scripts/doap/doap_serialize.py @@ -5,10 +5,7 @@ from dsp_permissions_scripts.doap.doap_model import Doap, DoapTargetType -def _get_file_path( - shortcode: str, - mode: Literal["original", "modified"] -) -> Path: +def _get_file_path(shortcode: str, mode: Literal["original", "modified"]) -> Path: return Path(f"project_data/{shortcode}/DOAPs_{mode}.json") diff --git a/dsp_permissions_scripts/doap/doap_set.py b/dsp_permissions_scripts/doap/doap_set.py index 0c68df3e..9ee85fa9 100644 --- a/dsp_permissions_scripts/doap/doap_set.py +++ b/dsp_permissions_scripts/doap/doap_set.py @@ -15,6 +15,7 @@ logger = get_logger(__name__) + def _update_doap_scope( doap_iri: str, scope: PermissionScope, diff --git a/dsp_permissions_scripts/models/scope.py b/dsp_permissions_scripts/models/scope.py index 72efd459..7e25e5b5 100644 --- a/dsp_permissions_scripts/models/scope.py +++ b/dsp_permissions_scripts/models/scope.py @@ -12,6 +12,7 @@ class PermissionScope(BaseModel): A scope is an object encoding the information: "Which user group gets which permissions on a resource/value?" """ + model_config = ConfigDict(frozen=True) CR: frozenset[str] = frozenset() @@ -62,7 +63,7 @@ def add( if perm != permission: kwargs[perm] = getattr(self, perm) return PermissionScope.create(**kwargs) - + def remove( self, permission: Literal["CR", "D", "M", "V", "RV"], diff --git a/dsp_permissions_scripts/oap/oap_get_set.py b/dsp_permissions_scripts/oap/oap_get_set.py index 86d765b2..fc42d210 100644 --- a/dsp_permissions_scripts/oap/oap_get_set.py +++ b/dsp_permissions_scripts/oap/oap_get_set.py @@ -162,22 +162,22 @@ def _update_permissions_for_resource_and_values( context = _get_context(resource) values = _get_value_iris(resource) _update_permissions_for_resource( - resource_iri=resource_iri, - lmd=lmd, - resource_type=resource_type, - context=context, - scope=scope, - host=host, + resource_iri=resource_iri, + lmd=lmd, + resource_type=resource_type, + context=context, + scope=scope, + host=host, token=token, ) for v in values: _update_permissions_for_value( - resource_iri=resource_iri, - value=v, - resource_type=resource_type, - context=context, - scope=scope, - host=host, + resource_iri=resource_iri, + value=v, + resource_type=resource_type, + context=context, + scope=scope, + host=host, token=token, ) @@ -223,7 +223,7 @@ def apply_updated_oaps_on_server( if failed_res_iris: filename = "FAILED_RESOURCES.txt" _write_failed_res_iris_to_file( - failed_res_iris=failed_res_iris, + failed_res_iris=failed_res_iris, shortcode=shortcode, host=host, filename=filename, diff --git a/dsp_permissions_scripts/oap/oap_serialize.py b/dsp_permissions_scripts/oap/oap_serialize.py index f30ceb1e..9ad1294d 100644 --- a/dsp_permissions_scripts/oap/oap_serialize.py +++ b/dsp_permissions_scripts/oap/oap_serialize.py @@ -5,10 +5,7 @@ from dsp_permissions_scripts.oap.oap_model import Oap -def _get_project_data_path( - shortcode: str, - mode: Literal["original", "modified"] -) -> Path: +def _get_project_data_path(shortcode: str, mode: Literal["original", "modified"]) -> Path: return Path(f"project_data/{shortcode}/OAPs_{mode}") diff --git a/dsp_permissions_scripts/template.py b/dsp_permissions_scripts/template.py index 680df2ca..00ee1637 100644 --- a/dsp_permissions_scripts/template.py +++ b/dsp_permissions_scripts/template.py @@ -16,7 +16,7 @@ def modify_doaps(doaps: list[Doap]) -> list[Doap]: """Adapt this sample to your needs.""" - for doap in doaps: + for doap in doaps: if doap.target.group in [builtin_groups.PROJECT_MEMBER, builtin_groups.PROJECT_ADMIN]: doap.scope = PUBLIC return doaps diff --git a/dsp_permissions_scripts/utils/helpers.py b/dsp_permissions_scripts/utils/helpers.py index 1fda24e7..b3a43f27 100644 --- a/dsp_permissions_scripts/utils/helpers.py +++ b/dsp_permissions_scripts/utils/helpers.py @@ -2,7 +2,7 @@ def dereference_prefix( - identifier: str, + identifier: str, context: dict[str, str], ) -> str: prefix, actual_id = identifier.split(":") @@ -18,12 +18,12 @@ def _get_sort_pos_of_custom_group(group: str) -> int: def sort_groups(groups_original: list[str]) -> list[str]: """Sorts groups, first according to their power (most powerful first), then alphabetically.""" sort_key = [ - builtin_groups.SYSTEM_ADMIN, - builtin_groups.CREATOR, - builtin_groups.PROJECT_ADMIN, - builtin_groups.PROJECT_MEMBER, - builtin_groups.KNOWN_USER, - builtin_groups.UNKNOWN_USER + builtin_groups.SYSTEM_ADMIN, + builtin_groups.CREATOR, + builtin_groups.PROJECT_ADMIN, + builtin_groups.PROJECT_MEMBER, + builtin_groups.KNOWN_USER, + builtin_groups.UNKNOWN_USER, ] groups = groups_original.copy() groups.sort(key=lambda x: sort_key.index(x) if x in sort_key else _get_sort_pos_of_custom_group(x)) diff --git a/tests/test_doap_serialization.py b/tests/test_doap_serialization.py index 28433552..af7dce6d 100644 --- a/tests/test_doap_serialization.py +++ b/tests/test_doap_serialization.py @@ -19,7 +19,7 @@ def tearDown(self) -> None: testdata_dir = Path(f"project_data/{self.shortcode}") if testdata_dir.is_dir(): shutil.rmtree(testdata_dir) - + def test_doap_serialization(self): doap1 = Doap( target=DoapTarget( @@ -49,7 +49,7 @@ def test_doap_serialization(self): mode="original", ) deserialized_doaps = deserialize_doaps_of_project( - shortcode=self.shortcode, + shortcode=self.shortcode, mode="original", ) self._compare_doaps(deserialized_doaps[0], doap1) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 4be5c18f..35462999 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -5,7 +5,6 @@ class TestHelpers(unittest.TestCase): - def test_sort_groups(self) -> None: groups_original = [ "http://www.knora.org/ontology/knora-admin#C_CustomGroup", diff --git a/tests/test_oap_serialization.py b/tests/test_oap_serialization.py index c1c00ecd..b1ff59b4 100644 --- a/tests/test_oap_serialization.py +++ b/tests/test_oap_serialization.py @@ -19,7 +19,7 @@ def tearDown(self) -> None: testdata_dir = Path(f"project_data/{self.shortcode}") if testdata_dir.is_dir(): shutil.rmtree(testdata_dir) - + def test_oap_serialization(self): oap1 = Oap( scope=PermissionScope.create( @@ -41,7 +41,7 @@ def test_oap_serialization(self): mode="original", ) deserialized_oaps = deserialize_resource_oaps( - shortcode=self.shortcode, + shortcode=self.shortcode, mode="original", ) deserialized_oaps.sort(key=lambda oap: oap.object_iri) diff --git a/tests/test_scope.py b/tests/test_scope.py index 117f2e70..e93bb9a1 100644 --- a/tests/test_scope.py +++ b/tests/test_scope.py @@ -6,7 +6,6 @@ class TestScope(unittest.TestCase): - def test_scope_validation_on_creation(self) -> None: with self.assertRaisesRegex(ValueError, "must not occur in more than one field"): PermissionScope.create( @@ -21,8 +20,7 @@ def test_scope_validation_on_add_to_same_permission(self) -> None: V={builtin_groups.UNKNOWN_USER, builtin_groups.KNOWN_USER}, ) with self.assertRaisesRegex( - ValueError, - "Group 'http://www.knora.org/ontology/knora-admin#ProjectAdmin' is already in permission 'CR'" + ValueError, "Group 'http://www.knora.org/ontology/knora-admin#ProjectAdmin' is already in permission 'CR'" ): _ = scope.add("CR", builtin_groups.PROJECT_ADMIN) @@ -56,7 +54,7 @@ def test_remove_inexisting_group(self) -> None: ) with self.assertRaisesRegex(ValueError, "is not in permission 'D'"): _ = scope.remove("D", builtin_groups.UNKNOWN_USER) - + def test_remove_from_empty_perm(self) -> None: scope = PermissionScope.create( D={builtin_groups.PROJECT_ADMIN}, @@ -80,5 +78,6 @@ def test_remove_from_scope(self) -> None: ), ) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_scope_serialization.py b/tests/test_scope_serialization.py index 7fb1965e..a21cd691 100644 --- a/tests/test_scope_serialization.py +++ b/tests/test_scope_serialization.py @@ -12,7 +12,7 @@ def compare_scopes( - scope1: PermissionScope, + scope1: PermissionScope, scope2: PermissionScope, msg: str | None = None, ) -> None: