use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminChangesProjectOwner in project sechub by mercedes-benz.
the class InformThatProjectHasNewOwnerNotificationService method notify.
@UseCaseAdminChangesProjectOwner(@Step(number = 4, name = "Inform new and previous project owners that the project owner ship has changed"))
public void notify(ProjectMessage projectMessage, String baseUrl) {
requireNonNull(projectMessage);
String projectOwnerEmailAddress = projectMessage.getProjectOwnerEmailAddress();
String previousOwnerEmailAddress = projectMessage.getPreviousProjectOwnerEmailAddress();
if (projectOwnerEmailAddress == null || projectOwnerEmailAddress.isEmpty()) {
LOG.warn("No project owner email set - can not inform owner about owner change of project {}", projectMessage.getProjectId());
return;
}
if (previousOwnerEmailAddress == null || previousOwnerEmailAddress.isEmpty()) {
LOG.warn("No previous project owner email set - can not inform previous owner about owner change of project {}", projectMessage.getProjectId());
return;
}
Set<String> ccMailsSet = projectMessage.getUserEmailAdresses();
ccMailsSet.add(previousOwnerEmailAddress);
String[] ccAddresses = ccMailsSet.stream().toArray(String[]::new);
SimpleMailMessage message = factory.createMessage("Owner of project " + projectMessage.getProjectId() + " changed");
StringBuilder emailContent = new StringBuilder();
emailContent.append("Ownership of the project '" + projectMessage.getProjectId());
emailContent.append("' in environment " + baseUrl + " has changed.");
emailContent.append("\n\nPrevious owner: " + previousOwnerEmailAddress);
emailContent.append("\nNew owner: " + projectOwnerEmailAddress);
message.setTo(projectOwnerEmailAddress);
message.setCc(ccAddresses);
message.setText(emailContent.toString());
emailService.send(message);
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminChangesProjectOwner in project sechub by mercedes-benz.
the class ProjectChangeOwnerService method changeProjectOwner.
/* @formatter:off */
@UseCaseAdminChangesProjectOwner(@Step(number = 2, name = "Change project owner", description = "The service will set the user as the owner of the project. If user does not have ROLE_OWNER it will obtain it. The old owner will loose project ownership."))
public /* @formatter:on */
void changeProjectOwner(String newOnwerUserId, String projectId) {
LOG.info("User {} triggers project owner change - user:{} to project:{}", userContextService.getUserId(), logSanitizer.sanitize(newOnwerUserId, 30), logSanitizer.sanitize(projectId, 30));
assertion.assertIsValidUserId(newOnwerUserId);
assertion.assertIsValidProjectId(projectId);
Project project = projectRepository.findOrFailProject(projectId);
User newOwner = userRepository.findOrFailUser(newOnwerUserId);
if (project.owner.equals(newOwner)) {
throw new AlreadyExistsException("User already assigned in the role as owner to this project!");
}
User previousOwner = changeProjectOwnerAndReturnPreviousOwner(project, newOwner);
transactionService.saveInOwnTransaction(project, newOwner, previousOwner);
sendOwnerChangedForProjectEvent(project, previousOwner, newOwner);
sendRequestOwnerRoleRecalculation(newOwner);
sendRequestOwnerRoleRecalculation(previousOwner);
}
Aggregations