async def test_attach_permissions_to_role(fake_dependencies):
    uow, _ = fake_dependencies
    permissions_i = uow.roles.get(helpers.DEFAULT_ROLE_CODE).permissions
    handlers.attach_permissions_to_role(
        code=helpers.DEFAULT_ROLE_CODE,
        permissions=auth.AVAILABLE_PERMISSIONS[2:4],
        uow=uow,
    )

    permissions_j = uow.roles.get(helpers.DEFAULT_ROLE_CODE).permissions
    assert permissions_i != permissions_j
    assert model.Permission(**auth.AVAILABLE_PERMISSIONS[2]) in permissions_j
    assert model.Permission(**auth.AVAILABLE_PERMISSIONS[3]) in permissions_j
def test_attach_permissions():
    permission_1 = model.Permission(
        "wallet", model.PermissionActionEnum.CREATE, False
    )
    permission_2 = model.Permission(
        "wallet", model.PermissionActionEnum.CREATE, True
    )
    role = model.Role(
        name=helpers.DEFAULT_ROLE_NAME,
        code=helpers.DEFAULT_ROLE_CODE,
        permissions=set(),
    )
    role.attach_permissions({permission_1, permission_2})
    assert len(role.permissions) > 0
    assert role.permissions == {permission_1, permission_2}
async def test_attach_permissions_to_user(fake_dependencies):
    uow, _ = fake_dependencies
    user = uow.users.list()[0]
    permissions_i = user.permissions

    handlers.attach_permissions_to_user(
        access_key=user.access_key,
        permissions=auth.AVAILABLE_PERMISSIONS[2:4],
        uow=uow,
    )

    permissions_j = uow.users.get(user.access_key).permissions
    assert permissions_i != permissions_j
    assert model.Permission(**auth.AVAILABLE_PERMISSIONS[2]) in permissions_j
    assert model.Permission(**auth.AVAILABLE_PERMISSIONS[3]) in permissions_j
def test_detach_permissions():
    permission_1 = model.Permission(
        resource="wallet",
        action=model.PermissionActionEnum.CREATE,
        is_conditional=False,
    )
    permission_2 = model.Permission(
        resource="wallet",
        action=model.PermissionActionEnum.CREATE,
        is_conditional=True,
    )
    role = model.Role(
        name=helpers.DEFAULT_ROLE_NAME,
        code=helpers.DEFAULT_ROLE_CODE,
        permissions={permission_1, permission_2},
    )
    assert len(role.permissions) == 2
    role.detach_permissions({permission_1})
    assert len(role.permissions) == 1
def get_mapped_permissions(
    permissions: List[Dict], mapped_permissions: List[model.Permission]
):
    permissions = [model.Permission(**p) for p in permissions]
    return {mp for mp in mapped_permissions if mp in permissions}
Beispiel #6
0
 def list(self) -> List[model.Permission]:
     return [model.Permission(**p) for p in AVAILABLE_PERMISSIONS]