use of jetbrains.buildServer.groups.SUserGroup 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.groups.SUserGroup in project teamcity-rest by JetBrains.
the class UserRequestTest method testUserEnityExposure.
@Test
void testUserEnityExposure() throws Throwable {
myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
final SUser user1 = createUser("user1");
final SUser user2 = createUser("user2");
// filling all user fields
user1.updateUserAccount("user1", "Display Name1", "email1@domain.com");
user2.updateUserAccount("user2", "Display Name2", "email2@domain.com");
SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
group1.addUser(user1);
group1.addUser(user2);
user1.addRole(RoleScope.globalScope(), getProjectViewerRole());
user2.addRole(RoleScope.globalScope(), getProjectViewerRole());
user1.setLastLoginTimestamp(new Date());
user2.setLastLoginTimestamp(new Date());
user1.setPassword("secret");
user2.setPassword("secret");
myFixture.getUserAvatarsManager().saveAvatar(user1, new BufferedImage(1, 1, 1));
myFixture.getUserAvatarsManager().saveAvatar(user2, new BufferedImage(1, 1, 1));
enable2FA(user1);
enable2FA(user2);
SecurityContextImpl securityContext = myFixture.getSecurityContext();
user2.addRole(RoleScope.globalScope(), getProjectAdminRole());
SFinishedBuild build10 = build().in(myBuildType).by(user1).finish();
SFinishedBuild build20 = build().in(myBuildType).by(user2).finish();
BuildRequest buildRequest = new BuildRequest();
buildRequest.initForTests(BaseFinderTest.getBeanContext(myFixture));
// if changed, the checks below should be changed
assertEquals(15, getSubEntitiesNames(User.class).size());
final String fields = "triggered(user($long,hasPassword))";
{
Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
// not included in response
assertNull(user.getPassword());
// submit-only
assertNull(user.getLocator());
// obsolete
assertNull(user.getRealm());
}
{
Build build = buildRequest.serveBuild("id:" + build20.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
// not included in response
assertNull(user.getPassword());
// submit-only
assertNull(user.getLocator());
// obsolete
assertNull(user.getRealm());
}
securityContext.runAs(user1, () -> {
Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
assertNull(user.getPassword());
});
securityContext.runAs(user2, () -> {
Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
assertNull(user.getPassword());
});
securityContext.runAs(user1, () -> {
Build build = buildRequest.serveBuild("id:" + build20.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNull(user.getEmail());
assertNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNull(user.getProperties());
assertNull(user.getRoles());
assertNull(user.getGroups());
assertNull(user.getHasPassword());
assertNull(user.getPassword());
assertNotNull(user.getAvatars());
assertNull(user.getEnabled2FA());
});
}
use of jetbrains.buildServer.groups.SUserGroup in project teamcity-rest by JetBrains.
the class UserRequest method removeGroup.
@DELETE
@Path("/{userLocator}/groups/{groupLocator}")
@ApiOperation(value = "Remove the matching user from the specific group.", nickname = "removeUserFromGroup")
public void removeGroup(@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");
}
group.removeUser(user);
}
use of jetbrains.buildServer.groups.SUserGroup 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.groups.SUserGroup 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