Search in sources :

Example 6 with Group

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);
    }
}
Also used : Group(org.gitlab4j.api.models.Group) GroupApi(org.gitlab4j.api.GroupApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) GitMember(de.catma.repository.git.GitMember) Member(org.gitlab4j.api.models.Member)

Example 7 with Group

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);
    }
}
Also used : NotesApi(org.gitlab4j.api.NotesApi) JsonObject(com.google.gson.JsonObject) Reply(de.catma.document.comment.Reply) AccessLevel(org.gitlab4j.api.models.AccessLevel) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) Author(org.gitlab4j.api.models.Author) IssuesApi(org.gitlab4j.api.IssuesApi) ChangeUserAttributeEvent(de.catma.ui.events.ChangeUserAttributeEvent) Map(java.util.Map) Group(org.gitlab4j.api.models.Group) IssueState(org.gitlab4j.api.Constants.IssueState) GroupApi(org.gitlab4j.api.GroupApi) Visibility(org.gitlab4j.api.models.Visibility) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) IGitUserInformation(de.catma.repository.git.interfaces.IGitUserInformation) GitMember(de.catma.repository.git.GitMember) Pager(org.gitlab4j.api.Pager) GitlabUtils(de.catma.repository.git.GitlabUtils) Set(java.util.Set) Logger(java.util.logging.Logger) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) List(java.util.List) ProjectApi(org.gitlab4j.api.ProjectApi) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) Status(org.gitlab4j.api.models.ImportStatus.Status) CacheBuilder(com.google.common.cache.CacheBuilder) GitLabApi(org.gitlab4j.api.GitLabApi) RBACPermission(de.catma.rbac.RBACPermission) Permissions(org.gitlab4j.api.models.Permissions) GroupFilter(org.gitlab4j.api.models.GroupFilter) Namespace(org.gitlab4j.api.models.Namespace) HashMap(java.util.HashMap) RBACRole(de.catma.rbac.RBACRole) JsonParser(com.google.gson.JsonParser) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EventBus(com.google.common.eventbus.EventBus) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) ForkStatus(de.catma.project.ForkStatus) GitProjectManager(de.catma.repository.git.GitProjectManager) Note(org.gitlab4j.api.models.Note) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) Issue(org.gitlab4j.api.models.Issue) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) Maps(com.google.common.collect.Maps) IssueFilter(org.gitlab4j.api.models.IssueFilter) TimeUnit(java.util.concurrent.TimeUnit) Member(org.gitlab4j.api.models.Member) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) BackgroundService(de.catma.backgroundservice.BackgroundService) GitUser(de.catma.repository.git.GitUser) Group(org.gitlab4j.api.models.Group) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Example 8 with Group

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);
    }
}
Also used : Group(org.gitlab4j.api.models.Group) Project(org.gitlab4j.api.models.Project) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) GitMember(de.catma.repository.git.GitMember) GitMember(de.catma.repository.git.GitMember) Member(org.gitlab4j.api.models.Member)

Example 9 with Group

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());
}
Also used : Group(org.gitlab4j.api.models.Group) Project(org.gitlab4j.api.models.Project) IRemoteGitServerManager(de.catma.repository.git.interfaces.IRemoteGitServerManager) Test(org.junit.Test)

Example 10 with Group

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());
}
Also used : Group(org.gitlab4j.api.models.Group) Test(org.junit.Test)

Aggregations

Group (org.gitlab4j.api.models.Group)15 GitLabApiException (org.gitlab4j.api.GitLabApiException)13 IOException (java.io.IOException)11 Project (org.gitlab4j.api.models.Project)7 GitMember (de.catma.repository.git.GitMember)6 GroupApi (org.gitlab4j.api.GroupApi)6 Member (org.gitlab4j.api.models.Member)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 CreateRepositoryResponse (de.catma.repository.git.CreateRepositoryResponse)4 Cache (com.google.common.cache.Cache)3 CacheBuilder (com.google.common.cache.CacheBuilder)3 Maps (com.google.common.collect.Maps)3 EventBus (com.google.common.eventbus.EventBus)3 Subscribe (com.google.common.eventbus.Subscribe)3 JsonObject (com.google.gson.JsonObject)3 JsonParser (com.google.gson.JsonParser)3 BackgroundService (de.catma.backgroundservice.BackgroundService)3 Comment (de.catma.document.comment.Comment)3