Search in sources :

Example 1 with AssignUsersRQ

use of com.epam.ta.reportportal.ws.model.project.AssignUsersRQ in project service-api by reportportal.

the class ProjectControllerTest method assignProjectUsersPositive.

@Test
void assignProjectUsersPositive() throws Exception {
    AssignUsersRQ rq = new AssignUsersRQ();
    Map<String, String> user = new HashMap<>();
    user.put("default", "MEMBER");
    rq.setUserNames(user);
    mockMvc.perform(put("/v1/project/test_project/assign").with(token(oAuthHelper.getSuperadminToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isOk());
}
Also used : AssignUsersRQ(com.epam.ta.reportportal.ws.model.project.AssignUsersRQ) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 2 with AssignUsersRQ

use of com.epam.ta.reportportal.ws.model.project.AssignUsersRQ in project service-api by reportportal.

the class UpdateProjectHandlerImpl method assignUsers.

@Override
public OperationCompletionRS assignUsers(String projectName, AssignUsersRQ assignUsersRQ, ReportPortalUser user) {
    if (UserRole.ADMINISTRATOR.equals(user.getUserRole())) {
        Project project = projectRepository.findByName(normalizeId(projectName)).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, normalizeId(projectName)));
        List<String> assignedUsernames = project.getUsers().stream().map(u -> u.getUser().getLogin()).collect(toList());
        assignUsersRQ.getUserNames().forEach((name, role) -> {
            ProjectRole projectRole = ProjectRole.forName(role).orElseThrow(() -> new ReportPortalException(ROLE_NOT_FOUND, role));
            assignUser(name, projectRole, assignedUsernames, project);
        });
    } else {
        expect(assignUsersRQ.getUserNames().keySet(), not(Preconditions.contains(equalTo(user.getUsername())))).verify(UNABLE_ASSIGN_UNASSIGN_USER_TO_PROJECT, "User should not assign himself to project.");
        ReportPortalUser.ProjectDetails projectDetails = projectExtractor.extractProjectDetails(user, projectName);
        Project project = projectRepository.findById(projectDetails.getProjectId()).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, normalizeId(projectName)));
        List<String> assignedUsernames = project.getUsers().stream().map(u -> u.getUser().getLogin()).collect(toList());
        assignUsersRQ.getUserNames().forEach((name, role) -> {
            ProjectRole projectRole = ProjectRole.forName(role).orElseThrow(() -> new ReportPortalException(ROLE_NOT_FOUND, role));
            ProjectRole modifierRole = projectDetails.getProjectRole();
            expect(modifierRole.sameOrHigherThan(projectRole), BooleanUtils::isTrue).verify(ACCESS_DENIED);
            assignUser(name, projectRole, assignedUsernames, project);
        });
    }
    return new OperationCompletionRS("User(s) with username='" + assignUsersRQ.getUserNames().keySet() + "' was successfully assigned to project='" + normalizeId(projectName) + "'");
}
Also used : SenderCase(com.epam.ta.reportportal.entity.project.email.SenderCase) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) Autowired(org.springframework.beans.factory.annotation.Autowired) ProjectAttributesActivityResource(com.epam.ta.reportportal.ws.model.activity.ProjectAttributesActivityResource) ProjectAttributeEnum(com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) ProjectResource(com.epam.ta.reportportal.ws.model.project.ProjectResource) Predicates(com.epam.ta.reportportal.commons.Predicates) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) UserType(com.epam.ta.reportportal.entity.user.UserType) Preconditions(com.epam.ta.reportportal.commons.Preconditions) ProjectAnalyzerConfigEvent(com.epam.ta.reportportal.core.events.activity.ProjectAnalyzerConfigEvent) ProjectIndexEvent(com.epam.ta.reportportal.core.events.activity.ProjectIndexEvent) Suppliers.formattedSupplier(com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier) Collectors.toSet(java.util.stream.Collectors.toSet) NotificationConfigConverter(com.epam.ta.reportportal.ws.converter.converters.NotificationConfigConverter) ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) LogIndexer(com.epam.ta.reportportal.core.analyzer.auto.LogIndexer) UpdateProjectRQ(com.epam.ta.reportportal.ws.model.project.UpdateProjectRQ) Predicate(java.util.function.Predicate) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) ProjectEvent(com.epam.reportportal.extension.event.ProjectEvent) UserRepository(com.epam.ta.reportportal.dao.UserRepository) ProjectUtils(com.epam.ta.reportportal.entity.project.ProjectUtils) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Collectors(java.util.stream.Collectors) AnalyzerUtils(com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) NotificationsConfigUpdatedEvent(com.epam.ta.reportportal.core.events.activity.NotificationsConfigUpdatedEvent) EmailRulesValidator(com.epam.ta.reportportal.util.email.EmailRulesValidator) AUTO_ANALYZER_KEY(com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerStatusCache.AUTO_ANALYZER_KEY) ProjectConfigurationUpdate(com.epam.ta.reportportal.ws.model.project.config.ProjectConfigurationUpdate) SendCase.findByName(com.epam.ta.reportportal.entity.enums.SendCase.findByName) IndexerStatusCache(com.epam.ta.reportportal.core.analyzer.auto.indexer.IndexerStatusCache) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) Preconditions.contains(com.epam.ta.reportportal.commons.Preconditions.contains) BooleanUtils(org.apache.commons.lang3.BooleanUtils) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.ProjectActivityConverter.TO_ACTIVITY_RESOURCE) ProjectConverter(com.epam.ta.reportportal.ws.converter.converters.ProjectConverter) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) AssignUsersRQ(com.epam.ta.reportportal.ws.model.project.AssignUsersRQ) UpdateProjectHandler(com.epam.ta.reportportal.core.project.UpdateProjectHandler) ProjectUpdatedEvent(com.epam.ta.reportportal.core.events.activity.ProjectUpdatedEvent) ProjectType(com.epam.ta.reportportal.entity.enums.ProjectType) ProjectExtractor(com.epam.ta.reportportal.util.ProjectExtractor) MailServiceFactory(com.epam.ta.reportportal.util.email.MailServiceFactory) Lists(com.google.common.collect.Lists) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) UserRole(com.epam.ta.reportportal.entity.user.UserRole) BasePermission(org.springframework.security.acls.domain.BasePermission) AnalyzerStatusCache(com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerStatusCache) UserPreferenceRepository(com.epam.ta.reportportal.dao.UserPreferenceRepository) SenderCaseDTO(com.epam.ta.reportportal.ws.model.project.email.SenderCaseDTO) ProjectAttributeValidator(com.epam.ta.reportportal.core.project.validator.attribute.ProjectAttributeValidator) MapUtils(org.apache.commons.collections.MapUtils) Optional.ofNullable(java.util.Optional.ofNullable) ProjectUserRepository(com.epam.ta.reportportal.dao.ProjectUserRepository) User(com.epam.ta.reportportal.entity.user.User) UnassignUsersRQ(com.epam.ta.reportportal.ws.model.project.UnassignUsersRQ) EntityUtils.normalizeId(com.epam.ta.reportportal.commons.EntityUtils.normalizeId) Collectors.toList(java.util.stream.Collectors.toList) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) BusinessRule.fail(com.epam.ta.reportportal.commons.validation.BusinessRule.fail) Cache(com.google.common.cache.Cache) AnalyzerServiceClient(com.epam.ta.reportportal.core.analyzer.auto.client.AnalyzerServiceClient) ProjectNotificationConfigDTO(com.epam.ta.reportportal.ws.model.project.email.ProjectNotificationConfigDTO) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

