use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.
the class PermissionPersistenceTest method testOrPermission.
@Test
public void testOrPermission() {
PermissionService service = Common.getBean(PermissionService.class);
// Create some roles
Set<Role> roles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
// insert the permission
MangoPermission permission = service.findOrCreate(MangoPermission.requireAnyRole(roles));
MangoPermission read = service.get(permission.getId());
assertEquals(2, read.getRoles().size());
Iterator<Set<Role>> it = read.getRoles().iterator();
assertEquals(1, it.next().size());
assertEquals(1, it.next().size());
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.
the class PermissionPersistenceTest method testOrphanedPermission.
/**
* TODO we cannot remove permissions with empty minterms as of the FK RESTRICT on VOs
* Test when removing a role we also delete any orphaned permission (has no roles in minterms)
* Delete role then check each used minterms to see if empty
*/
@Test
public void testOrphanedPermission() {
PermissionService service = Common.getBean(PermissionService.class);
// insert some roles
Set<Role> roles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
// insert the permission
MangoPermission permission = service.findOrCreate(MangoPermission.requireAnyRole(roles));
MangoPermission read = service.get(permission.getId());
assertEquals(2, read.getRoles().size());
// Delete all roles in minterm
Iterator<Set<Role>> it = read.getRoles().iterator();
Set<Role> term1 = it.next();
Iterator<Role> term1It = term1.iterator();
Set<Role> term2 = it.next();
Iterator<Role> term2It = term2.iterator();
Common.getBean(RoleDao.class).delete(term1It.next().getId());
Common.getBean(RoleDao.class).delete(term2It.next().getId());
// Confirm that the permission has no roles
read = service.get(permission.getId());
assertEquals(0, read.getRoles().size());
// Check for orphaned minterm mappings
List<Integer> mintermIds = getMintermIds(permission.getId());
assertEquals(0, mintermIds.size());
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.
the class PermissionPersistenceTest method testModifyPermission.
/**
* Modify a permission and ensure that it is retrieved correctly from the database after
*/
@Test
public void testModifyPermission() {
PermissionService service = Common.getBean(PermissionService.class);
// insert some roles
Set<Role> roles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
// insert the permission
MangoPermission permission = service.findOrCreate(MangoPermission.requireAnyRole(roles));
MangoPermission read = service.get(permission.getId());
assertEquals(2, read.getRoles().size());
Iterator<Set<Role>> it = read.getRoles().iterator();
Role toKeep = it.next().iterator().next();
MangoPermission keep = service.findOrCreate(MangoPermission.requireAnyRole(toKeep));
read = service.get(keep.getId());
assertEquals(1, read.getRoles().size());
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-modules-public by infiniteautomation.
the class SetPointEventHandlerModel method readInto.
@Override
public void readInto(SetPointEventHandlerVO vo) {
super.readInto(vo);
Integer targetId = DataPointDao.getInstance().getIdByXid(targetPointXid);
if (targetId != null)
vo.setTargetPointId(targetId);
vo.setActiveAction(SetPointEventHandlerVO.SET_ACTION_CODES.getId(activeAction));
if (activeValueToSet != null)
vo.setActiveValueToSet(activeValueToSet.toString());
if (activePointXid != null) {
Integer activePointId = DataPointDao.getInstance().getIdByXid(activePointXid);
if (activePointId != null)
vo.setActivePointId(activePointId);
}
vo.setActiveScript(activeScript);
vo.setInactiveAction(SetPointEventHandlerVO.SET_ACTION_CODES.getId(inactiveAction));
if (inactiveValueToSet != null)
vo.setInactiveValueToSet(inactiveValueToSet.toString());
if (inactivePointXid != null) {
Integer inactivePointId = DataPointDao.getInstance().getIdByXid(inactivePointXid);
if (inactivePointId != null)
vo.setInactivePointId(inactivePointId);
}
vo.setInactiveScript(inactiveScript);
PermissionService service = Common.getBean(PermissionService.class);
vo.setScriptRoles(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(scriptPermissions)));
if (scriptContext != null) {
List<IntStringPair> additionalContext = new ArrayList<>();
for (ScriptContextVariableModel var : scriptContext) {
Integer id = DataPointDao.getInstance().getIdByXid(var.getXid());
if (id != null) {
additionalContext.add(new IntStringPair(id, var.getVariableName()));
} else {
additionalContext.add(new IntStringPair(Common.NEW_ID, var.getVariableName()));
}
}
vo.setAdditionalContext(additionalContext);
}
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by infiniteautomation.
the class RoleDao method joinPermissions.
@Override
public <R extends Record> SelectJoinStep<R> joinPermissions(SelectJoinStep<R> select, PermissionHolder user) {
PermissionService permissionService = permissionServiceSupplier.get();
Set<Role> heldRoles = permissionService.getAllInheritedRoles(user);
if (heldRoles.contains(PermissionHolder.SUPERADMIN_ROLE)) {
return select;
}
List<String> xids = heldRoles.stream().map(Role::getXid).collect(Collectors.toList());
return select.innerJoin(DSL.selectOne()).on(table.xid.in(xids));
}
Aggregations