Search in sources :

Example 6 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class ProjectFinderTest method testUserPermissionDimension.

@Test
public void testUserPermissionDimension() throws Exception {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    ProjectEx root = myProjectManager.getRootProject();
    final SProject project10 = createProject("p10", "project 10");
    final SProject project10_10 = project10.createProject("p10_10", "p10 child1");
    final SProject project20 = createProject("p20", "project 20");
    final SProject project30 = createProject("p30", "project 30");
    RoleImpl role10 = new RoleImpl("role10", "custom role", new Permissions(Permission.TAG_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role10);
    RoleImpl role20 = new RoleImpl("role20", "custom role", new Permissions(Permission.CHANGE_SERVER_SETTINGS, Permission.LABEL_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role20);
    RoleImpl role30 = new RoleImpl("role30", "custom role", new Permissions(Permission.RUN_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role30);
    role30.addIncludedRole(role10);
    final SUser user10 = createUser("user10");
    final SUser user20 = createUser("user20");
    final SUser user30 = createUser("user30");
    final SUser user40 = createUser("user40");
    final SUserGroup group10 = myFixture.createUserGroup("group1", "group 1", "");
    final SUserGroup group20 = myFixture.createUserGroup("group1.1", "group 1.1", "");
    group10.addSubgroup(group20);
    group20.addUser(user20);
    group10.addRole(RoleScope.projectScope(project10.getProjectId()), role30);
    user10.addRole(RoleScope.projectScope(project10_10.getProjectId()), role10);
    user30.addRole(RoleScope.globalScope(), role30);
    user40.addRole(RoleScope.projectScope(project10_10.getProjectId()), role20);
    check(null, getRootProject(), project10, project10_10, project20, project30);
    check("userPermission:(user:(id:" + user10.getId() + "),permission:tag_build)", project10_10);
    checkExceptionOnItemsSearch(LocatorProcessException.class, "userPermission:(user:(id:" + user10.getId() + "))");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "userPermission:(permission:view_project)");
    check("userPermission:(user:(id:" + user20.getId() + "),permission:tag_build)", project10, project10_10);
    // project permission granted globally
    check("userPermission:(user:(id:" + user30.getId() + "),permission:TAG_BUILD)", getRootProject(), project10, project10_10, project20, project30);
    check("userPermission:(user:(id:" + user30.getId() + "),permission:change_server_settings)");
    // global permission
    check("userPermission:(user:(id:" + user40.getId() + "),permission:change_server_settings)", getRootProject(), project10, project10_10, project20, project30);
    check("userPermission:(user:(id:" + user40.getId() + "),permission:TAG_BUILD)");
    RoleImpl role11 = new RoleImpl("role11", "custom role", new Permissions(Permission.VIEW_PROJECT), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role11);
    user10.addRole(RoleScope.projectScope(project10_10.getProjectId()), role11);
    // view project is propagated on top
    check("userPermission:(user:(id:" + user10.getId() + "),permission:view_project)", getRootProject(), project10, project10_10);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) RoleImpl(jetbrains.buildServer.serverSide.impl.auth.RoleImpl) SUser(jetbrains.buildServer.users.SUser) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) SUserGroup(jetbrains.buildServer.groups.SUserGroup) SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 7 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class InvestigationFinderTest method createFailingBuild.

private void createFailingBuild() {
    final ProjectEx rootProject = myProjectManager.getRootProject();
    final ProjectEx project1 = rootProject.createProject("project1", "Project name");
    myBuildType = project1.createBuildType("extId", "bt name");
    startBuild(myBuildType);
    runTestsInRunningBuild(new String[] { "pass.test1" }, new String[] { FAIL_TEST2_NAME }, new String[0]);
    BuildServerCreator.doBuildProblem(getRunningBuild(), PROBLEM_IDENTITY);
    final SFinishedBuild build = finishBuild(true);
    myUser = createUser("user");
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild)

Example 8 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class Project method setFieldValueAndPersist.

public static void setFieldValueAndPersist(final SProject project, final String field, final String value, @NotNull final ServiceLocator serviceLocator) {
    if ("name".equals(field)) {
        if (StringUtil.isEmpty(value)) {
            throw new BadRequestException("Project name cannot be empty.");
        }
        project.setName(value);
        project.schedulePersisting("Project name changed");
        return;
    } else if ("id".equals(field)) {
        if (StringUtil.isEmpty(value)) {
            throw new BadRequestException("Project id cannot be empty.");
        }
        project.setExternalId(value);
        return;
    } else if ("description".equals(field)) {
        project.setDescription(value);
        project.schedulePersisting("Project description changed");
        return;
    } else if ("archived".equals(field)) {
        project.setArchived(Boolean.parseBoolean(value), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser());
        return;
    } else if ("readOnlyUI".equals(field) && TeamCityProperties.getBoolean("rest.projectRequest.allowSetReadOnlyUI")) {
        boolean editable = !Boolean.parseBoolean(value);
        ((ProjectEx) project).setEditable(editable);
        project.schedulePersisting("Project editing is " + (editable ? "enabled" : "disabled"));
        return;
    }
    throw new BadRequestException("Setting field '" + field + "' is not supported. Supported are: name, description, archived");
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 9 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class BuildTypeResolverTest method basicAncestorProjects.

public void basicAncestorProjects() throws Exception {
    ProjectEx p0 = myFixture.createProject("p0");
    ProjectEx p1 = myFixture.createProject("p1", p0);
    ProjectEx p2 = myFixture.createProject("p2", p1);
    ProjectEx p3 = myFixture.createProject("p3", p2);
    BuildTypeImpl realBuildType = myFixture.createBuildType(p3, "testBT", "test");
    ProjectsConnection ancestors = myResolver.ancestorProjects(new jetbrains.buildServer.server.graphql.model.buildType.BuildType(realBuildType), myDataFetchingEnvironment);
    // _Root, p0 .. p3
    assertEquals(5, ancestors.getCount());
    // Ancestors must be from closest to _Root
    assertExtensibleEdges(ancestors.getEdges().getData(), new Project(p3), new Project(p2), new Project(p1), new Project(p0), new Project(myFixture.getProjectManager().getRootProject()));
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Project(jetbrains.buildServer.server.graphql.model.Project) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) ProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.ProjectsConnection)

Example 10 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class ProjectRequest method setProjectsOrder.

/**
 * Put empty collection to remove custom ordering
 */
@PUT
@Path("/{projectLocator}/order/projects")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update custom ordering of subprojects of the matching project.", nickname = "setSubprojectsOrder")
public Projects setProjectsOrder(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, Projects projects, @QueryParam("field") String fields) {
    SProject project = myProjectFinder.getItem(projectLocator);
    LinkedHashSet<String> ids = new LinkedHashSet<>();
    if (projects.projects != null) {
        for (Project postedProject : projects.projects) {
            final String locatorFromPosted = postedProject.getLocatorFromPosted();
            List<SProject> items = myProjectFinder.getItems(project, locatorFromPosted).myEntries;
            if (items.isEmpty()) {
                throw new BadRequestException("No direct sub-projects in project found by locator '" + locatorFromPosted + "'");
            }
            for (SProject item : items) {
                ids.add(item.getProjectId());
            }
        }
    }
    ((ProjectEx) project).setOwnProjectsOrder(new ArrayList<>(ids));
    return new Projects(((ProjectEx) project).getOwnProjectsOrder(), null, new Fields(fields), myBeanContext);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Fields(jetbrains.buildServer.server.rest.model.Fields) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)52 Test (org.testng.annotations.Test)42 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)16 SUser (jetbrains.buildServer.users.SUser)10 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)8 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)7 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)7 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 TestName (jetbrains.buildServer.tests.TestName)5 ApiOperation (io.swagger.annotations.ApiOperation)4 SUserGroup (jetbrains.buildServer.groups.SUserGroup)4 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)4 Mutes (jetbrains.buildServer.server.rest.model.problem.Mutes)3 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)3 SProject (jetbrains.buildServer.serverSide.SProject)3 STest (jetbrains.buildServer.serverSide.STest)3 Permissions (jetbrains.buildServer.serverSide.auth.Permissions)3