From 648d4eb1fc801ceb988ed2c7d6aec918796e0ed0 Mon Sep 17 00:00:00 2001 From: Johannes Nussbaum Date: Wed, 11 Oct 2023 09:40:31 +0200 Subject: [PATCH] adapt scenario tanner to what needs to be done --- .../scenario-tanner/scenario-tanner.py | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/dsp_permissions_scripts/scenario-tanner/scenario-tanner.py b/dsp_permissions_scripts/scenario-tanner/scenario-tanner.py index d894ed2b..91f3dce7 100644 --- a/dsp_permissions_scripts/scenario-tanner/scenario-tanner.py +++ b/dsp_permissions_scripts/scenario-tanner/scenario-tanner.py @@ -1,12 +1,15 @@ from dotenv import load_dotenv +from dsp_permissions_scripts.models.groups import BuiltinGroup from dsp_permissions_scripts.models.host import Hosts +from dsp_permissions_scripts.models.oap import Oap from dsp_permissions_scripts.utils.authentication import login from dsp_permissions_scripts.utils.doap_get import ( get_doaps_of_project, print_doaps_of_project, ) from dsp_permissions_scripts.utils.doap_set import _update_doap_scope +from dsp_permissions_scripts.utils.oap import apply_updated_oaps_on_server from dsp_permissions_scripts.utils.project import get_all_resource_oaps_of_project @@ -31,18 +34,6 @@ def fix_scenario_tanner() -> None: ) -def fix_oaps( - host: str, - shortcode: str, - token: str, -) -> None: - all_resource_oaps = get_all_resource_oaps_of_project( - shortcode=shortcode, - host=host, - token=token, - ) - - def fix_doaps( host: str, shortcode: str, @@ -59,7 +50,8 @@ def fix_doaps( shortcode=shortcode, ) for d in doaps: - d.scope.V.append("http://rdfh.ch/groups/0102/oe8-uWCgS4Wl6wfOvaFGCA") + d.scope = d.scope.remove("M", BuiltinGroup.PROJECT_MEMBER) + d.scope = d.scope.add("V", BuiltinGroup.PROJECT_MEMBER) new_doaps = [] for d in doaps: new_doap = _update_doap_scope( @@ -77,5 +69,31 @@ def fix_doaps( ) +def fix_oaps( + host: str, + shortcode: str, + token: str, +) -> None: + all_resource_oaps = get_all_resource_oaps_of_project( + shortcode=shortcode, + host=host, + token=token, + ) + resource_oaps_updated = modify_oaps(oaps=all_resource_oaps) + apply_updated_oaps_on_server( + resource_oaps=resource_oaps_updated, + host=host, + token=token, + ) + + +def modify_oaps(oaps: list[Oap]) -> list[Oap]: + """Remove ProjectMember from Modify, and add it to View.""" + for oap in oaps: + oap.scope = oap.scope.remove("M", BuiltinGroup.PROJECT_MEMBER) + oap.scope = oap.scope.add("V", BuiltinGroup.PROJECT_MEMBER) + return oaps + + if __name__ == "__main__": fix_scenario_tanner()