use of org.gitlab4j.api.models.Group in project catma by forTEXT.
the class GitlabManagerRestricted method leaveGroup.
@Override
public void leaveGroup(String path) throws IOException {
GroupApi groupApi = restrictedGitLabApi.getGroupApi();
try {
Group group = groupApi.getGroup(path);
Member member = groupApi.getMember(group.getId(), user.getUserId());
if (member != null && member.getAccessLevel().value >= AccessLevel.GUEST.value && member.getAccessLevel().value < AccessLevel.OWNER.value) {
groupApi.removeMember(group.getId(), user.getUserId());
}
} catch (GitLabApiException ge) {
throw new IOException("Couldn't leave group", ge);
}
}
use of org.gitlab4j.api.models.Group in project catma by forTEXT.
the class GitlabManagerRestricted method getRolesPerResource.
public Map<String, RBACRole> getRolesPerResource(String projectId) throws IOException {
try {
Group group = restrictedGitLabApi.getGroupApi().getGroup(projectId);
Map<String, AccessLevel> permMap = getResourcePermissions(group.getId());
return permMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> RBACRole.forValue(e.getValue().value)));
} catch (GitLabApiException e) {
throw new IOException("Permission retrieval failed!", e);
}
}
use of org.gitlab4j.api.models.Group in project catma by forTEXT.
the class GitlabManagerCommon method assignDefaultAccessToRootProject.
private RBACSubject assignDefaultAccessToRootProject(RBACSubject subject, Integer groupId) throws IOException {
try {
Group group = getGitLabApi().getGroupApi().getGroup(groupId);
Project rootProject = getGitLabApi().getProjectApi().getProject(group.getName(), GitProjectManager.getProjectRootRepositoryName(group.getName()));
try {
Member member = getGitLabApi().getProjectApi().getMember(rootProject.getId(), subject.getUserId());
if (member.getAccessLevel().value < RBACRole.ASSISTANT.getAccessLevel()) {
return new GitMember(getGitLabApi().getProjectApi().updateMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
} else {
// In both cases we refuse to update the role, and simply do nothing.
return subject;
}
} catch (GitLabApiException e) {
return new GitMember(getGitLabApi().getProjectApi().addMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
}
} catch (GitLabApiException e) {
throw new IOException("error assigning default access to root project in group #" + groupId, e);
}
}
use of org.gitlab4j.api.models.Group in project catma by forTEXT.
the class GitLabServerManagerTest method createRepositoryInGroup.
@Test
public void createRepositoryInGroup() throws Exception {
String randomGroupNameAndPath = Randomizer.getGroupName();
String createdGroupPath = this.serverManager.createGroup(randomGroupNameAndPath, randomGroupNameAndPath, null);
this.groupsToDeleteOnTearDown.add(createdGroupPath);
assertNotNull(createdGroupPath);
Group group = this.serverManager.getAdminGitLabApi().getGroupApi().getGroup(createdGroupPath);
assertNotNull(group);
assertEquals(randomGroupNameAndPath, group.getName());
assertEquals(randomGroupNameAndPath, group.getPath());
// to assert that the user is the owner of the new group, get the groups for the user using
// the *user-specific* GitLabApi instance
List<Group> groups = this.serverManager.getUserGitLabApi().getGroupApi().getGroups();
assertEquals(1, groups.size());
assertEquals(group.getId(), groups.get(0).getId());
String randomRepoName = Randomizer.getRepoName();
IRemoteGitServerManager.CreateRepositoryResponse createRepositoryResponse = this.serverManager.createRepository(randomRepoName, null, createdGroupPath);
// we don't add the repositoryId to this.repositoriesToDeleteOnTearDown as deletion of the group will take care
// of that for us
assertNotNull(createRepositoryResponse);
assert createRepositoryResponse.repositoryId > 0;
Project project = this.serverManager.getAdminGitLabApi().getProjectApi().getProject(createRepositoryResponse.repositoryId);
assertNotNull(project);
assertEquals(randomRepoName, project.getName());
assertEquals(this.serverManager.getGitLabUser().getId(), project.getCreatorId());
List<Project> repositoriesInGroup = this.serverManager.getAdminGitLabApi().getGroupApi().getProjects(group.getId());
assertEquals(1, repositoriesInGroup.size());
assertEquals(createRepositoryResponse.repositoryId, (int) repositoriesInGroup.get(0).getId());
}
use of org.gitlab4j.api.models.Group in project catma by forTEXT.
the class GitLabServerManagerTest method createGroup.
@Test
public void createGroup() throws Exception {
String randomGroupNameAndPath = Randomizer.getGroupName();
String createdGroupPath = this.serverManager.createGroup(randomGroupNameAndPath, randomGroupNameAndPath, null);
this.groupsToDeleteOnTearDown.add(createdGroupPath);
assertNotNull(createdGroupPath);
Group group = this.serverManager.getAdminGitLabApi().getGroupApi().getGroup(createdGroupPath);
assertNotNull(group);
assertEquals(randomGroupNameAndPath, group.getName());
assertEquals(randomGroupNameAndPath, group.getPath());
// to assert that the user is the owner of the new group, get the groups for the user using
// the *user-specific* GitLabApi instance
List<Group> groups = this.serverManager.getUserGitLabApi().getGroupApi().getGroups();
assertEquals(1, groups.size());
assertEquals(group.getId(), groups.get(0).getId());
}
Aggregations