/** * Creates a new ErrorCollection instance for a single error message. If the reason "forbidden" and the user is * null, this method adds an additional error message along the lines of "You are not logged in, please log in". * * @param user the ApplicationUser for whom the message will be i18n'ed * @param i18nKey a String containing an i18n key * @param reason a Reason code * @param params a String array containing the i18n params @return a new ErrorCollection * @return a new ErrorCollection * @since v6.1 */ protected final ErrorCollection makeErrorCollection(ApplicationUser user, String i18nKey, ErrorCollection.Reason reason, String... params) { final ErrorCollection errors = ErrorCollections.empty(); final I18nHelper i18nBean = getI18nBean(user); errors.addErrorMessage(i18nBean.getText(i18nKey, params), reason); // lack of permissions may be due to the user not being logged in if (reason == Reason.FORBIDDEN && user == null) { errors.addErrorMessage(i18nBean.getText("common.forms.ajax.unauthorised.alert"), Reason.NOT_LOGGED_IN); } return errors; }
private ErrorCollection validateUpdateProjectData(ApplicationUser user, String name, Project oldProject, ApplicationUser lead, String url, Long assigneeType, Long avatarId) { final ErrorCollection errorCollection = ErrorCollections.empty(); final I18nHelper i18nHelper = getI18nBean(user); validateProjectNameForUpdate(name, oldProject.getKey(), errorCollection, i18nHelper); validateProjectLead(Option.option(lead), errorCollection, i18nHelper); validateProjectUrl(url, errorCollection, i18nHelper); validateProjectAssigneeType(assigneeType, errorCollection, i18nHelper); validateAvatarId(avatarId, oldProject, errorCollection, i18nHelper); return errorCollection; }
@Nonnull @Override public CreateProjectValidationResult validateCreateProjectBasedOnExistingProject( final ApplicationUser user, @Nonnull final Long existingProjectId, @Nonnull ProjectCreationData input ) { final JiraServiceContext serviceContext = getServiceContext(user, ErrorCollections.empty()); final I18nHelper i18nBean = getI18nBean(user); if (!globalPermissionManager.hasPermission(GlobalPermissionKey.ADMINISTER, user)) { serviceContext.getErrorCollection().addErrorMessage(i18nBean.getText("admin.projects.service.error.no.admin.permission"), Reason.FORBIDDEN); return new CreateProjectValidationResult(serviceContext.getErrorCollection()); } final GetProjectResult projectById = getProjectByIdForAction(user, existingProjectId, ProjectAction.EDIT_PROJECT_CONFIG); if (!projectById.isValid()) { return new CreateProjectValidationResult(projectById.getErrorCollection()); } final ProjectCreationData creationData = new ProjectCreationData.Builder().fromExistingProject(projectById.get(), input).build(); isValidAllProjectData(serviceContext, creationData); return new CreateProjectValidationResult(serviceContext.getErrorCollection(), user, creationData, Optional.of(existingProjectId)); }
@Override public @Nonnull CreateProjectValidationResult validateCreateProject(ApplicationUser user, @Nonnull ProjectCreationData projectCreationData) { final JiraServiceContext serviceContext = getServiceContext(user, ErrorCollections.empty()); final I18nHelper i18nBean = getI18nBean(user); if (!globalPermissionManager.hasPermission(GlobalPermissionKey.ADMINISTER, user)) { serviceContext.getErrorCollection().addErrorMessage(i18nBean.getText("admin.projects.service.error.no.admin.permission"), Reason.FORBIDDEN); return new CreateProjectValidationResult(serviceContext.getErrorCollection()); } ProjectCreationData overridenProjectCreationData = overrideProjectTypeUsingTypeFromProjectTemplate(projectCreationData); isValidAllProjectData(serviceContext, overridenProjectCreationData); if (serviceContext.getErrorCollection().hasAnyErrors()) { return new CreateProjectValidationResult(serviceContext.getErrorCollection()); } return new CreateProjectValidationResult(serviceContext.getErrorCollection(), user, overridenProjectCreationData); }
@Override public Either<Project, ErrorCollection> updateProjectType(ApplicationUser user, Project project, ProjectTypeKey newProjectType) { I18nHelper i18nBean = getI18nBean(user); ErrorCollection errorCollection = new SimpleErrorCollection(); if (!checkActionPermission(user, project, ProjectAction.EDIT_PROJECT_CONFIG)) { errorCollection.addErrorMessage(i18nBean.getText("admin.errors.project.type.update.no.permission"), Reason.FORBIDDEN); } validateProjectType(user, newProjectType, errorCollection, i18nBean); if (errorCollection.hasAnyErrors()) { return Either.right(errorCollection); } return executeUnderClusterLock(getLockNameFor(project), () -> { Project updatedProject = projectManager.updateProjectType(user, project, newProjectType); return notifyProjectTypeUpdated(user, updatedProject, project.getProjectTypeKey(), newProjectType); }); }
@Override public DeleteProjectValidationResult validateDeleteProject(ApplicationUser user, String key) { final I18nHelper i18nBean = getI18nBean(user); if (!globalPermissionManager.hasPermission(GlobalPermissionKey.ADMINISTER, user)) { return new DeleteProjectValidationResult(ErrorCollections.create(i18nBean.getText("admin.projects.service.error.no.admin.permission"), Reason.FORBIDDEN)); } //check if the project exists. If not return with an error. final GetProjectResult oldProjectResult = getProjectByKeyForAction(user, key, ProjectAction.EDIT_PROJECT_CONFIG); if (!oldProjectResult.isValid() || oldProjectResult.getProject() == null) { return new DeleteProjectValidationResult(ErrorCollections.copyOf(oldProjectResult.getErrorCollection())); } return new DeleteProjectValidationResult(ErrorCollections.empty(), oldProjectResult.getProject()); }
private UpdateProjectValidationResult validateUpdateProject(final ApplicationUser user, final String name, final String oldKey, final String newKey, final String description, final String leadName, final String url, final Long assigneeType, final Long avatarId) final I18nHelper i18nBean = getI18nBean(user);
final I18nHelper i18nBean = getI18nBean(user);
final I18nHelper i18nBean = getI18nBean(user);