Search in sources :

Example 1 with ProjectAccess

use of org.gitlab4j.api.models.ProjectAccess in project legend-sdlc by finos.

the class GitLabProjectApi method getUserAccess.

private AccessLevel getUserAccess(org.gitlab4j.api.models.Project gitLabProject) {
    Permissions permissions = gitLabProject.getPermissions();
    if (permissions != null) {
        ProjectAccess projectAccess = permissions.getProjectAccess();
        AccessLevel projectAccessLevel = (projectAccess == null) ? null : projectAccess.getAccessLevel();
        if (projectAccessLevel != null) {
            return projectAccessLevel;
        }
        ProjectAccess groupAccess = permissions.getGroupAccess();
        return (groupAccess == null) ? null : groupAccess.getAccessLevel();
    }
    return null;
}
Also used : Permissions(org.gitlab4j.api.models.Permissions) ProjectAccess(org.gitlab4j.api.models.ProjectAccess) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Example 2 with ProjectAccess

use of org.gitlab4j.api.models.ProjectAccess in project legend-sdlc by finos.

the class GitLabProjectApi method getCurrentUserAccessRole.

@Override
public AccessRole getCurrentUserAccessRole(String id) {
    LegendSDLCServerException.validateNonNull(id, "id may not be null");
    try {
        GitLabProjectId projectId = parseProjectId(id);
        org.gitlab4j.api.models.Project gitLabProject = withRetries(() -> getGitLabApi(projectId.getGitLabMode()).getProjectApi().getProject(projectId.getGitLabId()));
        if (!isLegendSDLCProject(gitLabProject)) {
            throw new LegendSDLCServerException("Failed to get project " + id);
        }
        Permissions permissions = gitLabProject.getPermissions();
        if (permissions != null) {
            ProjectAccess projectAccess = permissions.getProjectAccess();
            AccessLevel projectAccessLevel = (projectAccess == null) ? null : projectAccess.getAccessLevel();
            if (projectAccessLevel != null) {
                return new AccessRoleWrapper(projectAccessLevel);
            }
            ProjectAccess groupAccess = permissions.getGroupAccess();
            AccessLevel groupAccessLevel = (groupAccess == null) ? null : groupAccess.getAccessLevel();
            if (groupAccessLevel != null) {
                return new AccessRoleWrapper(groupAccessLevel);
            }
        }
        return null;
    } catch (Exception e) {
        throw buildException(e, () -> "Failed to get project " + id);
    }
}
Also used : LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) GitLabProjectId(org.finos.legend.sdlc.server.gitlab.GitLabProjectId) Permissions(org.gitlab4j.api.models.Permissions) ProjectAccess(org.gitlab4j.api.models.ProjectAccess) AccessLevel(org.gitlab4j.api.models.AccessLevel) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException)

Aggregations

AccessLevel (org.gitlab4j.api.models.AccessLevel)2 Permissions (org.gitlab4j.api.models.Permissions)2 ProjectAccess (org.gitlab4j.api.models.ProjectAccess)2 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)1 GitLabProjectId (org.finos.legend.sdlc.server.gitlab.GitLabProjectId)1