use of jetbrains.buildServer.serverSide.SProject in project teamcity-git by JetBrains.
the class GitHubPasswordAuthHealthPage method isAvailable.
@Override
public boolean isAvailable(@NotNull HttpServletRequest request) {
if (!super.isAvailable(request))
return false;
final SVcsRoot vcsRoot = getRootFromRequest(request);
if (vcsRoot == null)
return false;
final SProject project = vcsRoot.getProject();
return SessionUser.getUser(request).isPermissionGrantedForProject(project.getProjectId(), Permission.EDIT_PROJECT) && // check vcs root still exists
project.getOwnVcsRoots().contains(vcsRoot);
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-git by JetBrains.
the class GitUrlSupportTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
ServerPaths paths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
PluginConfig config = new PluginConfigBuilder(paths).build();
myMirrorManager = new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
myProjectMock = mock(SProject.class);
final Mock pmMock = mock(ProjectManager.class);
final SProject project = (SProject) myProjectMock.proxy();
pmMock.stubs().method("findProjectById").will(returnValue(project));
ProjectManager pm = (ProjectManager) pmMock.proxy();
final Mock sshMock = mock(ServerSshKeyManager.class);
sshMock.stubs().method("getKeys").with(eq(project)).will(returnValue(myTestKeys));
ServerSshKeyManager ssh = (ServerSshKeyManager) sshMock.proxy();
Mock epMock = mock(ExtensionsProvider.class);
epMock.stubs().method("getExtensions").with(eq(ServerSshKeyManager.class)).will(returnValue(Collections.singleton(ssh)));
myGitVcsSupport = gitSupport().withServerPaths(paths).withTestConnectionSupport(vcsRoot -> {
if (myTestConnectionMocked != null && myTestConnectionMocked)
return null;
return myGitVcsSupport.testConnection(vcsRoot);
}).build();
myUrlSupport = new GitUrlSupport(myGitVcsSupport) {
@NotNull
@Override
protected VcsRoot createDummyRoot(@NotNull final Map<String, String> props, @Nullable final SProject curProject) {
return new VcsRootImpl(-1, Constants.VCS_NAME, props);
}
};
myUrlSupport.setProjectManager(pm);
myUrlSupport.setExtensionsProvider((ExtensionsProvider) epMock.proxy());
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class Investigation method getFromPostedAndApply.
@NotNull
public List<InvestigationWrapper> getFromPostedAndApply(@NotNull final ServiceLocator serviceLocator, final boolean allowMultipleResult) {
checkIsValid();
if (target == null) {
throw new BadRequestException("Invalid 'investigation' entity: 'target' should be specified");
}
ProblemTarget.ProblemTargetData targetData;
try {
targetData = target.getFromPosted(serviceLocator);
} catch (BadRequestException e) {
throw new BadRequestException("Invalid 'investigation' entity: " + e.getMessage());
}
ResponsibilityEntry entry = new ResponsibilityEntryEx(TypedFinderBuilder.getEnumValue(state, ResponsibilityEntry.State.class), assignee.getFromPosted(serviceLocator.getSingletonService(UserFinder.class)), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser(), new Date(), assignment == null || assignment.getTextFromPosted() == null ? "" : assignment.getTextFromPosted(), resolution.getFromPostedForInvestigation(serviceLocator));
ResponsibilityFacadeEx responsibilityFacade = serviceLocator.getSingletonService(ResponsibilityFacadeEx.class);
InvestigationFinder investigationFinder = serviceLocator.findSingletonService(InvestigationFinder.class);
assert investigationFinder != null;
List<InvestigationWrapper> resultEntries = new ArrayList<>(1);
if (targetData.isAnyProblem()) {
List<BuildType> buildTypesFromPosted = scope.getBuildTypesFromPosted(serviceLocator);
if (!allowMultipleResult && buildTypesFromPosted.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'scope' entity: for this request only single buildType is supported within 'buildTypes' entity");
}
for (BuildType buildType : buildTypesFromPosted) {
responsibilityFacade.setBuildTypeResponsibility(buildType, entry);
resultEntries.add(investigationFinder.getItem(InvestigationFinder.getLocator((SBuildType) buildType)));
}
} else {
if (scope.buildTypes != null) {
throw new BadRequestException("Invalid 'investigation' entity: Invalid 'scope' entity: 'buildTypes' should not be specified for not buildType-level investigation");
}
SProject project = scope.getProjectFromPosted(serviceLocator);
List<STest> tests = targetData.getTests();
if (!tests.isEmpty()) {
if (!allowMultipleResult && tests.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single test is supported within 'tests' entity");
}
responsibilityFacade.setTestNameResponsibility(tests.stream().map(sTest -> sTest.getName()).distinct().collect(Collectors.toList()), project.getProjectId(), entry);
tests.stream().map(test -> // only one item should be found in the project
investigationFinder.getItem(InvestigationFinder.getLocatorForTest(test.getTestNameId(), project))).distinct().forEachOrdered(resultEntries::add);
}
List<Long> problems = targetData.getProblemIds();
if (!problems.isEmpty()) {
if (!allowMultipleResult && problems.size() > 1) {
throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single problem is supported within 'problems' entity");
}
responsibilityFacade.setBuildProblemResponsibility(// seems like only id is used inside
problems.stream().distinct().map(problemId -> ProblemWrapper.getBuildProblemInfo(problemId.intValue(), project.getProjectId())).collect(Collectors.toList()), project.getProjectId(), entry);
problems.stream().distinct().map(problemId -> // only one item should be found in the project
investigationFinder.getItem(InvestigationFinder.getLocatorForProblem(problemId.intValue(), project))).forEachOrdered(resultEntries::add);
}
}
if (!allowMultipleResult && resultEntries.size() != 1) {
throw new BadRequestException("Invalid 'investigation' entity: Invalid 'target' entity: found " + resultEntries.size() + " result entities, while exactly one is required");
}
return resultEntries;
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class ProjectFinderTest method testUserSelectedDimension.
@Test
public void testUserSelectedDimension() throws Exception {
myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
ProjectEx root = myProjectManager.getRootProject();
final SProject project10 = createProject("p10", "project 10");
final SProject project20 = createProject("p20", "project 20");
final SProject project10_10 = project10.createProject("p10_10", "p10 child1");
final SProject project10_20 = project10.createProject("p10_20", "xxx");
final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
final SProject project10_10_20 = project10_10.createProject("p10_10_20", "p10_10 child2");
final SProject project10_10_30 = project10_10.createProject("p10_10_30", "p10_10 child3");
final SProject project30 = createProject(project10.getProjectId(), "project 30");
final SProject project40 = createProject("p40", "project 40");
final SUser user2 = createUser("user2");
user2.addRole(RoleScope.projectScope(project10.getProjectId()), getProjectViewerRole());
// default sorting is hierarchy-based + name-based within the same level
check("selectedByUser:(username:user2)", project10, project10_10, project10_10_20, project10_10_30, project10_10_10, project10_20);
check("selectedByUser:(user:(username:user2),mode:selected_and_unknown)", project10, project10_10, project10_10_20, project10_10_30, project10_10_10, project10_20);
check("selectedByUser:(user:(username:user2),mode:all_with_order)", root, project10, project10_10, project10_10_20, project10_10_30, project10_10_10, project10_20);
check("selectedByUser:(user:(username:user2),mode:selected)");
final SUser user1 = createUser("user1");
user1.addRole(RoleScope.projectScope(project10.getProjectId()), getProjectViewerRole());
user1.addRole(RoleScope.projectScope(project20.getProjectId()), getProjectViewerRole());
user1.addRole(RoleScope.projectScope(project30.getProjectId()), getProjectViewerRole());
user1.setVisibleProjects(Arrays.asList(project10.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
user1.setProjectsOrder(Arrays.asList(project10.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
check("selectedByUser:(username:user1)", project10, project10_10_20, project10_10_10, project30);
check("selectedByUser:(user:(username:user1))", project10, project10_10_20, project10_10_10, project30);
check("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", project10, project10_10_20, project10_10_10, project30);
check("selectedByUser:(user:(username:user1),mode:all_with_order)", root, project10, project10_10, project10_10_20, project10_10_10, project10_10_30, project10_20, project30, project20);
check("selectedByUser:(user:(username:user1),mode:selected)", project10, project10_10_20, project10_10_10, project30);
check("selectedByUser:(username:user1),project:(id:_Root)", project10, project30);
check("selectedByUser:(user:(username:user1),mode:selected_and_unknown),project:(id:_Root)", project10, project30);
check("selectedByUser:(user:(username:user1),mode:all_with_order),project:(id:_Root)", project10, project30, project20);
check("selectedByUser:(user:(username:user1),mode:selected),project:(id:_Root)", project10, project30);
check("selectedByUser:(username:user1),project:(id:p10)");
check("selectedByUser:(user:(username:user1),mode:selected_and_unknown),project:(id:p10)");
check("selectedByUser:(user:(username:user1),mode:all_with_order),project:(id:p10)", project10_10, project10_20);
check("selectedByUser:(user:(username:user1),mode:selected),project:(id:p10)");
user1.setVisibleProjects(Arrays.asList(project30.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId()));
user1.setProjectsOrder(Arrays.asList(project30.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId()));
check("selectedByUser:(username:user1)", project30, project10_10_20, project10_10_10);
check("selectedByUser:(username:user1),project:(id:_Root)", project30);
checkExceptionOnItemsSearch(LocatorProcessException.class, "selectedByUser:(username:user2,mode:selected)");
checkExceptionOnItemsSearch(BadRequestException.class, "selectedByUser:(user:(username:user2),mode:aaa)");
checkExceptionOnItemsSearch(LocatorProcessException.class, "selectedByUser:(user:(username:user2),mode:aaa,ccc:ddd)");
checkExceptionOnItemsSearch(LocatorProcessException.class, "selectedByUser:(user:(username:user2,aaa:bbb))");
// add checks after ProjectEx.setOwnProjectsOrder / setOwnBuildTypesOrder
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class ProjectFinderTest method testProjectBean.
@Test
public void testProjectBean() throws Exception {
final SProject project10 = createProject("p1", "project 1");
final SProject project20 = createProject("p2", "project 2");
final SProject project10_10 = project10.createProject("p10_10", "p1_child1");
final SProject project10_20 = project10.createProject("p10_20", "xxx");
final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
final SProject project30 = createProject(project10.getProjectId(), "p3");
Project project = new Project(project10, new Fields("projects($long)"), getBeanContext(myServer));
assertNotNull(project.projects.projects);
checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {
public String createFrom(@NotNull final Project source) {
return source.id;
}
}), project10_10.getExternalId(), project10_20.getExternalId());
project = new Project(project10, new Fields("projects($long,$locator(name:xxx))"), getBeanContext(myServer));
assertNotNull(project.projects.projects);
checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {
public String createFrom(@NotNull final Project source) {
return source.id;
}
}), project10_20.getExternalId());
project = new Project(project10, new Fields("projects($long,$locator(project:$any,affectedProject:(" + project10.getExternalId() + ")))"), getBeanContext(myServer));
assertNotNull(project.projects.projects);
checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {
public String createFrom(@NotNull final Project source) {
return source.id;
}
}), project10_10.getExternalId(), project10_20.getExternalId(), project10_10_10.getExternalId());
ProjectFeatureDescriptorFactory featureDescriptorFactory = myFixture.findSingletonService(ProjectFeatureDescriptorFactory.class);
assert featureDescriptorFactory != null;
project10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId10", "type10", asMap("a", "b", "c", "d"), project10.getProjectId()));
project10_10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId20", "type20", asMap("a", "b", "c", "d"), project10_10.getProjectId()));
project = new Project(project10_10, new Fields("$long"), getBeanContext(myServer));
assertEquals(project.id, project10_10.getExternalId());
assertNotNull(project.projectFeatures);
assertEquals(Integer.valueOf(1), project.projectFeatures.count);
List<PropEntityProjectFeature> propEntities = project.projectFeatures.propEntities;
assertEquals(1, propEntities.size());
PropEntityProjectFeature feature = propEntities.get(0);
assertEquals("uniqueId20", feature.id);
assertEquals("type20", feature.type);
assertEquals(Integer.valueOf(2), feature.properties.count);
assertEquals("a", feature.properties.properties.get(0).name);
assertEquals("b", feature.properties.properties.get(0).value);
assertEquals("c", feature.properties.properties.get(1).name);
assertEquals("d", feature.properties.properties.get(1).value);
}
Aggregations