Skip to content

Commit

Permalink
Add method split_user_and_role_names
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Nov 28, 2023
1 parent 53c2bdf commit 25755f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/layman/common/prime_db_schema/publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/layman/common/prime_db_schema/publications_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 25755f4

Please sign in to comment.