use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class PermissionTemplateService method apply.
/**
* Apply a permission template to a set of projects. Authorization to administrate these projects
* is not verified. The projects must exist, so the "project creator" permissions defined in the
* template are ignored.
*/
public void apply(DbSession dbSession, PermissionTemplateDto template, Collection<ComponentDto> projects) {
if (projects.isEmpty()) {
return;
}
for (ComponentDto project : projects) {
copyPermissions(dbSession, template, project, null);
}
dbSession.commit();
indexProjectPermissions(dbSession, projects.stream().map(ComponentDto::uuid).collect(Collectors.toList()));
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class SearchResponseFormat method formatComponents.
private static List<Issues.Component> formatComponents(SearchResponseData data) {
Collection<ComponentDto> components = data.getComponents();
if (components == null) {
return Collections.emptyList();
}
List<Issues.Component> result = new ArrayList<>();
for (ComponentDto dto : components) {
String uuid = dto.uuid();
Issues.Component.Builder builder = Issues.Component.newBuilder().setOrganization(data.getOrganizationKey(dto.getOrganizationUuid())).setId(dto.getId()).setKey(dto.key()).setUuid(uuid).setQualifier(dto.qualifier()).setName(nullToEmpty(dto.name())).setLongName(nullToEmpty(dto.longName())).setEnabled(dto.isEnabled());
String path = dto.path();
// Value must not be "" in this case.
if (!Strings.isNullOrEmpty(path)) {
builder.setPath(path);
}
// On a root project, parentProjectId is null but projectId is equal to itself, which make no sense.
if (!uuid.equals(dto.getRootUuid())) {
ComponentDto project = data.getComponentByUuid(dto.projectUuid());
setNullable(project, builder::setProjectId, ComponentDto::getId);
ComponentDto subProject = data.getComponentByUuid(dto.getRootUuid());
setNullable(subProject, builder::setSubProjectId, ComponentDto::getId);
}
result.add(builder.build());
}
return result;
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class SearchResponseLoader method loadComponents.
private void loadComponents(Collector collector, DbSession dbSession, SearchResponseData result) {
// always load components and projects, because some issue fields still relate to component ids/keys.
// They should be dropped but are kept for backward-compatibility (see SearchResponseFormat)
result.addComponents(dbClient.componentDao().selectByUuids(dbSession, collector.getComponentUuids()));
result.addComponents(dbClient.componentDao().selectSubProjectsByComponentUuids(dbSession, collector.getComponentUuids()));
for (ComponentDto component : result.getComponents()) {
collector.addProjectUuid(component.projectUuid());
}
List<ComponentDto> projects = dbClient.componentDao().selectByUuids(dbSession, collector.getProjectUuids());
result.addComponents(projects);
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class SearchProjectPermissionsAction method buildResponse.
private SearchProjectPermissionsWsResponse buildResponse(SearchProjectPermissionsData data) {
SearchProjectPermissionsWsResponse.Builder response = SearchProjectPermissionsWsResponse.newBuilder();
Permission.Builder permissionResponse = Permission.newBuilder();
Project.Builder rootComponentBuilder = Project.newBuilder();
for (ComponentDto rootComponent : data.rootComponents()) {
rootComponentBuilder.clear().setId(rootComponent.uuid()).setKey(rootComponent.key()).setQualifier(rootComponent.qualifier()).setName(rootComponent.name());
for (String permission : data.permissions(rootComponent.getId())) {
rootComponentBuilder.addPermissions(permissionResponse.clear().setKey(permission).setUsersCount(data.userCount(rootComponent.getId(), permission)).setGroupsCount(data.groupCount(rootComponent.getId(), permission)));
}
response.addProjects(rootComponentBuilder);
}
for (String permissionKey : ProjectPermissions.ALL) {
response.addPermissions(permissionResponse.clear().setKey(permissionKey).setName(i18nName(permissionKey)).setDescription(i18nDescriptionMessage(permissionKey)));
}
Paging paging = data.paging();
response.setPaging(Common.Paging.newBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()));
return response.build();
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class SearchProjectPermissionsAction method checkAuthorized.
private void checkAuthorized(DbSession dbSession, SearchProjectPermissionsWsRequest request) {
com.google.common.base.Optional<ProjectWsRef> projectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
if (projectRef.isPresent()) {
ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, projectRef.get());
PermissionPrivilegeChecker.checkProjectAdmin(userSession, project.getOrganizationUuid(), Optional.of(new ProjectId(project)));
} else {
userSession.checkLoggedIn().checkIsSystemAdministrator();
}
}
Aggregations