diff --git a/src/layman/common/prime_db_schema/publications.py b/src/layman/common/prime_db_schema/publications.py index 75aeeef02..371299568 100644 --- a/src/layman/common/prime_db_schema/publications.py +++ b/src/layman/common/prime_db_schema/publications.py @@ -370,6 +370,12 @@ def owner_can_still_write(owner, raise LaymanError(43, f'Owner of the personal workspace have to keep write right.') +def split_user_and_role_names(user_and_role_names): + role_names = [name for name in user_and_role_names if any(letter.isupper() for letter in name)] + user_names = [name for name in user_and_role_names if name not in role_names] + return user_names, role_names + + def check_rights_axioms(can_read, can_write, actor_name, diff --git a/src/layman/common/prime_db_schema/publications_test.py b/src/layman/common/prime_db_schema/publications_test.py index 80334aa9d..893b6f0ce 100644 --- a/src/layman/common/prime_db_schema/publications_test.py +++ b/src/layman/common/prime_db_schema/publications_test.py @@ -472,3 +472,16 @@ def case_test_update_rights(username, users.delete_user(username) users.delete_user(username2) workspaces.delete_workspace(workspace_name) + + +@pytest.mark.parametrize('roles_and_users, exp_users, exp_roles', [ + pytest.param([], [], [], id='no-names'), + pytest.param(['user1', 'user2'], ['user1', 'user2'], [], id='only-users'), + pytest.param(['ROLE1', 'EVERYONE'], [], ['ROLE1', 'EVERYONE'], id='only-roles'), + pytest.param(['ROLE2', 'user1', 'EVERYONE', 'user2'], ['user1', 'user2'], ['ROLE2', 'EVERYONE'], + id='more-users-and-roles'), +]) +def test_split_user_and_role_names(roles_and_users, exp_users, exp_roles): + user_names, role_names = publications.split_user_and_role_names(roles_and_users) + assert user_names == exp_users + assert role_names == exp_roles