Search in sources :

Example 36 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.

the class EmailEventHandlerDefinition method handleRoleEvent.

@Override
public void handleRoleEvent(EmailEventHandlerVO vo, DaoEvent<? extends RoleVO> event) {
    // Remove and re-serialize our handler's script roles if it has a role that was deleted
    if (vo.getScriptRoles().getRoles().contains(event.getVo().getRole())) {
        switch(event.getType()) {
            case UPDATE:
                break;
            case DELETE:
                Set<Role> updated = new HashSet<>(vo.getScriptRoles().getRoles());
                updated.remove(event.getVo().getRole());
                Set<Role> allRoles = new HashSet<>();
                for (Role role : updated) {
                    allRoles.addAll(service.getAllInheritedRoles(role));
                }
                ScriptPermissions permission = new ScriptPermissions(allRoles, vo.getScriptRoles().getPermissionHolderName());
                vo.setScriptRoles(permission);
                eventHandlerService.update(vo.getId(), vo);
                break;
            default:
                break;
        }
    }
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) HashSet(java.util.HashSet)

Example 37 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

the class SetPointEventHandlerServiceTest method testCreatePrivilegeSuccess.

@Test
public void testCreatePrivilegeSuccess() {
    SetPointEventHandlerVO vo = newVO(editUser);
    vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
    vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
    ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(editRole));
    vo.setScriptRoles(permissions);
    addRoleToCreatePermission(editRole);
    runAs.runAs(editUser, () -> {
        service.insert(vo);
    });
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test)

Example 38 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

the class SetPointEventHandlerServiceTest method testDeleteRoleUpdateVO.

@Test
public void testDeleteRoleUpdateVO() {
    SetPointEventHandlerVO vo = newVO(readUser);
    ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
    vo.setScriptRoles(permissions);
    service.insert(vo);
    SetPointEventHandlerVO fromDb = (SetPointEventHandlerVO) service.get(vo.getId());
    assertVoEqual(vo, fromDb);
    roleService.delete(editRole.getId());
    roleService.delete(readRole.getId());
    SetPointEventHandlerVO updated = (SetPointEventHandlerVO) service.get(fromDb.getId());
    fromDb.setScriptRoles(new ScriptPermissions(Collections.emptySet()));
    assertVoEqual(fromDb, updated);
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test)

Example 39 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

the class EmailEventHandlerServiceTest method newVO.

@Override
EmailEventHandlerVO newVO(User user) {
    EmailEventHandlerVO vo = (EmailEventHandlerVO) ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME).baseCreateEventHandlerVO();
    vo.setXid(UUID.randomUUID().toString());
    vo.setName(UUID.randomUUID().toString());
    ScriptPermissions permissions = new ScriptPermissions(Collections.singleton(readRole));
    vo.setScriptRoles(permissions);
    List<EventTypeMatcher> eventTypes = Collections.singletonList(new EventTypeMatcher(new MockEventType(readRole)));
    vo.setEventTypes(eventTypes);
    return vo;
}
Also used : EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) MockEventType(com.serotonin.m2m2.rt.event.type.MockEventType)

Example 40 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

the class EmailEventHandlerServiceTest method testCreatePrivilegeSuccess.

@Test
public void testCreatePrivilegeSuccess() {
    EmailEventHandlerVO vo = newVO(editUser);
    vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
    vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
    ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(editRole));
    vo.setScriptRoles(permissions);
    addRoleToCreatePermission(editRole);
    runAs.runAs(editUser, () -> {
        service.insert(vo);
    });
}
Also used : EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test)

Aggregations

ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)45 Test (org.junit.Test)20 EmailEventHandlerVO (com.serotonin.m2m2.vo.event.EmailEventHandlerVO)16 SetPointEventHandlerVO (com.serotonin.m2m2.vo.event.SetPointEventHandlerVO)14 Role (com.serotonin.m2m2.vo.role.Role)12 ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)8 HashSet (java.util.HashSet)8 IntStringPair (com.serotonin.db.pair.IntStringPair)6 JsonArray (com.serotonin.json.type.JsonArray)6 ArrayList (java.util.ArrayList)6 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)5 EventTypeMatcher (com.serotonin.m2m2.rt.event.type.EventTypeMatcher)4 MockEventType (com.serotonin.m2m2.rt.event.type.MockEventType)4 List (java.util.List)4 Set (java.util.Set)4 ScriptContextVariableModel (com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel)2 JsonObject (com.serotonin.json.type.JsonObject)2 JsonValue (com.serotonin.json.type.JsonValue)2 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)2 ResultSet (java.sql.ResultSet)2