Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-89198 routing refactor #1926

Merged
merged 17 commits into from
Feb 26, 2024
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -72,9 +72,9 @@ dependencies {
implementation 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:commons-events:e337f8b7be'
implementation 'com.github.reportportal:commons-dao:458b67ab61'
implementation 'com.github.reportportal:commons-dao:b15003e'
implementation 'com.github.reportportal:commons-rules:42d4dd5634'
implementation 'com.github.reportportal:commons-model:c800793'
implementation 'com.github.reportportal:commons-model:950d304'
implementation 'com.github.reportportal:commons:07566b8e'
implementation 'com.github.reportportal:commons-fonts:d6e62dd'
implementation 'com.github.reportportal:plugin-api:0ccfed880c'
@@ -90,6 +90,8 @@ dependencies {


implementation 'com.opencsv:opencsv:5.8'
implementation 'com.github.slugify:slugify:3.0.6'


// Fix CVE-2021-41079, CVE-2022-23181, CVE-2021-33037, CVE-2021-30640, CVE-2022-42252
implementation 'org.apache.tomcat.embed:tomcat-embed-core:9.0.82'
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ services:
ports:
- "5432:5432"

elastic:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.3.0
opensearch:
image: opensearchproject/opensearch:2.11.0
restart: always
volumes:
- elastic:/usr/share/elasticsearch/data
- opensearch:/usr/share/opensearch/data
environment:
- "bootstrap.memory_lock=true"
- "discovery.type=single-node"
@@ -77,5 +77,5 @@ services:

volumes:
reportportal-database:
elastic:
opensearch:
minio:
2 changes: 2 additions & 0 deletions project-properties.gradle
Original file line number Diff line number Diff line change
@@ -67,6 +67,8 @@ project.ext {
(migrationsUrl + '/migrations/76_user_bid_extension.up.sql') : 'V076__user_bid_extension.sql',
(migrationsUrl + '/migrations/77_email_server_documentation_link.up.sql') : 'V077__email_server_documentation_link.sql',
(migrationsUrl + '/migrations/78_drop_redundant_index.up.sql') : 'V078__drop_redundant_index.sql',
(migrationsUrl + '/migrations/83_add_slugify_function.up.sql') : 'V083__add_slugify_function.sql',
(migrationsUrl + '/migrations/84_organization_tables.up.sql') : 'V084__organization_tables.sql',
]
excludeTests = ['**/entity/**',
'**/aop/**',
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ protected BaseProjectPermission(ProjectExtractor projectExtractor) {
* subclass
*/
@Override
public boolean isAllowed(Authentication authentication, Object projectName) {
public boolean isAllowed(Authentication authentication, Object projectKey) {
if (!authentication.isAuthenticated()) {
return false;
}
@@ -56,14 +56,14 @@ public boolean isAllowed(Authentication authentication, Object projectName) {
ReportPortalUser rpUser = (ReportPortalUser) oauth.getUserAuthentication().getPrincipal();
BusinessRule.expect(rpUser, Objects::nonNull).verify(ErrorType.ACCESS_DENIED);

final String resolvedProjectName = String.valueOf(projectName);
final String resolvedProjectKey = String.valueOf(projectKey);
final ReportPortalUser.ProjectDetails projectDetails = projectExtractor.findProjectDetails(
rpUser, resolvedProjectName)
rpUser, resolvedProjectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.ACCESS_DENIED));
fillProjectDetails(rpUser, resolvedProjectName, projectDetails);
fillProjectDetails(rpUser, resolvedProjectKey, projectDetails);

ProjectRole role = projectDetails.getProjectRole();
return checkAllowed(rpUser, projectName.toString(), role);
return checkAllowed(rpUser, projectKey.toString(), role);
}

private void fillProjectDetails(ReportPortalUser rpUser, String resolvedProjectName,
@@ -83,4 +83,4 @@ private void fillProjectDetails(ReportPortalUser rpUser, String resolvedProjectN
* @return TRUE if access allowed
*/
abstract protected boolean checkAllowed(ReportPortalUser user, String project, ProjectRole role);
}
}
Original file line number Diff line number Diff line change
@@ -29,20 +29,15 @@ private Permissions() {

public static final String ADMIN_ONLY = "hasRole('ADMINISTRATOR')";

public static final String ALLOWED_TO_EDIT_USER =
"(#login.toLowerCase() == authentication.name)" + "||" + ADMIN_ONLY;
public static final String ALLOWED_TO_EDIT_USER = "(#login.toLowerCase() == authentication.name)" + "||" + ADMIN_ONLY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 100 characters (found 120).


public static final String ALLOWED_TO_REPORT =
"hasPermission(#projectName.toLowerCase(), 'reporterPermission')" + "||" + ADMIN_ONLY;
public static final String ALLOWED_TO_REPORT = "hasPermission(#projectKey.toLowerCase(), 'reporterPermission')" + "||" + ADMIN_ONLY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 100 characters (found 134).


public static final String ASSIGNED_TO_PROJECT = "hasPermission(#projectName.toLowerCase(), 'isAssignedToProject')";
public static final String ASSIGNED_TO_PROJECT = "hasPermission(#projectKey.toLowerCase(), 'isAssignedToProject')";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 100 characters (found 117).


public static final String PROJECT_MANAGER =
"hasPermission(#projectName.toLowerCase(), 'projectManagerPermission')" + "||" + ADMIN_ONLY;
public static final String PROJECT_MANAGER = "hasPermission(#projectKey.toLowerCase(), 'projectManagerPermission')" + "||" + ADMIN_ONLY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 100 characters (found 138).


public static final String NOT_CUSTOMER =
"hasPermission(#projectName.toLowerCase(), 'notCustomerPermission')" + "||" + ADMIN_ONLY;
public static final String NOT_CUSTOMER = "hasPermission(#projectKey.toLowerCase(), 'notCustomerPermission')" + "||" + ADMIN_ONLY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 100 characters (found 132).


public static final String PROJECT_MANAGER_OR_ADMIN =
"hasPermission(#projectName.toLowerCase(), 'projectManagerPermission')" + "||" + ADMIN_ONLY;
}
public static final String PROJECT_MANAGER_OR_ADMIN = "hasPermission(#projectKey.toLowerCase(), 'projectManagerPermission')" + "||" + ADMIN_ONLY;
}
Original file line number Diff line number Diff line change
@@ -67,12 +67,12 @@ public BinaryData getUserPhoto(ReportPortalUser loggedInUser, boolean loadThumbn
}

@Override
public BinaryData getUserPhoto(String username, ReportPortalUser loggedInUser, String projectName,
public BinaryData getUserPhoto(String username, ReportPortalUser loggedInUser, String projectKey,
boolean loadThumbnail) {
User user = userRepository.findByLogin(username)
.orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, username));
ReportPortalUser.ProjectDetails projectDetails = projectExtractor.extractProjectDetailsAdmin(
loggedInUser, projectName);
loggedInUser, projectKey);
if (loggedInUser.getUserRole() != UserRole.ADMINISTRATOR) {
expect(
ProjectUtils.isAssignedToProject(user, projectDetails.getProjectId()),
Original file line number Diff line number Diff line change
@@ -108,11 +108,11 @@ public EntryCreatedRS createGlobalIntegration(IntegrationRQ createRequest, Strin
}

@Override
public EntryCreatedRS createProjectIntegration(String projectName, IntegrationRQ createRequest,
public EntryCreatedRS createProjectIntegration(String projectKey, IntegrationRQ createRequest,
String pluginName, ReportPortalUser user) {

Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectKey));

IntegrationType integrationType = integrationTypeRepository.findByName(pluginName)
.orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, pluginName));
@@ -175,11 +175,11 @@ public OperationCompletionRS updateGlobalIntegration(Long id, IntegrationRQ upda
}

@Override
public OperationCompletionRS updateProjectIntegration(Long id, String projectName,
public OperationCompletionRS updateProjectIntegration(Long id, String projectKey,
IntegrationRQ updateRequest, ReportPortalUser user) {

Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectKey));

final Integration integration = integrationRepository.findByIdAndProjectId(id, project.getId())
.orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, id));
Original file line number Diff line number Diff line change
@@ -16,6 +16,10 @@

