Search in sources :

Example 66 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class RoleActions method updateWithoutChecks.

@Override
protected ActionResponse<RolePermissionModel> updateWithoutChecks(Long id, RolePermissionModel resource) {
    try {
        String roleName = resource.getRoleName();
        Optional<UserRoleModel> existingRole = roleAccessor.getRoles(List.of(id)).stream().findFirst();
        if (existingRole.isPresent()) {
            logger.debug(actionMessageCreator.updateStartMessage("role", existingRole.get().getName()));
            if (!existingRole.get().getName().equals(roleName)) {
                authorizationManager.updateRoleName(id, roleName);
            }
            Set<PermissionModel> permissions = resource.getPermissions();
            PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
            authorizationManager.updatePermissionsForRole(roleName, permissionMatrixModel);
            logger.debug(actionMessageCreator.updateSuccessMessage("Role", roleName));
            return new ActionResponse<>(HttpStatus.NO_CONTENT);
        }
        logger.warn(actionMessageCreator.updateNotFoundMessage("Role", id));
        return new ActionResponse<>(HttpStatus.NOT_FOUND, "Role not found.");
    } catch (AlertException ex) {
        logger.error(actionMessageCreator.updateErrorMessage("role", resource.getRoleName()));
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)66 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)23 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)20 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)19 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)17 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)16 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)15 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)15 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)15 Test (org.junit.jupiter.api.Test)15 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)12 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)8 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)6 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 MultiFieldModel (com.synopsys.integration.alert.common.rest.model.MultiFieldModel)5 Collection (java.util.Collection)5 Optional (java.util.Optional)5 Set (java.util.Set)5