Search in sources :

Example 86 with Role

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

the class MailingListServiceTest method testRemoveOverprivledgedEditRole.

@Test(expected = PermissionException.class)
public void testRemoveOverprivledgedEditRole() {
    MailingList vo = newVO(readUser);
    Set<Role> editRoles = Collections.singleton(editRole);
    vo.setEditPermission(MangoPermission.requireAnyRole(editRoles));
    service.insert(vo);
    MailingList fromDb = service.get(vo.getId());
    assertVoEqual(vo, fromDb);
    runAs.runAs(readUser, () -> {
        vo.setEditPermission(MangoPermission.superadminOnly());
        service.update(vo.getXid(), vo);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) Test(org.junit.Test)

Example 87 with Role

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

the class UsersServiceTest method testAddEditRoleUserDoesNotHave.

@Test
@Override
@ExpectValidationException("roles")
public void testAddEditRoleUserDoesNotHave() {
    User vo = newVO(readUser);
    vo.setRoles(Collections.singleton(readRole));
    service.insert(vo);
    // Ensure the ability to edit self
    setEditSelfPermission(MangoPermission.requireAnyRole(readRole));
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        Set<Role> newRoles = new HashSet<>(self.getRoles());
        newRoles.add(editRole);
        self.setRoles(newRoles);
        service.update(self.getId(), self);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) HashSet(java.util.HashSet) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 88 with Role

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

the class UsersServiceTest method canAddOwnRolesWhenCreating.

@Test
public void canAddOwnRolesWhenCreating() {
    Role createRole = createUsersRole();
    User createUser = insertUser(createRole, editRole, readRole);
    runAs.runAs(createUser, () -> {
        insertUser(readRole);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Example 89 with Role

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

the class RoleServiceTest method canGetRoleUserHas.

@Test
public void canGetRoleUserHas() {
    RoleVO roleUserHas = insertNewVO(readUser);
    User testUser = createUser("test-user@example.com", "test-user@example.com", "test-user@example.com", "test-user@example.com", roleUserHas.getRole());
    runAs.runAs(testUser, () -> {
        RoleVO role = service.get(roleUserHas.getXid());
        assertEquals(role.getXid(), roleUserHas.getXid());
        assertEquals(role.getName(), roleUserHas.getName());
        assertEquals(role.getId(), roleUserHas.getId());
    });
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test)

Example 90 with Role

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

the class UsersServiceTest method createUsersRole.

public Role createUsersRole() {
    Role createRole = createRole(randomXid(), "Create users role").getRole();
    PermissionDefinition createPermission = Common.getBean(UserCreatePermission.class);
    systemPermissionService.update(MangoPermission.requireAnyRole(createRole), createPermission);
    return createRole;
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) ChangeOwnUsernamePermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.ChangeOwnUsernamePermissionDefinition) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition)

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