package com.epam.ta.reportportal.core.integration.impl;

import static com.epam.ta.reportportal.ws.converter.converters.IntegrationConverter.TO_ACTIVITY_RESOURCE;
import static com.epam.ta.reportportal.ws.model.ErrorType.INTEGRATION_NOT_FOUND;
import static com.epam.ta.reportportal.ws.model.ErrorType.PROJECT_NOT_FOUND;

import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.commons.validation.Suppliers;
import com.epam.ta.reportportal.core.events.activity.IntegrationDeletedEvent;
@@ -29,17 +33,12 @@
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

import static com.epam.ta.reportportal.ws.converter.converters.IntegrationConverter.TO_ACTIVITY_RESOURCE;
import static com.epam.ta.reportportal.ws.model.ErrorType.INTEGRATION_NOT_FOUND;
import static com.epam.ta.reportportal.ws.model.ErrorType.PROJECT_NOT_FOUND;

/**
* @author <a href="mailto:andrei_varabyeu@epam.com">Andrei Varabyeu</a>
*/
@@ -96,10 +95,10 @@ public OperationCompletionRS deleteGlobalIntegrationsByType(String type, ReportP
}

@Override
public OperationCompletionRS deleteProjectIntegration(Long integrationId, String projectName,
public OperationCompletionRS deleteProjectIntegration(Long integrationId, String projectKey,
ReportPortalUser user) {
Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectKey));
Integration integration = integrationRepository.findByIdAndProjectId(integrationId,
project.getId())
.orElseThrow(() -> new ReportPortalException(INTEGRATION_NOT_FOUND, integrationId));
@@ -115,10 +114,10 @@ public OperationCompletionRS deleteProjectIntegration(Long integrationId, String
}

