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