use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.
the class DataverseRoleServiceBean method save.
public DataverseRole save(DataverseRole aRole) {
if (aRole.getId() == null) {
em.persist(aRole);
/**
* @todo Why would getId be null? Should we call
* indexDefinitionPoint here too?
* A: it's null for new roles.
*/
return aRole;
} else {
DataverseRole merged = em.merge(aRole);
/**
* @todo update permissionModificationTime here.
*/
IndexResponse indexDefinitionPountResult = indexDefinitionPoint(merged.getOwner());
logger.info("aRole getId was not null. Indexing result: " + indexDefinitionPountResult);
return merged;
}
}
use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.
the class DataverseRoleServiceBean method getDataverseRolesByPermission.
public List<DataverseRole> getDataverseRolesByPermission(Permission permissionIn, Long ownerId) {
/*
For a given permission and dataverse Id get all of the roles (built-in or owned by the dataverse)
that contain that permission
*/
List<DataverseRole> rolesToCheck = findBuiltinRoles();
List<DataverseRole> retVal = new ArrayList<>();
rolesToCheck.addAll(findByOwnerId(ownerId));
for (DataverseRole role : rolesToCheck) {
if (role.permissions().contains(permissionIn)) {
retVal.add(role);
}
}
return retVal;
}
use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.
the class DataverseRoleServiceBean method revoke.
public void revoke(Set<DataverseRole> roles, RoleAssignee assignee, DvObject defPoint) {
for (DataverseRole role : roles) {
em.createNamedQuery("RoleAssignment.deleteByAssigneeIdentifier_RoleIdDefinition_PointId").setParameter("assigneeIdentifier", assignee.getIdentifier()).setParameter("roleId", role.getId()).setParameter("definitionPointId", defPoint.getId()).executeUpdate();
em.refresh(role);
}
em.refresh(assignee);
}
use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.
the class Roles method viewRole.
@GET
@Path("{id}")
public Response viewRole(@PathParam("id") Long id) {
return response(() -> {
final User user = findUserOrDie();
final DataverseRole role = findRoleOrDie(id);
return (permissionSvc.userOn(user, role.getOwner()).has(Permission.ManageDataversePermissions)) ? ok(json(role)) : permissionError("Permission required to view roles.");
});
}
use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.
the class RoleDTO method asRole.
public DataverseRole asRole() {
DataverseRole r = new DataverseRole();
r.setAlias(alias);
r.setDescription(description);
r.setName(name);
if (permissions != null) {
if (permissions.length > 0) {
if (permissions[0].trim().toLowerCase().equals("all")) {
r.addPermissions(EnumSet.allOf(Permission.class));
} else {
for (String ps : permissions) {
r.addPermission(Permission.valueOf(ps));
}
}
}
}
return r;
}
Aggregations