use of org.gitlab4j.api.models.Permissions 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;
}
use of org.gitlab4j.api.models.Permissions in project catma by forTEXT.
the class GitlabManagerRestricted method getResourcePermissions.
private Map<String, AccessLevel> getResourcePermissions(Integer groupId) throws GitLabApiException {
Map<String, AccessLevel> resultMap = Maps.newHashMap();
ProjectApi projectApi = new ProjectApi(restrictedGitLabApi);
logger.info("Loading project permissions");
List<Project> resourceAndContainerProjects = projectApi.getProjects(new ProjectFilter().withMembership(true));
logger.info(String.format("Filtering %1$d resources on group #%2$d", resourceAndContainerProjects.size(), groupId));
Set<Project> filteredOnGroupProjects = resourceAndContainerProjects.stream().filter(p -> p.getNamespace().getId().equals(groupId)).collect(Collectors.toSet());
logger.info(String.format("Updating accesslevel registry for %1$d resources", filteredOnGroupProjects.size()));
for (Project p : filteredOnGroupProjects) {
Permissions permission = p.getPermissions();
if (permission.getGroupAccess() != null) {
resultMap.put(p.getName(), permission.getGroupAccess().getAccessLevel());
}
if (permission.getProjectAccess() != null && (!resultMap.containsKey(p.getName()) || resultMap.get(p.getName()).value.intValue() < permission.getProjectAccess().getAccessLevel().value.intValue())) {
resultMap.put(p.getName(), permission.getProjectAccess().getAccessLevel());
}
}
return resultMap;
}
use of org.gitlab4j.api.models.Permissions in project fastjson by alibaba.
the class Issue2040 method test_for_issue_2040_2.
public void test_for_issue_2040_2() throws Exception {
String json = "{\n" + " \"project_access\": null,\n" + " \"group_access\": {\n" + " \"access_level\": 50,\n" + " \"notification_level\": 3\n" + " }\n" + " }";
ObjectMapper objectMapper = new ObjectMapper();
// Permissions permissions = objectMapper.readValue(json, Permissions.class);
Permissions permissions = JSON.parseObject(json, Permissions.class, config);
System.out.println(JSON.toJSONString(permissions));
}
use of org.gitlab4j.api.models.Permissions in project legend-sdlc by finos.
the class GitLabProjectApi method checkUserReleasePermission.
private boolean checkUserReleasePermission(GitLabProjectId projectId, ProjectAuthorizationAction action, AccessLevel accessLevel) {
try {
List<ProtectedTag> protectedTags = withRetries(() -> getGitLabApi(projectId.getGitLabMode()).getTagsApi().getProtectedTags(projectId.getGitLabId()));
if (protectedTags == null || protectedTags.isEmpty()) {
// By default user can perform a release if the user has developer access or above https://docs.gitlab.com/ee/user/permissions.html#release-permissions-with-protected-tags
return defaultReleaseAction(accessLevel);
}
protectedTags = protectedTags.stream().filter(a -> a.getName().startsWith("release") || a.getName().startsWith("version")).collect(Collectors.toList());
for (ProtectedTag tag : protectedTags) {
if (tag.getCreateAccessLevels().isEmpty()) {
return defaultReleaseAction(accessLevel);
}
// with th release protected tag the user must have the min access_level
List<ProtectedTag.CreateAccessLevel> matchedTags = tag.getCreateAccessLevels().stream().filter(a -> a.getAccess_level().value >= accessLevel.value).collect(Collectors.toList());
// if the machedTags are empty or null user access does not match any of the protected tags
if (matchedTags.isEmpty()) {
return defaultReleaseAction(accessLevel);
}
// User does not meet all criteria not authorized for the action
if (matchedTags.size() != tag.getCreateAccessLevels().size()) {
return false;
}
}
} catch (Exception e) {
throw buildException(e, () -> "Failed to get protected tags for " + projectId.getGitLabId());
}
return false;
}
use of org.gitlab4j.api.models.Permissions 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);
}
}
Aggregations