Search in sources :

Example 21 with AccessLevel

use of org.gitlab4j.api.models.AccessLevel in project ArTEMiS by ls1intum.

the class GitLabUserManagementService method addUserToGroups.

/**
 * Adds the Gitlab user to the groups. It will be given a different access level
 * based on the group type (instructors are given the MAINTAINER level and teaching
 * assistants REPORTED).
 *
 * @param gitlabUserId the user id of the Gitlab user
 * @param groups the new groups
 */
private void addUserToGroups(int gitlabUserId, Set<String> groups) {
    if (groups == null || groups.isEmpty()) {
        return;
    }
    List<ProgrammingExercise> exercises = programmingExerciseRepository.findAllByInstructorOrEditorOrTAGroupNameIn(groups);
    log.info("Update Gitlab permissions for programming exercises: " + exercises.stream().map(ProgrammingExercise::getProjectKey).toList());
    // TODO: in case we update a tutor group / role here, the tutor should NOT get access to exam exercises before the exam has finished
    for (var exercise : exercises) {
        Course course = exercise.getCourseViaExerciseGroupOrCourseMember();
        Optional<AccessLevel> accessLevel = getAccessLevelFromUserGroups(groups, course);
        accessLevel.ifPresent(level -> addUserToGroup(exercise.getProjectKey(), gitlabUserId, level));
    }
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) Course(de.tum.in.www1.artemis.domain.Course) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Aggregations

AccessLevel (org.gitlab4j.api.models.AccessLevel)21 Course (de.tum.in.www1.artemis.domain.Course)8 Permissions (org.gitlab4j.api.models.Permissions)6 GitLabApiException (org.gitlab4j.api.GitLabApiException)5 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)4 User (de.tum.in.www1.artemis.domain.User)4 Collections (java.util.Collections)4 List (java.util.List)4 Objects (java.util.Objects)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)3 GitLabProjectId (org.finos.legend.sdlc.server.gitlab.GitLabProjectId)3 GitLabApi (org.gitlab4j.api.GitLabApi)3 Pager (org.gitlab4j.api.Pager)3 Visibility (org.gitlab4j.api.models.Visibility)3 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 Maps (com.google.common.collect.Maps)2 EventBus (com.google.common.eventbus.EventBus)2