Search in sources :

Example 16 with SUserGroup

use of jetbrains.buildServer.groups.SUserGroup in project teamcity-rest by JetBrains.

the class GroupRequest method addRoleSimple.

@POST
@Path("/{groupLocator}/roles/{roleId}/{scope}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a role with the specific scope to the matching user group.", nickname = "addRoleAtScopeToGroup")
public RoleAssignment addRoleSimple(@PathParam("groupLocator") String groupLocator, @PathParam("roleId") String roleId, @PathParam("scope") String scopeValue) {
    SUserGroup group = myUserGroupFinder.getGroup(groupLocator);
    group.addRole(RoleAssignment.getScope(scopeValue, myBeanContext.getServiceLocator()), RoleAssignment.getRoleById(roleId, myBeanContext.getServiceLocator()));
    return new RoleAssignment(DataProvider.getGroupRoleEntry(group, roleId, scopeValue, myBeanContext), group, myBeanContext);
}
Also used : RoleAssignment(jetbrains.buildServer.server.rest.model.user.RoleAssignment) SUserGroup(jetbrains.buildServer.groups.SUserGroup) ApiOperation(io.swagger.annotations.ApiOperation)

Example 17 with SUserGroup

use of jetbrains.buildServer.groups.SUserGroup in project teamcity-rest by JetBrains.

the class GroupRequest method setParentGroups.

@PUT
@Path("/{groupLocator}/parent-groups")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update parent groups of the matching user group.", nickname = "setGroupParentGroups")
public Groups setParentGroups(@PathParam("groupLocator") String groupLocator, Groups parents, @QueryParam("fields") String fields) {
    SUserGroup group = myUserGroupFinder.getGroup(groupLocator);
    if (parents == null) {
        throw new BadRequestException("No payload received while list of groups expected");
    }
    Group.setGroupParents(group, new LinkedHashSet<>(parents.getFromPosted(myBeanContext.getServiceLocator())), true, myBeanContext.getServiceLocator());
    return new Groups(group.getParentGroups(), new Fields(fields), myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) Groups(jetbrains.buildServer.server.rest.model.group.Groups) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SUserGroup(jetbrains.buildServer.groups.SUserGroup) ApiOperation(io.swagger.annotations.ApiOperation)

Example 18 with SUserGroup

use of jetbrains.buildServer.groups.SUserGroup in project teamcity-rest by JetBrains.

the class UserGroupFinder method getGroup.

@NotNull
public SUserGroup getGroup(final String groupLocator) {
    if (StringUtil.isEmpty(groupLocator)) {
        throw new BadRequestException("Empty group locator is not supported.");
    }
    final Locator locator = new Locator(groupLocator);
    if (locator.isSingleValue()) {
        // no dimensions found, assume it's group key
        SUserGroup group = myUserGroupManager.findUserGroupByKey(groupLocator);
        if (group == null) {
            throw new NotFoundException("No group can be found by key '" + groupLocator + "'.");
        }
        return group;
    }
    String groupKey = locator.getSingleDimensionValue(KEY);
    if (groupKey != null) {
        SUserGroup group = myUserGroupManager.findUserGroupByKey(groupKey);
        if (group == null) {
            throw new NotFoundException("No group can be found by key '" + groupKey + "'.");
        }
        return group;
    }
    String groupName = locator.getSingleDimensionValue(NAME);
    if (groupName != null) {
        SUserGroup group = myUserGroupManager.findUserGroupByName(groupName);
        if (group == null) {
            throw new NotFoundException("No group can be found by name '" + groupName + "'.");
        }
        return group;
    }
    throw new NotFoundException("Group locator '" + groupLocator + "' is not supported.");
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) SUserGroup(jetbrains.buildServer.groups.SUserGroup) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SUserGroup (jetbrains.buildServer.groups.SUserGroup)18 SUser (jetbrains.buildServer.users.SUser)11 ApiOperation (io.swagger.annotations.ApiOperation)9 Test (org.testng.annotations.Test)7 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)4 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)4 Fields (jetbrains.buildServer.server.rest.model.Fields)4 Group (jetbrains.buildServer.server.rest.model.group.Group)3 RoleAssignment (jetbrains.buildServer.server.rest.model.user.RoleAssignment)3 Permissions (jetbrains.buildServer.serverSide.auth.Permissions)3 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)3 RoleImpl (jetbrains.buildServer.serverSide.impl.auth.RoleImpl)3 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 RoleAssignments (jetbrains.buildServer.server.rest.model.user.RoleAssignments)2 StringUtil (com.intellij.openapi.util.text.StringUtil)1 BufferedImage (java.awt.image.BufferedImage)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1