AssignUsersRQ (com.epam.ta.reportportal.ws.model.project.AssignUsersRQ)2 ProjectEvent (com.epam.reportportal.extension.event.ProjectEvent)1 ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)1 EntityUtils.normalizeId (com.epam.ta.reportportal.commons.EntityUtils.normalizeId)1 Preconditions (com.epam.ta.reportportal.commons.Preconditions)1 Preconditions.contains (com.epam.ta.reportportal.commons.Preconditions.contains)1 Predicates (com.epam.ta.reportportal.commons.Predicates)1 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)1 BusinessRule.fail (com.epam.ta.reportportal.commons.validation.BusinessRule.fail)1 Suppliers.formattedSupplier (com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier)1 LogIndexer (com.epam.ta.reportportal.core.analyzer.auto.LogIndexer)1 AnalyzerServiceClient (com.epam.ta.reportportal.core.analyzer.auto.client.AnalyzerServiceClient)1 AnalyzerStatusCache (com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerStatusCache)1 AUTO_ANALYZER_KEY (com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerStatusCache.AUTO_ANALYZER_KEY)1 AnalyzerUtils (com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils)1 IndexerStatusCache (com.epam.ta.reportportal.core.analyzer.auto.indexer.IndexerStatusCache)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 NotificationsConfigUpdatedEvent (com.epam.ta.reportportal.core.events.activity.NotificationsConfigUpdatedEvent)1 ProjectAnalyzerConfigEvent (com.epam.ta.reportportal.core.events.activity.ProjectAnalyzerConfigEvent)1