use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class PermissionAssignmentFinderTest method testProjectPermissions.
@Test
public void testProjectPermissions() throws Exception {
Role roleProject = getTestRoles().createRole(Permission.VIEW_PROJECT, Permission.RUN_BUILD);
String projectId = myProject1.getProjectId();
myUser1.addRole(RoleScope.projectScope(projectId), roleProject);
checkUnordered(null, pa(Permission.CHANGE_OWN_PROFILE), pa(Permission.VIEW_PROJECT, getRootProject().getProjectId()), pa(Permission.RUN_BUILD, projectId), pa(Permission.VIEW_PROJECT, projectId), pa(Permission.RUN_BUILD, myProject11.getProjectId()), pa(Permission.VIEW_PROJECT, myProject11.getProjectId()));
checkUnordered("global:any", pa(Permission.CHANGE_OWN_PROFILE), pa(Permission.VIEW_PROJECT, getRootProject().getProjectId()), pa(Permission.RUN_BUILD, projectId), pa(Permission.VIEW_PROJECT, projectId), pa(Permission.RUN_BUILD, myProject11.getProjectId()), pa(Permission.VIEW_PROJECT, myProject11.getProjectId()));
checkUnordered("global:true", pa(Permission.CHANGE_OWN_PROFILE));
checkUnordered("global:false", pa(Permission.VIEW_PROJECT, getRootProject().getProjectId()), pa(Permission.RUN_BUILD, projectId), pa(Permission.VIEW_PROJECT, projectId), pa(Permission.RUN_BUILD, myProject11.getProjectId()), pa(Permission.VIEW_PROJECT, myProject11.getProjectId()));
checkUnordered("project:(id:" + myProject1.getExternalId() + ")", pa(Permission.RUN_BUILD, projectId), pa(Permission.VIEW_PROJECT, projectId));
checkUnordered("project:(id:" + getRootProject().getExternalId() + ")", pa(Permission.VIEW_PROJECT, getRootProject().getProjectId()));
checkUnordered("permission:" + "RUN_BUILD", pa(Permission.RUN_BUILD, projectId), pa(Permission.RUN_BUILD, myProject11.getProjectId()));
checkUnordered("permission:" + "run_build" + ",global:true");
checkUnordered("permission:" + "view_PrOjEcT", pa(Permission.VIEW_PROJECT, getRootProject().getProjectId()), pa(Permission.VIEW_PROJECT, projectId), pa(Permission.VIEW_PROJECT, myProject11.getProjectId()));
checkUnordered("permission:" + "view_project" + ",project:" + projectId, pa(Permission.VIEW_PROJECT, projectId));
ProjectEx project2 = createProject("prj2", "prj2");
Role role2 = getTestRoles().createRole(Permission.RUN_BUILD);
myUser1.addRole(RoleScope.projectScope(project2.getProjectId()), role2);
checkUnordered("permission:run_build,project:(item:(id:" + myProject1.getExternalId() + "),item:(id:" + project2.getExternalId() + "))", pa(Permission.RUN_BUILD, projectId), pa(Permission.RUN_BUILD, project2.getProjectId()));
checkUnordered("item:(permission:view_project,project:(id:" + myProject1.getExternalId() + ")),item:(permission:view_project,project:(id:" + project2.getExternalId() + "))", pa(Permission.VIEW_PROJECT, projectId));
checkUnordered("item:(permission:view_project,project:(id:" + project2.getExternalId() + ")),item:(permission:run_build,project:(id:" + project2.getExternalId() + "))", pa(Permission.RUN_BUILD, project2.getProjectId()));
checkUnordered("item:(permission:CHANGE_OWN_PROFILE),item:(permission:run_build,project:(id:" + myProject1.getExternalId() + "))", pa(Permission.CHANGE_OWN_PROFILE), pa(Permission.RUN_BUILD, projectId));
checkExceptionOnItemsSearch(BadRequestException.class, "permission:XXX");
checkExceptionOnItemsSearch(LocatorProcessException.class, "project:(id:XXX)");
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx 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.impl.ProjectEx in project teamcity-rest by JetBrains.
the class ChangeFinderTest method testVersionedSettings.
@Test
public void testVersionedSettings() {
ProjectEx project = getRootProject().createProject("project", "project");
project.persist();
final BuildTypeEx buildConf = project.createBuildType("buildConf1");
buildConf.persist();
MockVcsSupport vcs = new MockVcsSupport("vcs");
myFixture.getVcsManager().registerVcsSupport(vcs);
SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", buildConf);
VcsRootInstance root1 = buildConf.getVcsRootInstanceForParent(parentRoot1);
assert root1 != null;
SVcsRoot vsRoot = project.createVcsRoot(vcsSupport().withName("vcs1").dagBased(true).register().getName(), "Settings Root", map());
VcsRootInstance vsInstance = resolveInProject(vsRoot, project);
myFixture.getSingletonService(RepositoryStateManager.class).setRepositoryState(vsInstance, createRepositoryState(map("default", "vs10"), "default"));
VersionedSettingsConfig vsConfig = new VersionedSettingsConfig();
vsConfig.setVcsRootExternalId(vsRoot.getExternalId());
vsConfig.setEnabled(true);
vsConfig.setShowSettingsChanges(true);
vsConfig.setBuildSettingsMode(VersionedSettingsConfig.BuildSettingsMode.PREFER_VCS);
myFixture.writeVersionedSettingsConfig(project, vsConfig);
SVcsModification m20 = myFixture.addModification(modification().in(root1).by("user1").version("m20").parentVersions("m10"));
SVcsModification vs_m20 = myFixture.addModification(modification().in(vsInstance).version("vs20").parentVersions("vs10"), buildConf, RelationType.SETTINGS_AFFECT_BUILDS);
myFixture.getSingletonService(RepositoryStateManager.class).setRepositoryState(vsInstance, createRepositoryState(map("default", "vs20"), "default"));
// myFixture.getVcsModificationChecker().checkForModifications(buildConf.getVcsRootInstances(), OperationRequestor.UNKNOWN);
// myFixture.getVcsModificationChecker().checkForModifications(Collections.singleton(vsInstance), OperationRequestor.UNKNOWN);
check(null, vs_m20, m20);
String bt = "buildType:(" + buildConf.getExternalId() + ")";
check(bt, vs_m20, m20);
check(bt + ",versionedSettings:true", vs_m20);
check(bt + ",versionedSettings:false", m20);
check(bt + ",versionedSettings:any", vs_m20, m20);
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class UserFinderTest method testSearchByRoles.
@Test
public void testSearchByRoles() throws Throwable {
myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
final SUser user10 = createUser("user10");
final SUser user20 = createUser("user20");
final SUser user30 = createUser("user30");
final SUser user40 = createUser("user40");
final SUser user50 = createUser("user50");
final SUser user60 = createUser("user60");
final SUser user70 = createUser("user70");
final SUser user100 = createUser("user100");
final SUserGroup group10 = myFixture.createUserGroup("group1", "group 1", "");
final SUserGroup group20 = myFixture.createUserGroup("group1.1", "group 1.1", "");
group10.addSubgroup(group20);
group10.addUser(user60);
group20.addUser(user70);
ProjectEx prj1 = createProject("prj1");
ProjectEx prj1_1 = prj1.createProject("prj1_1", "prj1.1");
ProjectEx prj3 = createProject("prj3");
RoleImpl role10 = new RoleImpl("role10", "custom role", new Permissions(Permission.LABEL_BUILD), null);
myFixture.getRolesManager().addRole(role10);
RoleImpl role20 = new RoleImpl("role20", "custom role", new Permissions(Permission.PIN_UNPIN_BUILD), myFixture.getRolesManager());
role20.addIncludedRole(role10);
myFixture.getRolesManager().addRole(role20);
RoleImpl role30 = new RoleImpl("role30", "custom role", new Permissions(Permission.LABEL_BUILD, Permission.CANCEL_BUILD), myFixture.getRolesManager());
myFixture.getRolesManager().addRole(role30);
user10.addRole(RoleScope.globalScope(), getSysAdminRole());
user20.addRole(RoleScope.globalScope(), getProjectAdminRole());
user30.addRole(RoleScope.projectScope(prj1.getProjectId()), getProjectViewerRole());
user40.addRole(RoleScope.projectScope(prj1_1.getProjectId()), getProjectViewerRole());
user50.addRole(RoleScope.projectScope(prj3.getProjectId()), getProjectViewerRole());
user50.addRole(RoleScope.globalScope(), role30);
group10.addRole(RoleScope.projectScope(prj1.getProjectId()), role20);
group10.addRole(RoleScope.projectScope(getRootProject().getProjectId()), getTestRoles().getProjectViewerRole());
check(null, user10, user20, user30, user40, user50, user60, user70, user100);
check("role:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:" + getProjectAdminRole().getId() + "))", user20);
check("role:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10))", user60, user70);
check("role:(item:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10)),method:effective)", user60, user70);
check("role:(item:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10)))", user60, user70);
check("role:(item:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10)),method:byPermission)", user10, user20, user50, user60, user70);
check("role:(scope:global)", user10, user20, user50);
// todo: error locators
checkExceptionOnItemsSearch(LocatorProcessException.class, "role:(aaa)");
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class UserFinderTest method testSearchByPermissions.
@Test
public void testSearchByPermissions() throws Throwable {
myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
final SUser user10 = createUser("user10");
final SUser user20 = createUser("user20");
final SUser user30 = createUser("user30");
final SUser user40 = createUser("user40");
final SUser user50 = createUser("user50");
final SUser user60 = createUser("user60");
final SUser user70 = createUser("user70");
final SUser user100 = createUser("user100");
final SUserGroup group10 = myFixture.createUserGroup("group1", "group 1", "");
final SUserGroup group20 = myFixture.createUserGroup("group1.1", "group 1.1", "");
group10.addSubgroup(group20);
group20.addUser(user70);
ProjectEx prj1 = createProject("prj1");
ProjectEx prj1_1 = prj1.createProject("prj1_1", "prj1.1");
ProjectEx prj3 = createProject("prj3");
RoleImpl role10 = new RoleImpl("role10", "custom role", new Permissions(Permission.RUN_BUILD), null);
myFixture.getRolesManager().addRole(role10);
RoleImpl role20 = new RoleImpl("role20", "custom role", new Permissions(Permission.VIEW_PROJECT, Permission.CHANGE_SERVER_SETTINGS), myFixture.getRolesManager());
role20.addIncludedRole(role10);
myFixture.getRolesManager().addRole(role20);
RoleImpl role30 = new RoleImpl("role30", "custom role", new Permissions(Permission.LABEL_BUILD, Permission.CANCEL_BUILD), myFixture.getRolesManager());
myFixture.getRolesManager().addRole(role30);
user10.addRole(RoleScope.globalScope(), getSysAdminRole());
user30.addRole(RoleScope.projectScope(prj3.getProjectId()), role10);
group10.addRole(RoleScope.projectScope(prj1.getProjectId()), role20);
check(null, user10, user20, user30, user40, user50, user60, user70, user100);
check("permission:(permission:run_build,project:(id:" + prj1_1.getExternalId() + "))", user10, user70);
checkExceptionOnItemsSearch(LocatorProcessException.class, "permission:(permission:run_build,permission:label_build,project:(id:" + prj1_1.getExternalId() + "))");
checkExceptionOnItemsSearch(LocatorProcessException.class, "permission:(permission:run_build,project:(id:a),project:(id:b))");
assertContains(checkException(LocatorProcessException.class, () -> getFinder().getItems("permission:(project:(id:a))"), null).getMessage(), "Nothing found");
// global permission check
check("permission:(permission:run_build)", user10);
check("permission:(permission:run_build,project:(item:" + prj3.getExternalId() + "))", user10, user30);
check("permission:(permission:run_build,project:(item:" + prj1_1.getExternalId() + ",item:" + prj3.getExternalId() + "))", user10, user30, // permission in one of the projects
user70);
// permission in any project of the first 100
check("permission:(permission:run_build,project:(count:100))", user10, user30, user70);
}
Aggregations