Search in sources :

Example 1 with GitMember

use of de.catma.repository.git.GitMember in project catma by forTEXT.

the class GitlabManagerRestricted method getResourceMembers.

@Override
public Set<de.catma.user.Member> getResourceMembers(String projectId, String resourceId) throws IOException {
    try {
        Project project = restrictedGitLabApi.getProjectApi().getProject(projectId, resourceId);
        if (project != null) {
            List<GitMember> allMembers = new ProjectApi(restrictedGitLabApi).getAllMembers(project.getId()).stream().map(member -> new GitMember(member)).collect(Collectors.toList());
            Map<Integer, de.catma.user.Member> mergedList = new HashMap<>();
            for (de.catma.user.Member m : allMembers) {
                if (!mergedList.containsKey(m.getUserId()) || mergedList.get(m.getUserId()).getRole().getAccessLevel() < m.getRole().getAccessLevel()) {
                    mergedList.put(m.getUserId(), m);
                }
            }
            return mergedList.values().stream().collect(Collectors.toSet());
        } else {
            throw new IOException("resource unknown");
        }
    } catch (GitLabApiException e) {
        throw new IOException("resource unknown");
    }
}
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) HashMap(java.util.HashMap) ProjectApi(org.gitlab4j.api.ProjectApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) GitMember(de.catma.repository.git.GitMember) GitMember(de.catma.repository.git.GitMember) Member(org.gitlab4j.api.models.Member)

Example 2 with GitMember

use of de.catma.repository.git.GitMember 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)

Aggregations

GitMember (de.catma.repository.git.GitMember)2 IOException (java.io.IOException)2 GitLabApiException (org.gitlab4j.api.GitLabApiException)2 Group (org.gitlab4j.api.models.Group)2 Member (org.gitlab4j.api.models.Member)2 Project (org.gitlab4j.api.models.Project)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Maps (com.google.common.collect.Maps)1 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 BackgroundService (de.catma.backgroundservice.BackgroundService)1 Comment (de.catma.document.comment.Comment)1 Reply (de.catma.document.comment.Reply)1 ForkStatus (de.catma.project.ForkStatus)1 ProjectReference (de.catma.project.ProjectReference)1 CATMAPropertyKey (de.catma.properties.CATMAPropertyKey)1 RBACPermission (de.catma.rbac.RBACPermission)1