Skip to content

Commit

Permalink
EPMRPP-91633 update user assign flow
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Aug 14, 2024
1 parent 8e54a65 commit 2cea526
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerStatusCache.AUTO_ANALYZER_KEY;
import static com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum.AUTO_PATTERN_ANALYZER_ENABLED;
import static com.epam.ta.reportportal.entity.enums.SendCase.findByName;
import static com.epam.ta.reportportal.entity.organization.OrganizationRole.MEMBER;
import static com.epam.ta.reportportal.ws.converter.converters.ProjectActivityConverter.TO_ACTIVITY_RESOURCE;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -68,13 +69,16 @@
import com.epam.ta.reportportal.dao.ProjectUserRepository;
import com.epam.ta.reportportal.dao.UserPreferenceRepository;
import com.epam.ta.reportportal.dao.UserRepository;
import com.epam.ta.reportportal.dao.organization.OrganizationRepositoryCustom;
import com.epam.ta.reportportal.dao.organization.OrganizationUserRepository;
import com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum;
import com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum.Prefix;
import com.epam.ta.reportportal.entity.organization.MembershipDetails;
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.project.ProjectRole;
import com.epam.ta.reportportal.entity.project.ProjectUtils;
import com.epam.ta.reportportal.entity.project.email.SenderCase;
import com.epam.ta.reportportal.entity.user.OrganizationUser;
import com.epam.ta.reportportal.entity.user.ProjectUser;
import com.epam.ta.reportportal.entity.user.User;
import com.epam.ta.reportportal.entity.user.UserRole;
Expand Down Expand Up @@ -104,6 +108,7 @@
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
Expand All @@ -115,6 +120,7 @@
* @author Pavel Bortnik
*/
@Service
@Log4j2
public class UpdateProjectHandlerImpl implements UpdateProjectHandler {

private static final String UPDATE_EVENT = "update";
Expand All @@ -130,6 +136,8 @@ public class UpdateProjectHandlerImpl implements UpdateProjectHandler {
private final UserPreferenceRepository preferenceRepository;

private final ProjectUserRepository projectUserRepository;
private final OrganizationUserRepository organizationUserRepository;
private final OrganizationRepositoryCustom organizationRepositoryCustom;

private final MessageBus messageBus;

Expand All @@ -151,7 +159,9 @@ public class UpdateProjectHandlerImpl implements UpdateProjectHandler {
public UpdateProjectHandlerImpl(ProjectExtractor projectExtractor,
ProjectAttributeValidator projectAttributeValidator, ProjectRepository projectRepository,
UserRepository userRepository, UserPreferenceRepository preferenceRepository,
OrganizationUserRepository organizationUserRepository,
MessageBus messageBus, ProjectUserRepository projectUserRepository,
OrganizationRepositoryCustom organizationRepositoryCustom,
ApplicationEventPublisher applicationEventPublisher, MailServiceFactory mailServiceFactory,
AnalyzerStatusCache analyzerStatusCache, IndexerStatusCache indexerStatusCache,
AnalyzerServiceClient analyzerServiceClient, LogIndexer logIndexer,
Expand All @@ -161,8 +171,10 @@ public UpdateProjectHandlerImpl(ProjectExtractor projectExtractor,
this.projectRepository = projectRepository;
this.userRepository = userRepository;
this.preferenceRepository = preferenceRepository;
this.organizationUserRepository = organizationUserRepository;
this.messageBus = messageBus;
this.projectUserRepository = projectUserRepository;
this.organizationRepositoryCustom = organizationRepositoryCustom;
this.applicationEventPublisher = applicationEventPublisher;
this.mailServiceFactory = mailServiceFactory;
this.analyzerStatusCache = analyzerStatusCache;
Expand Down Expand Up @@ -273,9 +285,7 @@ public OperationCompletionRS assignUsers(String projectKey, AssignUsersRQ assign

ProjectRole projectRole = ProjectRole.forName(role)
.orElseThrow(() -> new ReportPortalException(ROLE_NOT_FOUND, role));
ProjectRole modifierRole = membershipDetails.getProjectRole();
expect(modifierRole.sameOrHigherThan(projectRole), BooleanUtils::isTrue).verify(
ACCESS_DENIED);

assignUser(name, projectRole, assignedUsernames, project, user);
});
}
Expand Down Expand Up @@ -389,6 +399,22 @@ private void assignUser(String name, ProjectRole projectRole, List<String> assig
formattedSupplier("User '{}' cannot be assigned to project twice.", name)
);

// assign user to organization if not assigned yet
var organization = organizationRepositoryCustom.findById(project.getOrganizationId())
.orElseThrow(() -> new ReportPortalException(ErrorType.ORGANIZATION_NOT_FOUND,
project.getOrganizationId()));
organizationUserRepository.findByUserIdAndOrganization_Id(modifyingUser.getId(),
project.getOrganizationId())
.orElseGet(() -> {
log.debug("Assigning user {} to organization {}",
modifyingUser.getLogin(), organization.getName());
var organizationUser = new OrganizationUser();
organizationUser.setOrganization(organization);
organizationUser.setUser(modifyingUser);
organizationUser.setOrganizationRole(MEMBER);
return organizationUserRepository.save(organizationUser);
});

ProjectUser projectUser = new ProjectUser();
projectUser.setProjectRole(projectRole);
projectUser.setUser(modifyingUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.epam.ta.reportportal.auth.permissions.Permissions.ORGANIZATION_MEMBER;
import static com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.USER;

import com.epam.reportportal.api.OrganizationsApi;
import com.epam.reportportal.api.OrganizationApi;
import com.epam.reportportal.api.model.OrganizationProfile;
import com.epam.reportportal.api.model.OrganizationProfilesPage;
import com.epam.reportportal.api.model.SearchCriteriaRQ;
Expand All @@ -40,7 +40,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrganizationController extends BaseController implements OrganizationsApi {
public class OrganizationController extends BaseController implements OrganizationApi {

private final GetOrganizationHandler getOrganizationHandler;
private final OrganizationsSearchCriteriaService searchCriteriaService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static com.epam.ta.reportportal.auth.permissions.Permissions.ORGANIZATION_MEMBER;
import static org.springframework.http.HttpStatus.OK;

import com.epam.reportportal.api.ProjectsApi;
import com.epam.reportportal.api.OrganizationProjectApi;
import com.epam.reportportal.api.model.OrganizationProjectInfo;
import com.epam.reportportal.api.model.OrganizationProjectsPage;
import com.epam.reportportal.api.model.ProjectDetails;
Expand Down Expand Up @@ -51,7 +51,8 @@
* @author Siarhei Hrabko
*/
@RestController
public class OrganizationProjectController extends BaseController implements ProjectsApi {
public class OrganizationProjectController extends BaseController implements
OrganizationProjectApi {

private final OrganizationProjectHandler organizationProjectHandler;
private final OrganizationRepositoryCustom organizationRepositoryCustom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.epam.ta.reportportal.auth.permissions.Permissions.ORGANIZATION_MANAGER;
import static com.epam.ta.reportportal.commons.querygen.constant.UserCriteriaConstant.CRITERIA_FULL_NAME;

import com.epam.reportportal.api.UsersApi;
import com.epam.reportportal.api.OrganizationUserApi;
import com.epam.reportportal.api.model.OrganizationUsersPage;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
Expand All @@ -38,7 +38,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrganizationUsersController extends BaseController implements UsersApi {
public class OrganizationUsersController extends BaseController implements OrganizationUserApi {

private final OrganizationRepositoryCustom organizationRepositoryCustom;

Expand Down

0 comments on commit 2cea526

Please sign in to comment.