Search in sources :

Example 1 with SUserGroup

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

the class UserFinderTest method testGroupLocator.

@Test
public void testGroupLocator() throws Throwable {
    SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
    final SUser user1 = createUser("user1");
    final SUser user2 = createUser("user2");
    final SUser user25 = createUser("user25");
    group1.addUser(user1);
    group1.addUser(user2);
    group1.addUser(user25);
    SUserGroup group2 = myFixture.createUserGroup("key2", "name2", "description");
    final SUser user3 = createUser("user3");
    group2.addUser(user3);
    group2.addUser(user25);
    check(null, user1, user2, user25, user3);
    check("group:(key:" + group1.getKey() + ")", user1, user2, user25);
    check("group:(key:" + group2.getKey() + ")", user3, user25);
    check("group:(key:" + getUserGroupManager().getAllUsersGroup().getKey() + ")", user1, user2, user25, user3);
    check("group:(key:" + group1.getKey() + "),username:user1", user1);
    checkExceptionOnItemSearch(NotFoundException.class, "group:(key:XXX)");
    checkExceptionOnItemsSearch(NotFoundException.class, "group:(key:XXX)");
    check("group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + ")", user25);
}
Also used : SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) Test(org.testng.annotations.Test)

Example 2 with SUserGroup

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

the class UserFinderTest method testLogicOps.

@Test
public void testLogicOps() throws Throwable {
    SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
    final SUser user1 = createUser("user1");
    final SUser user2 = createUser("user2");
    final SUser user3 = createUser("user3");
    final SUser user4 = createUser("user4");
    group1.addUser(user1);
    group1.addUser(user2);
    SUserGroup group2 = myFixture.createUserGroup("key2", "name2", "description");
    group2.addUser(user3);
    group2.addUser(user2);
    check(null, user1, user2, user3, user4);
    check("group:(key:" + group1.getKey() + ")", user1, user2);
    // todo: should actually return sorted
    check("group:(key:" + group2.getKey() + ")", user3, user2);
    check("group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + ")", user2);
    check("group:(key:" + group1.getKey() + "),and:(group:(key:" + group2.getKey() + "))", user2);
    check("and:(group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + "))", user2);
    check("or:(group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + "))", user1, user2, user3);
    check("not:(group:(key:" + group1.getKey() + "))", user3, user4);
    check("not:(or:(group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + ")))", user4);
    // Only single 'and' dimension is supported in locator
    checkExceptionOnItemsSearch(LocatorProcessException.class, "and:(group:(key:" + group1.getKey() + ")),and:group:(key:" + group2.getKey() + "))");
}
Also used : SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) Test(org.testng.annotations.Test)

Example 3 with SUserGroup

use of jetbrains.buildServer.groups.SUserGroup 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);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) RoleImpl(jetbrains.buildServer.serverSide.impl.auth.RoleImpl) SUser(jetbrains.buildServer.users.SUser) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) SUserGroup(jetbrains.buildServer.groups.SUserGroup) SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 4 with SUserGroup

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

the class Group method setGroupParents.

public static void setGroupParents(@NotNull final SUserGroup group, @NotNull final Set<SUserGroup> newParents, final boolean revertOnError, @NotNull final ServiceLocator serviceLocator) {
    // workaround for TW-52253
    serviceLocator.getSingletonService(PermissionChecker.class).getServerActionChecker().checkCanEditUserGroup(group);
    Set<SUserGroup> currentParents = group.getParentGroups().stream().map(userGroup -> (SUserGroup) userGroup).collect(Collectors.toSet());
    currentParents.stream().filter(userGroup -> !newParents.contains(userGroup)).forEach(userGroup -> userGroup.removeSubgroup(group));
    try {
        newParents.stream().filter(userGroup -> !currentParents.contains(userGroup)).forEach(userGroup -> userGroup.addSubgroup(group));
    } catch (CycleDetectedException e) {
        if (revertOnError)
            setGroupParents(group, currentParents, false, serviceLocator);
        throw new BadRequestException("Error encountered while trying to set new parent groups", e);
    } catch (AccessDeniedException e) {
        if (revertOnError)
            setGroupParents(group, currentParents, false, serviceLocator);
        throw e;
    } catch (Exception e) {
        if (revertOnError)
            setGroupParents(group, currentParents, false, serviceLocator);
        throw new OperationException("Error encountered while trying to set new parent groups", e);
    }
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) HashMap(java.util.HashMap) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) SUserGroup(jetbrains.buildServer.groups.SUserGroup) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) RoleAssignment(jetbrains.buildServer.server.rest.model.user.RoleAssignment) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) XmlType(javax.xml.bind.annotation.XmlType) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) Map(java.util.Map) UserGroupManager(jetbrains.buildServer.groups.UserGroupManager) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) RoleAssignments(jetbrains.buildServer.server.rest.model.user.RoleAssignments) Properties(jetbrains.buildServer.server.rest.model.Properties) ServiceLocator(jetbrains.buildServer.ServiceLocator) StringUtil(com.intellij.openapi.util.text.StringUtil) Set(java.util.Set) Users(jetbrains.buildServer.server.rest.model.user.Users) RoleEntry(jetbrains.buildServer.serverSide.auth.RoleEntry) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) Locator(jetbrains.buildServer.server.rest.data.Locator) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) GroupRequest(jetbrains.buildServer.server.rest.request.GroupRequest) UserFinder(jetbrains.buildServer.server.rest.data.UserFinder) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) CycleDetectedException(jetbrains.buildServer.groups.CycleDetectedException) PropertyKey(jetbrains.buildServer.users.PropertyKey) SUser(jetbrains.buildServer.users.SUser) XmlElement(javax.xml.bind.annotation.XmlElement) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) CycleDetectedException(jetbrains.buildServer.groups.CycleDetectedException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SUserGroup(jetbrains.buildServer.groups.SUserGroup) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) CycleDetectedException(jetbrains.buildServer.groups.CycleDetectedException) OperationException(jetbrains.buildServer.server.rest.errors.OperationException)

Example 5 with SUserGroup

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

the class GroupRequest method removeUserProperty.

@DELETE
@Path("/{groupLocator}/properties/{name}")
@ApiOperation(value = "Remove a property of the matching user group.", nickname = "removeGroupProperty")
public void removeUserProperty(@PathParam("groupLocator") String groupLocator, @PathParam("name") String name) {
    SUserGroup group = myUserGroupFinder.getGroup(groupLocator);
    if (StringUtil.isEmpty(name)) {
        throw new BadRequestException("Property name cannot be empty.");
    }
    group.deleteGroupProperty(new SimplePropertyKey(name));
}
Also used : SimplePropertyKey(jetbrains.buildServer.users.SimplePropertyKey) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SUserGroup(jetbrains.buildServer.groups.SUserGroup) ApiOperation(io.swagger.annotations.ApiOperation)

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