use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.
the class BuildTypeUtil method checkCanUseBuildTypeAsDependency.
public static void checkCanUseBuildTypeAsDependency(final String buildTypeExternalId, final ServiceLocator serviceLocator) {
// see also TW-39209
if (!TeamCityProperties.getBooleanOrTrue("rest.dependency.checkPermissionsOnChange")) {
return;
}
final PermissionChecker permissionChecker = serviceLocator.getSingletonService(PermissionChecker.class);
if (permissionChecker.isPermissionGranted(Permission.VIEW_PROJECT, null)) {
return;
}
final SBuildType buildType = serviceLocator.getSingletonService(ProjectManager.class).findBuildTypeByExternalId(buildTypeExternalId);
if (buildType == null) {
if (TeamCityProperties.getBoolean("rest.dependency.allowMissingBuildTypeDependency")) {
return;
}
throw new BadRequestException("Cannot find build type with id '" + buildTypeExternalId + "'");
}
permissionChecker.checkProjectPermission(Permission.VIEW_PROJECT, buildType.getProjectId());
}
use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.
the class LicensingData method initLicensingPolicyDependantFields.
private void initLicensingPolicyDependantFields(@NotNull LicenseKeysManager licenseKeysManager, @NotNull Fields fields, @NotNull BeanContext beanContext) {
final LicensingPolicyEx licensingPolicy = licenseKeysManager.getLicensingPolicy();
final PermissionChecker permissionChecker = beanContext.getSingletonService(PermissionChecker.class);
licenseUseExceeded = ValueWithDefault.decideDefaultIgnoringAccessDenied(fields.isIncluded("licenseUseExceeded"), () -> {
permissionChecker.checkGlobalPermission(Permission.MANAGE_SERVER_LICENSES);
return licensingPolicy.isMaxNumberOfBuildTypesExceeded();
});
agentsLeft = ValueWithDefault.decideIncludeByDefault(myFields.isIncluded("agentsLeft"), () -> {
if (permissionChecker.hasGlobalPermission(Permission.MANAGE_SERVER_LICENSES) || permissionChecker.hasGlobalPermission(Permission.VIEW_AGENT_DETAILS))
return licensingPolicy.getAgentsLicensesLeft();
return null;
});
buildTypesLeft = ValueWithDefault.decideDefaultIgnoringAccessDenied(fields.isIncluded("buildTypesLeft"), () -> {
permissionChecker.checkGlobalPermission(Permission.MANAGE_SERVER_LICENSES);
int result = licensingPolicy.getBuildTypesLicensesLeft();
return result == -1 ? null : result;
});
}
use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.
the class ServerRequestTest method setUp.
@Override
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
BeanContext ctx = BaseFinderTest.getBeanContext(myFixture);
PermissionChecker checker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
myFixture.addService(checker);
myRequest = new ServerRequest();
myRequest.initForTests(ctx.getServiceLocator(), ctx.getApiUrlBuilder(), new BeanFactory(null), ctx, checker);
}
use of jetbrains.buildServer.server.rest.data.PermissionChecker in project teamcity-rest by JetBrains.
the class BaseResolverTest method setUp.
@Override
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
super.setUp();
myDataFetchingEnvironment = new MockDataFetchingEnvironment();
myFixture.addService(myProjectManager);
myPermissionChecker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
myFixture.addService(myPermissionChecker);
myProjectFinder = new ProjectFinder(myProjectManager, myPermissionChecker, myServer);
myFixture.addService(myProjectFinder);
}
Aggregations