Search in sources :

Example 86 with ComponentDto

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()));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 87 with ComponentDto

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;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList)

Example 88 with ComponentDto

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);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 89 with ComponentDto

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();
}
Also used : Project(org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse.Project) SearchProjectPermissionsWsResponse(org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse) Paging(org.sonar.api.utils.Paging) Permission(org.sonarqube.ws.WsPermissions.Permission) ComponentDto(org.sonar.db.component.ComponentDto)

Example 90 with ComponentDto

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();
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ProjectId(org.sonar.server.permission.ProjectId)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13