use of jetbrains.buildServer.server.rest.model.group.Group in project teamcity-rest by JetBrains.
the class GroupRequestTest method testUsers.
@Test
void testUsers() {
SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
final SUser user1 = createUser("user1");
final SUser user2 = createUser("user2");
group1.addUser(user1);
group1.addUser(user2);
SUserGroup group2 = myFixture.createUserGroup("key2", "name2", "description");
final SUser user3 = createUser("user3");
group2.addUser(user3);
{
Group result = myRequest.serveGroup("key:key1", "$long,users($long)");
assertNotNull(result.users);
assertNotNull(result.users.users);
assertEquals(2, result.users.users.size());
assertEquals(Long.valueOf(user1.getId()), result.users.users.get(0).getId());
assertEquals(Long.valueOf(user2.getId()), result.users.users.get(1).getId());
}
}
use of jetbrains.buildServer.server.rest.model.group.Group in project teamcity-rest by JetBrains.
the class UserRequest method addGroupToUser.
@POST
@Path("/{userLocator}/groups")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a user matching the locator to the group.", nickname = "addUserToGroup", hidden = true)
public Group addGroupToUser(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, Group group, @QueryParam("fields") String fields) {
SUser user = myUserFinder.getItem(userLocator, true);
SUserGroup userGroup = group.getFromPosted(myBeanContext.getServiceLocator());
userGroup.addUser(user);
return new Group(userGroup, new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.server.rest.model.group.Group in project teamcity-rest by JetBrains.
the class UserRequest method getGroup.
@GET
@Path("/{userLocator}/groups/{groupLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get a user group of the matching user.", nickname = "getUserGroup")
public Group getGroup(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @PathParam("groupLocator") String groupLocator, @QueryParam("fields") String fields) {
if (TeamCityProperties.getBooleanOrTrue(UserFinder.REST_CHECK_ADDITIONAL_PERMISSIONS_ON_USERS_AND_GROUPS)) {
myUserFinder.checkViewAllUsersPermission();
}
SUser user = myUserFinder.getItem(userLocator, true);
SUserGroup group = myBeanContext.getSingletonService(UserGroupFinder.class).getGroup(groupLocator);
if (!user.getUserGroups().contains(group)) {
throw new NotFoundException("User does not belong to the group");
}
return new Group(group, new Fields(fields), myBeanContext);
}
Aggregations