Search in sources :

Example 91 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method canAddOwnRolesWhenUpdating.

@Test
public void canAddOwnRolesWhenUpdating() {
    Role createRole = createUsersRole();
    User createUser = insertUser(createRole, editRole, readRole);
    User otherUser = insertUser();
    runAs.runAs(createUser, () -> {
        otherUser.setRoles(Collections.singleton(readRole));
        service.update(otherUser.getId(), otherUser);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Example 92 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantCreateUserYouCantEdit.

@Test
@ExpectValidationException("editPermission")
public void cantCreateUserYouCantEdit() {
    Role createRole = createUsersRole();
    User createUser = insertUser(readRole, createRole);
    // noinspection Convert2MethodRef
    runAs.runAs(createUser, () -> insertUser());
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 93 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantAddAdditionalRolesWhenUpdating.

@Test
@ExpectValidationException("roles")
public void cantAddAdditionalRolesWhenUpdating() {
    Role roleToAdd = createRole(randomXid(), "Some other role").getRole();
    Role createRole = createUsersRole();
    User createUser = insertUser(createRole, editRole, readRole);
    User otherUser = insertUser();
    runAs.runAs(createUser, () -> {
        otherUser.setRoles(Collections.singleton(roleToAdd));
        service.update(otherUser.getId(), otherUser);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 94 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class UsersServiceTest method insertUser.

public User insertUser(Role... roles) {
    User user = newVO(null);
    user.setReadPermission(MangoPermission.requireAnyRole(readRole));
    user.setEditPermission(MangoPermission.requireAnyRole(editRole));
    user.setRoles(Arrays.stream(roles).collect(Collectors.toSet()));
    return service.insert(user);
}
Also used : User(com.serotonin.m2m2.vo.User)

Example 95 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class AbstractVOServiceWithPermissionsTest method removeRoleFromCreatePermission.

void removeRoleFromCreatePermission(Role vo) {
    String permissionType = getCreatePermissionType();
    if (permissionType != null) {
        PermissionDefinition def = ModuleRegistry.getPermissionDefinition(getCreatePermissionType());
        MangoPermission permission = def.getPermission();
        Common.getBean(SystemPermissionService.class).update(new MangoPermission(permission.withoutRole(vo).getRoles()), def);
    }
}
Also used : PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Aggregations

Role (com.serotonin.m2m2.vo.role.Role)102 Test (org.junit.Test)59 HashSet (java.util.HashSet)40 Set (java.util.Set)38 User (com.serotonin.m2m2.vo.User)33 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)23 RoleVO (com.serotonin.m2m2.vo.role.RoleVO)22 Collectors (java.util.stream.Collectors)18 Common (com.serotonin.m2m2.Common)17 MangoTestBase (com.serotonin.m2m2.MangoTestBase)15 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)15 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)15 List (java.util.List)15 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)14 Assert.assertEquals (org.junit.Assert.assertEquals)14 Assert.assertTrue (org.junit.Assert.assertTrue)14 DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)12 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)12 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)11 DSLContext (org.jooq.DSLContext)11