use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class Dataverses method deleteAssignment.
@DELETE
@Path("{identifier}/assignments/{id}")
public Response deleteAssignment(@PathParam("id") long assignmentId, @PathParam("identifier") String dvIdtf) {
RoleAssignment ra = em.find(RoleAssignment.class, assignmentId);
if (ra != null) {
try {
findDataverseOrDie(dvIdtf);
execCommand(new RevokeRoleCommand(ra, createDataverseRequest(findUserOrDie())));
return ok("Role " + ra.getRole().getName() + " revoked for assignee " + ra.getAssigneeIdentifier() + " in " + ra.getDefinitionPoint().accept(DvObject.NamePrinter));
} catch (WrappedResponse ex) {
return ex.getResponse();
}
} else {
return error(Status.NOT_FOUND, "Role assignment " + assignmentId + " not found");
}
}
use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class SearchPermissionsServiceBean method findDvObjectPerms.
public List<String> findDvObjectPerms(DvObject dvObject) {
List<String> permStrings = new ArrayList<>();
resetRoleAssigneeCache();
Set<RoleAssignment> roleAssignments = rolesSvc.rolesAssignments(dvObject);
for (RoleAssignment roleAssignment : roleAssignments) {
logger.fine("role assignment on dvObject " + dvObject.getId() + ": " + roleAssignment.getAssigneeIdentifier());
if (roleAssignment.getRole().permissions().contains(getRequiredSearchPermission(dvObject))) {
RoleAssignee userOrGroup = getRoleAssignee(roleAssignment.getAssigneeIdentifier());
String indexableUserOrGroupPermissionString = getIndexableStringForUserOrGroup(userOrGroup);
if (indexableUserOrGroupPermissionString != null) {
permStrings.add(indexableUserOrGroupPermissionString);
}
}
}
resetRoleAssigneeCache();
return permStrings;
}
use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class SearchPermissionsServiceBean method findWhoHasDirectAssignments.
@Deprecated
private List<RoleAssignee> findWhoHasDirectAssignments(DvObject dvObject) {
List<RoleAssignee> emptyList = new ArrayList<>();
List<RoleAssignee> peopleWhoCanSearch = emptyList;
resetRoleAssigneeCache();
List<RoleAssignment> assignmentsOn = permissionService.assignmentsOn(dvObject);
for (RoleAssignment roleAssignment : assignmentsOn) {
if (roleAssignment.getRole().permissions().contains(getRequiredSearchPermission(dvObject))) {
RoleAssignee userOrGroup = getRoleAssignee(roleAssignment.getAssigneeIdentifier());
if (userOrGroup != null) {
peopleWhoCanSearch.add(userOrGroup);
}
}
}
resetRoleAssigneeCache();
return peopleWhoCanSearch;
}
use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class PrivateUrlServiceBean method getRoleAssignmentFromPrivateUrlToken.
/**
* @return A RoleAssignment or null.
*
* @todo This might be a good place for Optional.
*/
private RoleAssignment getRoleAssignmentFromPrivateUrlToken(String privateUrlToken) {
if (privateUrlToken == null) {
return null;
}
TypedQuery<RoleAssignment> query = em.createNamedQuery("RoleAssignment.listByPrivateUrlToken", RoleAssignment.class);
query.setParameter("privateUrlToken", privateUrlToken);
try {
RoleAssignment roleAssignment = query.getSingleResult();
return roleAssignment;
} catch (NoResultException | NonUniqueResultException ex) {
return null;
}
}
use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.
the class DataverseUserPage method getRoleStringFromUser.
private String getRoleStringFromUser(AuthenticatedUser au, DvObject dvObj) {
// Find user's role(s) for given dataverse/dataset
Set<RoleAssignment> roles = permissionService.assignmentsFor(au, dvObj);
List<String> roleNames = new ArrayList<>();
// Include roles derived from a user's groups
Set<Group> groupsUserBelongsTo = groupService.groupsFor(au, dvObj);
for (Group g : groupsUserBelongsTo) {
roles.addAll(permissionService.assignmentsFor(g, dvObj));
}
for (RoleAssignment ra : roles) {
roleNames.add(ra.getRole().getName());
}
if (roleNames.isEmpty()) {
return "[Unknown]";
}
return StringUtils.join(roleNames, "/");
}
Aggregations