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);
}
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() + "))");
}
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);
}
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);
}
}
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));
}
Aggregations