private void checkProjectAdminPermission(ErrorCollection errorCollection, ProjectComponent component, ApplicationUser user) { if (component == null) { errorCollection.addErrorMessage(translateKeyToMessage(KEY_NO_SUCH_COMPONENT, null), ErrorCollection.Reason.FORBIDDEN); } else { Long projectId = component.getProjectId(); checkProjectAdminPermission(errorCollection, projectId, user); } }
private void removeComponentForAffectedIssues(final JiraServiceContext context, final ProjectComponent component) { //call the swapComponent method with a null swapcomponent. Effectively means the old compoment will be removed //and nothing gets swapped in. swapComponentForAffectedIssues(context, component, null); }
@Override void validateData() { validateProjectId(this, projectId); validateName(this, null, name, projectId); validateLead(this, lead); validateAssigneeType(this, assigneeType); }
@Override void validateData() { validateProjectId(this, projectId); validateName(this, null, name, projectId); validateLead(this, lead); }
@Override public void deleteComponentForIssues(final JiraServiceContext context, Long componentId) { final ErrorCollection errorCollection = context.getErrorCollection(); final ApplicationUser user = context.getLoggedInUser(); // Validate that we can find the component we are deleting ProjectComponent component = validateAndGetComponent(componentId, KEY_NO_SUCH_COMPONENT, KEY_NO_SUCH_COMPONENT_WITH_ID, errorCollection); if(errorCollection.hasAnyErrors()) { return; } // Validate that we have permission to delete and swap the components checkProjectAdminPermission(errorCollection, component, user); if(errorCollection.hasAnyErrors()) { return; } // Now lets remove the component from all affected issues. removeComponentForAffectedIssues(context, component); if(errorCollection.hasAnyErrors()) { return; } // Now do the actual delete if there were no errors swaping components delete(context, componentId); }
ProjectComponent swapComponent = validateAndGetComponent(swapComponentId, KEY_NO_SUCH_COMPONENT_TO_SWAP_WITH_ID, KEY_NO_SUCH_COMPONENT_TO_SWAP_WITH_ID, errorCollection); if(errorCollection.hasAnyErrors()) ProjectComponent component = validateAndGetComponent(componentId, KEY_NO_SUCH_COMPONENT, KEY_NO_SUCH_COMPONENT_WITH_ID, errorCollection); if(errorCollection.hasAnyErrors()) checkProjectAdminPermission(errorCollection, component, user); if(errorCollection.hasAnyErrors()) swapComponentForAffectedIssues(context, component, swapComponent); if(errorCollection.hasAnyErrors()) delete(context, componentId);
@Override void validateData() { // validate lead validateLead(this, component.getLead()); // validate name Long id = component.getId(); try { ProjectComponent oldComponent = projectComponentManager.find(id); String oldName = oldComponent.getName(); if (!oldName.equalsIgnoreCase(component.getName())) { validateName(this, oldName, component.getName(), oldComponent.getProjectId()); } } catch (EntityNotFoundException e) { if (id != null) { addErrorKey(KEY_NO_SUCH_COMPONENT_WITH_ID, id.toString(), ErrorCollection.Reason.VALIDATION_FAILED); } else { addErrorKey(KEY_NO_SUCH_COMPONENT, null, ErrorCollection.Reason.VALIDATION_FAILED); } } }
private ProjectComponent validateAndGetComponent(Long componentId, String errorMsgNoId, String errorMsgNoCompWithId, ErrorCollection errorCollection) { if(componentId == null) { errorCollection.addErrorMessage(translateKeyToMessage(errorMsgNoId, null), ErrorCollection.Reason.VALIDATION_FAILED); return null; } try { return projectComponentManager.find(componentId); } catch (EntityNotFoundException e) { errorCollection.addErrorMessage(translateKeyToMessage(errorMsgNoCompWithId, componentId.toString()), ErrorCollection.Reason.VALIDATION_FAILED); return null; } }
private void checkProjectAdminPermission(Handler handler, ProjectComponent component, ApplicationUser user) { if (component == null) { handler.addErrorKey(KEY_NO_SUCH_COMPONENT, null, ErrorCollection.Reason.FORBIDDEN); } else { Long projectId = component.getProjectId(); checkProjectAdminPermission(handler, projectId, user); } }
private void swapComponentForAffectedIssues(final JiraServiceContext context, final ProjectComponent component, final ProjectComponent swapComponent) { // Get all issues that reference the component we are going to delete Collection<Long> affectedIssues = projectComponentManager.getIssueIdsWithComponent(component); for (final Long issueId : affectedIssues) { MutableIssue issue = issueManager.getIssueObject(issueId); Collection<ProjectComponent> newComponents = getNewComponents(issue, component, swapComponent); issue.setComponent(newComponents); // Use the backend issue update action to update the issue issueManager.updateIssue(context.getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false); } // publish project component merged event if necessary if (!affectedIssues.isEmpty() && swapComponent != null) { eventPublisher.publish(new ProjectComponentMergedEvent(swapComponent, component)); } }
private void checkProjectAdminPermission(ErrorCollection errorCollection, Long projectId, ApplicationUser user) { boolean hasProjectAdminPermission = permissionManager.hasPermission(Permissions.ADMINISTER, user) || permissionManager.hasPermission(ADMINISTER_PROJECTS, projectManager.getProjectObj(projectId), user); if (!hasProjectAdminPermission) { if (user != null) { errorCollection.addErrorMessage(translateKeyToMessage(KEY_USER_NO_PERMISSION_WITH_USER, user.getName()), ErrorCollection.Reason.FORBIDDEN); } else { errorCollection.addErrorMessage(translateKeyToMessage(KEY_USER_NO_PERMISSION, null), ErrorCollection.Reason.FORBIDDEN); } } }