Search in sources :

Example 1 with Group

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());
    }
}
Also used : Group(jetbrains.buildServer.server.rest.model.group.Group) UserGroup(jetbrains.buildServer.groups.UserGroup) SUserGroup(jetbrains.buildServer.groups.SUserGroup) SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 2 with Group

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);
}
Also used : SUserGroup(jetbrains.buildServer.groups.SUserGroup) Group(jetbrains.buildServer.server.rest.model.group.Group) Fields(jetbrains.buildServer.server.rest.model.Fields) SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with Group

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);
}
Also used : SUserGroup(jetbrains.buildServer.groups.SUserGroup) Group(jetbrains.buildServer.server.rest.model.group.Group) Fields(jetbrains.buildServer.server.rest.model.Fields) SUser(jetbrains.buildServer.users.SUser) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) SUserGroup(jetbrains.buildServer.groups.SUserGroup) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SUserGroup (jetbrains.buildServer.groups.SUserGroup)3 Group (jetbrains.buildServer.server.rest.model.group.Group)3 SUser (jetbrains.buildServer.users.SUser)3 ApiOperation (io.swagger.annotations.ApiOperation)2 Fields (jetbrains.buildServer.server.rest.model.Fields)2 UserGroup (jetbrains.buildServer.groups.UserGroup)1 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 Test (org.testng.annotations.Test)1