Search in sources :

Example 26 with SUser

use of jetbrains.buildServer.users.SUser 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 27 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class UserRequest method addRoleToUserSimple.

@PUT
@Path("/{userLocator}/roles/{roleId}/{scope}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a role with the specific scope to the matching user.", nickname = "addRoleToUserAtScope")
public RoleAssignment addRoleToUserSimple(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @PathParam("roleId") String roleId, @PathParam("scope") String scopeValue) {
    SUser user = myUserFinder.getItem(userLocator, true);
    user.addRole(RoleAssignment.getScope(scopeValue, myBeanContext.getServiceLocator()), RoleAssignment.getRoleById(roleId, myBeanContext.getServiceLocator()));
    return new RoleAssignment(DataProvider.getUserRoleEntry(user, roleId, scopeValue, myBeanContext), user, myBeanContext);
}
Also used : SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class UserRequest method addRoleToUser.

@POST
@Path("/{userLocator}/roles")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a role to the matching user.", nickname = "addRoleToUser")
public RoleAssignment addRoleToUser(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, RoleAssignment roleAssignment) {
    SUser user = myUserFinder.getItem(userLocator, true);
    user.addRole(RoleAssignment.getScope(roleAssignment.scope, myBeanContext.getServiceLocator()), RoleAssignment.getRoleById(roleAssignment.roleId, myBeanContext.getServiceLocator()));
    return new RoleAssignment(DataProvider.getUserRoleEntry(user, roleAssignment.roleId, roleAssignment.scope, myBeanContext), user, myBeanContext);
}
Also used : SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 29 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class UserRequest method putUserProperty.

@PUT
@Path("/{userLocator}/properties/{name}")
@Consumes("text/plain")
@Produces("text/plain")
@ApiOperation(value = "Update a property of the matching user.", nickname = "setUserProperty")
public String putUserProperty(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @PathParam("name") String name, String newValue) {
    SUser user = myUserFinder.getItem(userLocator, true);
    if (StringUtil.isEmpty(name)) {
        throw new BadRequestException("Property name cannot be empty.");
    }
    user.setUserProperty(new SimplePropertyKey(name), newValue);
    return BuildTypeUtil.getParameter(name, User.getProperties(myUserFinder.getItem(userLocator, true)), false, true, myBeanContext.getServiceLocator());
}
Also used : SimplePropertyKey(jetbrains.buildServer.users.SimplePropertyKey) SUser(jetbrains.buildServer.users.SUser) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 30 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class UserRequest method getTokens.

@GET
@Path("/{userLocator}/tokens")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get all authentication tokens of the matching user.", nickname = "getUserTokens")
public Tokens getTokens(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @QueryParam("fields") String fields) {
    if (TeamCityProperties.getBooleanOrTrue(UserFinder.REST_CHECK_ADDITIONAL_PERMISSIONS_ON_USERS_AND_GROUPS)) {
        myUserFinder.checkViewAllUsersPermission();
    }
    final TokenAuthenticationModel tokenAuthenticationModel = myBeanContext.getSingletonService(TokenAuthenticationModel.class);
    SUser user = myUserFinder.getItem(userLocator, true);
    return new Tokens(tokenAuthenticationModel.getUserTokens(user.getId()), new Fields(fields), myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SUser (jetbrains.buildServer.users.SUser)125 Test (org.testng.annotations.Test)70 ApiOperation (io.swagger.annotations.ApiOperation)35 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)35 Build (jetbrains.buildServer.server.rest.model.build.Build)20 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)18 NotNull (org.jetbrains.annotations.NotNull)18 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)15 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)13 Fields (jetbrains.buildServer.server.rest.model.Fields)12 SUserGroup (jetbrains.buildServer.groups.SUserGroup)11 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)10 ServiceLocator (jetbrains.buildServer.ServiceLocator)9 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)9 Nullable (org.jetbrains.annotations.Nullable)9 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)8 SecurityContextImpl (jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl)8 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)7