Skip to content

Commit

Permalink
Map thumbnail's patch_after_feature_change handle roles in access rights
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Dec 13, 2023
1 parent f0b16f7 commit 16310c2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
6 changes: 1 addition & 5 deletions src/layman/map/filesystem/thumbnail_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from celery.utils.log import get_task_logger

import layman_settings
from layman.celery import AbortedException
from layman import celery_app, util as layman_util
from . import thumbnail
Expand All @@ -18,10 +17,7 @@ def patch_after_feature_change(self, workspace, map):
if self.is_aborted():
raise AbortedException

info = layman_util.get_publication_info(workspace, MAP_TYPE, map, context={'keys': ['access_rights']})
write_rights = info.get('access_rights', {}).get('write', [])
writers = [write_right for write_right in write_rights if write_right != layman_settings.RIGHTS_EVERYONE_ROLE]
editor = next(iter(writers), layman_settings.ANONYM_USER)
editor = layman_util.get_publication_writer(workspace, MAP_TYPE, map)

thumbnail.generate_map_thumbnail(workspace, map, editor=editor)

Expand Down
6 changes: 3 additions & 3 deletions src/layman/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def get_complete_publication_info(workspace, publication_type, publication_name,
def get_publication_writer(workspace, publication_type, publication_name):
from layman.common.prime_db_schema.publications import is_user
info = get_publication_info(workspace, publication_type, publication_name, context={'keys': ['access_rights']})
return next(
return next((
user_or_role for user_or_role in info['access_rights']['write']
if user_or_role == settings.RIGHTS_EVERYONE_ROLE or is_user(user_or_role)
)
if is_user(user_or_role)
), settings.ANONYM_USER)
6 changes: 2 additions & 4 deletions tests/asserts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_publication_writer(publication):

def get_publication_header(publication):
writer = get_publication_writer(publication)
headers = None if writer == settings.RIGHTS_EVERYONE_ROLE else process_client.get_authz_headers(writer)
headers = None if writer == settings.ANONYM_USER else process_client.get_authz_headers(writer)
return headers


Expand All @@ -26,9 +26,7 @@ def get_publication_exists(publication):


def get_publication_actor(publication):
writer = get_publication_writer(publication)
actor = settings.ANONYM_USER if writer == settings.RIGHTS_EVERYONE_ROLE else writer
return actor
return get_publication_writer(publication)


def get_directory_name_from_publ_type(publ_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class TestPublication(base_test.TestSingleRestPublication):
},
},
type=EnumTestTypes.MANDATORY,
marks=[pytest.mark.xfail(reason="Not fixed yet")]
)]

def before_class(self):
Expand Down

0 comments on commit 16310c2

Please sign in to comment.