All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.epam.reportportal.extension.ProjectManagerCommand Maven / Gradle / Ivy

The newest version!
package com.epam.reportportal.extension;

import com.epam.reportportal.rules.commons.validation.BusinessRule;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.dao.ProjectRepository;
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.project.ProjectRole;
import com.epam.reportportal.rules.exception.ErrorType;

import static java.util.Optional.ofNullable;

/**
 * @author Ivan Budayeu
 */
public abstract class ProjectManagerCommand extends ProjectMemberCommand {

	protected ProjectManagerCommand(ProjectRepository projectRepository) {
		super(projectRepository);
	}

	@Override
	protected void validatePermissions(ReportPortalUser user, Project project) {
		ProjectRole projectRole = ofNullable(user.getProjectDetails()).flatMap(detailsMapping -> ofNullable(detailsMapping.get(project.getName())))
				.map(ReportPortalUser.ProjectDetails::getProjectRole)
				.orElseThrow(() -> new ReportPortalException(ErrorType.ACCESS_DENIED));

		BusinessRule.expect(projectRole, ProjectRole.PROJECT_MANAGER::sameOrLowerThan).verify(ErrorType.ACCESS_DENIED);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy