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
Show file tree
Hide file tree
Changes from 6 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
Expand Up @@ -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:08e1cad'
implementation 'com.github.reportportal:commons-rules:42d4dd5634'
implementation 'com.github.reportportal:commons-model:c800793'
implementation 'com.github.reportportal:commons-model:62f4803'
implementation 'com.github.reportportal:commons:07566b8e'
implementation 'com.github.reportportal:commons-fonts:d6e62dd'
implementation 'com.github.reportportal:plugin-api:0ccfed880c'
Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions project-properties.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/**',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand All @@ -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
Expand Up @@ -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
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:[email protected]">Andrei Varabyeu</a>
*/
Expand Down Expand Up @@ -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));
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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(),
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.impl;

import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.core.organization.GetOrganizationHandler;
import com.epam.ta.reportportal.dao.organization.OrganizationRepository;
import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.model.OrganizationResource;
import com.epam.ta.reportportal.ws.converter.converters.OrganizationConverter;
import com.epam.ta.reportportal.ws.model.ErrorType;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**

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
*/
@Service
public class GetOrganizationHandlerImpl implements GetOrganizationHandler {

private final OrganizationRepository organizationRepository;

@Autowired
public GetOrganizationHandlerImpl(OrganizationRepository organizationRepository) {
this.organizationRepository = organizationRepository;
}

@Override
public OrganizationResource getResource(Long organizationId, ReportPortalUser user) {
Organization organization = organizationRepository.findById(organizationId)
.orElseThrow(
() -> new ReportPortalException(ErrorType.ORGANIZATION_NOT_FOUND, organizationId));
return OrganizationConverter.TO_ORGANIZATION_RESOURCE.apply(organization);
}

@Override
public List<OrganizationResource> getAllOrganization() {
List<Organization> organizations = organizationRepository.findAll();
return organizations.stream().map(OrganizationConverter.TO_ORGANIZATION_RESOURCE).toList();
}

}
Loading
Loading