Search in sources :

Example 16 with Role

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

the class PostgresDatabaseTest method test1AutoIncrement.

@Test
public void test1AutoIncrement() throws SQLException {
    DSLContext context = Common.getBean(DatabaseProxy.class).getContext();
    Roles r = Roles.ROLES;
    context.insertInto(r, r.id, r.xid, r.name).values(10, "xid", "name").execute();
    context.insertInto(r, r.xid, r.name).values("test", "test").execute();
    RoleVO role = Common.getBean(RoleDao.class).getByXid("test");
    assertNotEquals(11, role.getId());
    assertEquals(4, role.getId());
    String sequence = r.getName() + "_" + r.id.getName() + "_seq";
    context.alterSequence(sequence).restartWith(20).execute();
    context.insertInto(r, r.xid, r.name).values("test2", "test2").execute();
    role = Common.getBean(RoleDao.class).getByXid("test2");
    assertEquals(20, role.getId());
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) DSLContext(org.jooq.DSLContext) Roles(com.infiniteautomation.mango.db.tables.Roles) Test(org.junit.Test)

Example 17 with Role

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

the class SetPointEventHandlerDefinition method handleRoleEvent.

@Override
public void handleRoleEvent(SetPointEventHandlerVO 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 18 with Role

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

the class JsonDataVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String json = jsonObject.getString("jsonData");
    try {
        jsonData = JsonDataDao.getInstance().readValueFromString(json);
    } catch (Exception e) {
        throw new TranslatableJsonException("emport.error.parseError", "jsonData");
    }
    // Read permission handling in case we need to add the anonymous role
    if (jsonObject.containsKey("readPermission")) {
        readPermission = reader.read(MangoPermission.class, jsonObject.get("readPermission"));
    } else {
        readPermission = new MangoPermission();
    }
    if (jsonObject.containsKey("publicData") && jsonObject.getBoolean("publicData", false)) {
        Set<Set<Role>> newRoles = new HashSet<>(readPermission.getRoles());
        newRoles.add(Collections.singleton(PermissionHolder.ANONYMOUS_ROLE));
        newRoles.add(Collections.singleton(PermissionHolder.USER_ROLE));
        readPermission = new MangoPermission(newRoles);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) IOException(java.io.IOException) JsonException(com.serotonin.json.JsonException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 19 with Role

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

the class UserEventMulticasterTest method setupRoles.

@Before
public void setupRoles() {
    roleService = Common.getBean(RoleService.class);
    systemSuperadmin = PermissionHolder.SYSTEM_SUPERADMIN;
    // Add some roles
    mockRole = new RoleVO(Common.NEW_ID, "MOCK", "Mock test role.");
    mockRole = roleService.insert(mockRole);
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) RoleService(com.infiniteautomation.mango.spring.service.RoleService) Before(org.junit.Before)

Example 20 with Role

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

the class RoleDao method addInheritance.

/**
 * Recursively add all inherited roles
 */
private void addInheritance(Role role, Set<Role> all) {
    Set<Role> inherited = getInherited(role.getId());
    for (Role inheritedRole : inherited) {
        all.add(inheritedRole);
        addInheritance(inheritedRole, all);
    }
}
Also used : Role(com.serotonin.m2m2.vo.role.Role)

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