com.epam.reportportal.extension.ProjectManagerCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin-api Show documentation
Show all versions of plugin-api Show documentation
EPAM Report portal. Plugin extension APIs
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);
}
}