Search in sources :

Example 26 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method superadminCantRemoveSuperadminRoleFromSelf.

@Test
@ExpectValidationException("roles")
public void superadminCantRemoveSuperadminRoleFromSelf() {
    setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
    User vo = insertUser(editRole, readRole, PermissionHolder.SUPERADMIN_ROLE);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setRoles(self.getRoles().stream().filter(r -> !r.equals(PermissionHolder.SUPERADMIN_ROLE)).collect(Collectors.toSet()));
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 27 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantDisableSelfEvenIfSuperadmin.

@Test
@ExpectValidationException("disabled")
public void cantDisableSelfEvenIfSuperadmin() {
    User vo = insertUser(PermissionHolder.SUPERADMIN_ROLE);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setDisabled(true);
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 28 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantChangePermissionsOfSelf.

@Test
@ExpectValidationException({ "readPermission", "editPermission" })
public void cantChangePermissionsOfSelf() {
    setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
    User vo = insertUser();
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setReadPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
        self.setEditPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 29 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method mustRetainAccessToSelf.

@Test
@ExpectValidationException({ "readPermission", "editPermission" })
public void mustRetainAccessToSelf() {
    User vo = insertUser(editRole, readRole);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setReadPermission(MangoPermission.superadminOnly());
        self.setEditPermission(MangoPermission.superadminOnly());
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 30 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException 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)

Aggregations

ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)33 Test (org.junit.Test)33 User (com.serotonin.m2m2.vo.User)21 Role (com.serotonin.m2m2.vo.role.Role)9 ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)4 RoleVO (com.serotonin.m2m2.vo.role.RoleVO)4 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)2 EmailEventHandlerVO (com.serotonin.m2m2.vo.event.EmailEventHandlerVO)2 SetPointEventHandlerVO (com.serotonin.m2m2.vo.event.SetPointEventHandlerVO)2 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)2 HashSet (java.util.HashSet)2 MaintenanceEventVO (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)1 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)1 ChangeOwnUsernamePermissionDefinition (com.serotonin.m2m2.module.definitions.permissions.ChangeOwnUsernamePermissionDefinition)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 MailingListEntry (com.serotonin.m2m2.vo.mailingList.MailingListEntry)1 MailingListRecipient (com.serotonin.m2m2.vo.mailingList.MailingListRecipient)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Set (java.util.Set)1