Search in sources :

Example 1 with UpdateDataverseDefaultContributorRoleCommand

use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseDefaultContributorRoleCommand in project dataverse by IQSS.

the class ManagePermissionsPage method saveConfiguration.

public void saveConfiguration(ActionEvent e) {
    // Set role (if any) for authenticatedUsers
    DataverseRole roleToAssign = null;
    List<String> contributorRoles = Arrays.asList(DataverseRole.FULL_CONTRIBUTOR, DataverseRole.DV_CONTRIBUTOR, DataverseRole.DS_CONTRIBUTOR);
    if (!StringUtil.isEmpty(authenticatedUsersContributorRoleAlias)) {
        roleToAssign = roleService.findBuiltinRoleByAlias(authenticatedUsersContributorRoleAlias);
    }
    // then, check current contributor role
    List<RoleAssignment> aUsersRoleAssignments = roleService.directRoleAssignments(AuthenticatedUsers.get(), dvObject);
    for (RoleAssignment roleAssignment : aUsersRoleAssignments) {
        DataverseRole currentRole = roleAssignment.getRole();
        if (contributorRoles.contains(currentRole.getAlias())) {
            if (currentRole.equals(roleToAssign)) {
                // found the role, so no need to assign
                roleToAssign = null;
            } else {
                revokeRole(roleAssignment);
            }
        }
    }
    // finally, assign role, if new
    if (roleToAssign != null) {
        assignRole(AuthenticatedUsers.get(), roleToAssign);
    }
    // set dataverse default contributor role
    if (dvObject instanceof Dataverse) {
        Dataverse dv = (Dataverse) dvObject;
        DataverseRole defaultRole = roleService.findBuiltinRoleByAlias(defaultContributorRoleAlias);
        if (!defaultRole.equals(dv.getDefaultContributorRole())) {
            try {
                commandEngine.submit(new UpdateDataverseDefaultContributorRoleCommand(defaultRole, dvRequestService.getDataverseRequest(), dv));
                JsfHelper.addSuccessMessage("The default permissions for this dataverse have been updated.");
            } catch (PermissionException ex) {
                JH.addMessage(FacesMessage.SEVERITY_ERROR, "Cannot assign default permissions.", "Permissions " + ex.getRequiredPermissions().toString() + " missing.");
            } catch (CommandException ex) {
                JH.addMessage(FacesMessage.SEVERITY_FATAL, "Cannot assign default permissions.");
                logger.log(Level.SEVERE, "Error assigning default permissions: " + ex.getMessage(), ex);
            }
        }
    }
    roleAssignments = initRoleAssignments();
    showConfigureMessages();
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) UpdateDataverseDefaultContributorRoleCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseDefaultContributorRoleCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Aggregations

DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)1 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)1 UpdateDataverseDefaultContributorRoleCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseDefaultContributorRoleCommand)1