Skip to content

Commit

Permalink
implement modify_oaps()
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Oct 3, 2023
1 parent 183145c commit 171bef0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dsp_permissions_scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

from dsp_permissions_scripts.models.groups import BuiltinGroup
from dsp_permissions_scripts.models.host import Hosts
from dsp_permissions_scripts.models.permission import Oap
from dsp_permissions_scripts.models.scope import PUBLIC
from dsp_permissions_scripts.utils.authentication import login
from dsp_permissions_scripts.utils.permissions import (
apply_updated_oaps_on_server,
get_doaps_of_project,
print_doaps_of_project,
set_doaps_of_groups,
update_permissions_for_resources_and_values,
)
from dsp_permissions_scripts.utils.project import (
get_all_resource_oaps_of_project,
get_project_iri_by_shortcode,
)


def modify_oaps(oaps: list[Oap]) -> list[Oap]:
for oap in oaps:
oap.scope.D.append(BuiltinGroup.PROJECT_MEMBER)
return oaps


def main() -> None:
"""
The main method assembles a sample call of all available high-level functions.
Expand Down Expand Up @@ -54,9 +61,9 @@ def main() -> None:
host=host,
token=token,
)
update_permissions_for_resources_and_values(
resource_iris=resource_oaps_updated,
scope=new_scope,
resource_oaps_updated = modify_oaps(oaps=resource_oaps)
apply_updated_oaps_on_server(
resource_oaps=resource_oaps_updated,
host=host,
token=token,
)
Expand Down
16 changes: 16 additions & 0 deletions dsp_permissions_scripts/utils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Doap,
DoapTarget,
DoapTargetType,
Oap,
PermissionScope,
)
from dsp_permissions_scripts.models.value import ValueUpdate
Expand Down Expand Up @@ -233,6 +234,21 @@ def update_doap_scope(
return new_doap


def apply_updated_oaps_on_server(
resource_oaps: list[Oap],
host: str,
token: str,
) -> None:
"""Applies object access permissions on a DSP server."""
for resource_oap in resource_oaps:
update_permissions_for_resources_and_values(
resource_iris=[resource_oap.object_iri],
scope=resource_oap.scope,
host=host,
token=token,
)


def update_permissions_for_resources_and_values(
resource_iris: list[str],
scope: PermissionScope,
Expand Down

0 comments on commit 171bef0

Please sign in to comment.