@Override
public OperationCompletionRS deleteProjectIntegrationsByType(String type, String projectName,
public OperationCompletionRS deleteProjectIntegrationsByType(String type, String projectKey,
ReportPortalUser user) {
Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectKey));
IntegrationType integrationType = integrationTypeRepository.findByName(type)
.orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, type));
List<Integration> integrations = integrationRepository.findAllByProjectIdAndInIntegrationTypeIds(
Original file line number Diff line number Diff line change
@@ -73,9 +73,9 @@ public GetIntegrationHandlerImpl(@Qualifier("integrationServiceMapping")
}

@Override
public IntegrationResource getProjectIntegrationById(Long integrationId, String projectName) {
Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
public IntegrationResource getProjectIntegrationById(Long integrationId, String projectKey) {
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectKey));
Integration integration =
integrationRepository.findByIdAndProjectId(integrationId, project.getId()).orElseThrow(
() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, integrationId));
@@ -194,17 +194,17 @@ public List<IntegrationResource> getGlobalIntegrations(String pluginName) {
}

@Override
public List<IntegrationResource> getProjectIntegrations(String projectName) {
Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
public List<IntegrationResource> getProjectIntegrations(String projectKey) {
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectKey));
return integrationRepository.findAllByProjectIdOrderByCreationDateDesc(project.getId()).stream()
.map(TO_INTEGRATION_RESOURCE).collect(Collectors.toList());
}

@Override
public List<IntegrationResource> getProjectIntegrations(String pluginName, String projectName) {
Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
public List<IntegrationResource> getProjectIntegrations(String pluginName, String projectKey) {
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectKey));
IntegrationType integrationType = integrationTypeRepository.findByName(pluginName)
.orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, pluginName));
return integrationRepository.findAllByProjectIdAndTypeOrderByCreationDateDesc(project.getId(),
@@ -213,9 +213,9 @@ public List<IntegrationResource> getProjectIntegrations(String pluginName, Strin
}

@Override
public boolean testConnection(Long integrationId, String projectName) {
Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
public boolean testConnection(Long integrationId, String projectKey) {
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectKey));

Integration integration =
integrationRepository.findByIdAndProjectId(integrationId, project.getId()).orElseGet(
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ public Map<String, Object> convertParams(ProjectInfo project) {
params.put(ProjectReportConstants.PROJECT_TYPE, project.getProjectType());
params.put(ProjectReportConstants.PROJECT_NAME, project.getName());
params.put(ProjectReportConstants.ORGANIZATION,
ofNullable(project.getOrganization()).orElse(EMPTY_STRING));
ofNullable(project.getOrganizationSlug()).orElse(EMPTY_STRING));
params.put(ProjectReportConstants.MEMBERS, project.getUsersQuantity());
params.put(ProjectReportConstants.LAUNCHES, project.getLaunchesQuantity());

Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ public FinishLaunchRS finishLaunch(String launchId, FinishExecutionRQ finishLaun
FinishLaunchRS response = new FinishLaunchRS();
response.setId(launch.getUuid());
response.setNumber(launch.getNumber());
response.setLink(generateLaunchLink(baseUrl, projectDetails.getProjectName(),
response.setLink(generateLaunchLink(baseUrl, projectDetails.getProjectKey(),
String.valueOf(launch.getId())
));
return response;
Original file line number Diff line number Diff line change
@@ -169,10 +169,10 @@ private Launch findLaunch(String launchId, ReportPortalUser.ProjectDetails proje
}

@Override
public LaunchResource getLaunchByProjectName(String projectName, Pageable pageable, Filter filter,
public LaunchResource getLaunchByProjectName(String projectKey, Pageable pageable, Filter filter,
String username) {
Project project = projectRepository.findByName(projectName)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectName));
Project project = projectRepository.findByKey(projectKey)
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectKey));

Page<Launch> launches =
launchRepository.findByFilter(ProjectFilter.of(filter, project.getId()), pageable);
@@ -408,4 +408,4 @@ private void fillWithAdditionalParams(Map<String, Object> params, Launch launch,
params.put(LaunchReportConstants.TEST_ITEMS, dataProvider.getTestItemsOfLaunch(launch));
}

}
}
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@

@Primary
@Service
@ConditionalOnProperty(prefix = "rp.elasticsearch", name = "host")
@ConditionalOnProperty(prefix = "rp.searchengine", name = "host")
public class ElasticLogService implements LogService {

private final AmqpTemplate amqpTemplate;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.ta.reportportal.core.organization;

import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.model.OrganizationResource;
import java.util.List;

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck> reported by reviewdog 🐶
Summary javadoc is missing.

* @author Andrei Piankouski
*/
public interface GetOrganizationHandler {

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck> reported by reviewdog 🐶
First sentence of Javadoc is missing an ending period.

* Get Organization resource information
*
* @param organizationId Organization id
* @param user User
* @return {@link OrganizationResource}
*/
OrganizationResource getResource(Long organizationId, ReportPortalUser user);

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck> reported by reviewdog 🐶
First sentence of Javadoc is missing an ending period.

* Get List of all Organizations
*
* @return The {@link List} of the {@link OrganizationResource}
*/
List<OrganizationResource> getAllOrganization();
}
Loading