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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations