@@ -27,7 +27,6 @@ import org.sonar.api.utils.System2; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.rule.RuleDao; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.rule.RuleDto; |
@@ -31,7 +31,6 @@ import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.RuleStatus; | |||
import org.sonar.api.rules.RuleType; | |||
import org.sonar.api.server.debt.DebtRemediationFunction; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; |
@@ -0,0 +1,23 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.platform.db.migration.version.v85.util; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -36,13 +36,11 @@ import org.sonar.api.rule.RuleStatus; | |||
import org.sonar.api.rules.RulePriority; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.rule.RuleDao; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.db.rule.RuleParamDto; | |||
import org.sonar.markdown.Markdown; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
import static java.util.Optional.empty; |
@@ -140,9 +140,7 @@ public class RuleIndexer implements ResilientIndexer { | |||
}); | |||
// the remaining items reference rows that don't exist in db. They must be deleted from index. | |||
ruleUuids.forEach(ruleUuid -> { | |||
bulkIndexer.addDeletion(TYPE_RULE, ruleUuid, ruleUuid); | |||
}); | |||
ruleUuids.forEach(ruleUuid -> bulkIndexer.addDeletion(TYPE_RULE, ruleUuid, ruleUuid)); | |||
return Optional.of(bulkIndexer.stop()); | |||
} |
@@ -26,7 +26,6 @@ import javax.annotation.Nullable; | |||
import org.sonar.api.rule.RuleStatus; | |||
import org.sonar.api.rule.Severity; | |||
import org.sonar.api.rules.RuleType; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.qualityprofile.QProfileDto; | |||
import static java.util.Arrays.asList; |
@@ -97,9 +97,9 @@ public class UserRegistrarImpl implements UserRegistrar { | |||
Optional<UserDto> otherUserToIndex = detectEmailUpdate(dbSession, authenticatorParameters); | |||
NewUser newUser = createNewUser(authenticatorParameters); | |||
if (disabledUser == null) { | |||
return userUpdater.createAndCommit(dbSession, newUser, beforeCommit(dbSession, true, authenticatorParameters), toArray(otherUserToIndex)); | |||
return userUpdater.createAndCommit(dbSession, newUser, beforeCommit(dbSession, authenticatorParameters), toArray(otherUserToIndex)); | |||
} | |||
return userUpdater.reactivateAndCommit(dbSession, disabledUser, newUser, beforeCommit(dbSession, true, authenticatorParameters), toArray(otherUserToIndex)); | |||
return userUpdater.reactivateAndCommit(dbSession, disabledUser, newUser, beforeCommit(dbSession, authenticatorParameters), toArray(otherUserToIndex)); | |||
} | |||
private UserDto registerExistingUser(DbSession dbSession, UserDto userDto, UserRegistration authenticatorParameters) { | |||
@@ -111,14 +111,12 @@ public class UserRegistrarImpl implements UserRegistrar { | |||
authenticatorParameters.getUserIdentity().getProviderLogin(), | |||
authenticatorParameters.getUserIdentity().getProviderId())); | |||
Optional<UserDto> otherUserToIndex = detectEmailUpdate(dbSession, authenticatorParameters); | |||
userUpdater.updateAndCommit(dbSession, userDto, update, beforeCommit(dbSession, false, authenticatorParameters), toArray(otherUserToIndex)); | |||
userUpdater.updateAndCommit(dbSession, userDto, update, beforeCommit(dbSession, authenticatorParameters), toArray(otherUserToIndex)); | |||
return userDto; | |||
} | |||
private Consumer<UserDto> beforeCommit(DbSession dbSession, boolean isNewUser, UserRegistration authenticatorParameters) { | |||
return user -> { | |||
syncGroups(dbSession, authenticatorParameters.getUserIdentity(), user); | |||
}; | |||
private Consumer<UserDto> beforeCommit(DbSession dbSession, UserRegistration authenticatorParameters) { | |||
return user -> syncGroups(dbSession, authenticatorParameters.getUserIdentity(), user); | |||
} | |||
private Optional<UserDto> detectEmailUpdate(DbSession dbSession, UserRegistration authenticatorParameters) { |
@@ -28,7 +28,6 @@ import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RuleQuery; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
public class WebServerRuleFinderImpl implements WebServerRuleFinder { | |||
private final DbClient dbClient; |
@@ -125,7 +125,6 @@ public class TaskAction implements CeWsAction { | |||
private void checkPermission(Optional<ComponentDto> component) { | |||
if (component.isPresent()) { | |||
String orgUuid = component.get().getOrganizationUuid(); | |||
if (!userSession.hasPermission(GlobalPermission.ADMINISTER) && | |||
!userSession.hasPermission(GlobalPermission.SCAN) && | |||
!userSession.hasComponentPermission(UserRole.SCAN, component.get())) { |
@@ -30,7 +30,6 @@ import org.sonar.db.issue.IssueDto; | |||
import org.sonar.server.issue.IssueChangeWSSupport; | |||
import org.sonar.server.issue.IssueChangeWSSupport.Load; | |||
import org.sonar.server.issue.IssueFinder; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonarqube.ws.Issues.ChangelogWsResponse; | |||
import static java.util.Collections.singleton; | |||
@@ -43,13 +42,11 @@ public class ChangelogAction implements IssuesWsAction { | |||
private final DbClient dbClient; | |||
private final IssueFinder issueFinder; | |||
private final UserSession userSession; | |||
private final IssueChangeWSSupport issueChangeSupport; | |||
public ChangelogAction(DbClient dbClient, IssueFinder issueFinder, UserSession userSession, IssueChangeWSSupport issueChangeSupport) { | |||
public ChangelogAction(DbClient dbClient, IssueFinder issueFinder, IssueChangeWSSupport issueChangeSupport) { | |||
this.dbClient = dbClient; | |||
this.issueFinder = issueFinder; | |||
this.userSession = userSession; | |||
this.issueChangeSupport = issueChangeSupport; | |||
} | |||
@@ -57,7 +57,7 @@ public class SearchGlobalPermissionsAction implements PermissionsWsAction { | |||
@Override | |||
public void define(WebService.NewController context) { | |||
WebService.NewAction action = context.createAction(ACTION) | |||
context.createAction(ACTION) | |||
.setDescription("List global permissions. <br />" + | |||
"Requires the following permission: 'Administer System'") | |||
.setResponseExample(getClass().getResource("search_global_permissions-example.json")) |
@@ -256,7 +256,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction { | |||
final Table<String, String, Integer> userCountByRootComponentUuidAndPermission = TreeBasedTable.create(); | |||
dbClient.groupPermissionDao().groupsCountByComponentUuidAndPermission(dbSession, rootComponentUuids, context -> { | |||
CountPerProjectPermission row = (CountPerProjectPermission) context.getResultObject(); | |||
CountPerProjectPermission row = context.getResultObject(); | |||
userCountByRootComponentUuidAndPermission.put(row.getComponentUuid(), row.getPermission(), row.getCount()); | |||
}); | |||
@@ -103,7 +103,6 @@ public class ApplyTemplateAction implements PermissionsWsAction { | |||
private String projectId; | |||
private String projectKey; | |||
private String templateId; | |||
private String organization; | |||
private String templateName; | |||
@CheckForNull |
@@ -105,7 +105,7 @@ public class TemplateUsersAction implements PermissionsWsAction { | |||
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, templateRef); | |||
checkGlobalAdmin(userSession); | |||
PermissionQuery query = buildQuery(wsRequest, template); | |||
PermissionQuery query = buildQuery(wsRequest); | |||
int total = dbClient.permissionTemplateDao().countUserLoginsByQueryAndTemplate(dbSession, query, template.getUuid()); | |||
Paging paging = Paging.forPageIndex(wsRequest.mandatoryParamAsInt(PAGE)).withPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE)).andTotal(total); | |||
List<UserDto> users = findUsers(dbSession, query, template); | |||
@@ -116,7 +116,7 @@ public class TemplateUsersAction implements PermissionsWsAction { | |||
} | |||
} | |||
private PermissionQuery buildQuery(Request wsRequest, PermissionTemplateDto template) { | |||
private PermissionQuery buildQuery(Request wsRequest) { | |||
String textQuery = wsRequest.param(TEXT_QUERY); | |||
String permission = wsRequest.param(PARAM_PERMISSION); | |||
PermissionQuery.Builder query = PermissionQuery.builder() |
@@ -72,21 +72,21 @@ public class ListAction implements QualityGatesWsAction { | |||
OrganizationDto organization = wsSupport.getOrganization(dbSession, request); | |||
QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization); | |||
Collection<QualityGateDto> qualityGates = dbClient.qualityGateDao().selectAll(dbSession, organization); | |||
writeProtobuf(buildResponse(organization, qualityGates, defaultQualityGate), request, response); | |||
writeProtobuf(buildResponse(qualityGates, defaultQualityGate), request, response); | |||
} | |||
} | |||
private ListWsResponse buildResponse(OrganizationDto organization, Collection<QualityGateDto> qualityGates, @Nullable QualityGateDto defaultQualityGate) { | |||
private ListWsResponse buildResponse(Collection<QualityGateDto> qualityGates, @Nullable QualityGateDto defaultQualityGate) { | |||
String defaultUuid = defaultQualityGate == null ? null : defaultQualityGate.getUuid(); | |||
ListWsResponse.Builder builder = ListWsResponse.newBuilder() | |||
.setActions(ListWsResponse.RootActions.newBuilder().setCreate(wsSupport.isQualityGateAdmin(organization))) | |||
.setActions(ListWsResponse.RootActions.newBuilder().setCreate(wsSupport.isQualityGateAdmin())) | |||
.addAllQualitygates(qualityGates.stream() | |||
.map(qualityGate -> QualityGate.newBuilder() | |||
.setId(qualityGate.getUuid()) | |||
.setName(qualityGate.getName()) | |||
.setIsDefault(qualityGate.getUuid().equals(defaultUuid)) | |||
.setIsBuiltIn(qualityGate.isBuiltIn()) | |||
.setActions(wsSupport.getActions(organization, qualityGate, defaultQualityGate)) | |||
.setActions(wsSupport.getActions(qualityGate, defaultQualityGate)) | |||
.build()) | |||
.collect(toList())); | |||
ofNullable(defaultUuid).ifPresent(builder::setDefault); |
@@ -77,7 +77,7 @@ public class QualityGatesWsSupport { | |||
return checkFound(dbClient.gateConditionDao().selectByUuid(uuid, dbSession), "No quality gate condition with uuid '%s'", uuid); | |||
} | |||
boolean isQualityGateAdmin(OrganizationDto organization) { | |||
boolean isQualityGateAdmin() { | |||
return userSession.hasPermission(ADMINISTER_QUALITY_GATES); | |||
} | |||
@@ -91,10 +91,10 @@ public class QualityGatesWsSupport { | |||
.setExampleValue("my-org"); | |||
} | |||
Qualitygates.Actions getActions(OrganizationDto organization, QualityGateDto qualityGate, @Nullable QualityGateDto defaultQualityGate) { | |||
Qualitygates.Actions getActions(QualityGateDto qualityGate, @Nullable QualityGateDto defaultQualityGate) { | |||
boolean isDefault = defaultQualityGate != null && Objects.equals(defaultQualityGate.getUuid(), qualityGate.getUuid()); | |||
boolean isBuiltIn = qualityGate.isBuiltIn(); | |||
boolean isQualityGateAdmin = isQualityGateAdmin(organization); | |||
boolean isQualityGateAdmin = isQualityGateAdmin(); | |||
return Qualitygates.Actions.newBuilder() | |||
.setCopy(isQualityGateAdmin) | |||
.setRename(!isBuiltIn && isQualityGateAdmin) |
@@ -99,7 +99,7 @@ public class ShowAction implements QualityGatesWsAction { | |||
Collection<QualityGateConditionDto> conditions = getConditions(dbSession, qualityGate); | |||
Map<String, MetricDto> metricsByUuid = getMetricsByUuid(dbSession, conditions); | |||
QualityGateDto defaultQualityGate = qualityGateFinder.getDefault(dbSession, organization); | |||
writeProtobuf(buildResponse(organization, qualityGate, defaultQualityGate, conditions, metricsByUuid), request, response); | |||
writeProtobuf(buildResponse(qualityGate, defaultQualityGate, conditions, metricsByUuid), request, response); | |||
} | |||
} | |||
@@ -124,7 +124,7 @@ public class ShowAction implements QualityGatesWsAction { | |||
.collect(uniqueIndex(MetricDto::getUuid)); | |||
} | |||
private ShowWsResponse buildResponse(OrganizationDto organization, QualityGateDto qualityGate, QualityGateDto defaultQualityGate, | |||
private ShowWsResponse buildResponse(QualityGateDto qualityGate, QualityGateDto defaultQualityGate, | |||
Collection<QualityGateConditionDto> conditions, Map<String, MetricDto> metricsByUuid) { | |||
return ShowWsResponse.newBuilder() | |||
.setId(qualityGate.getUuid()) | |||
@@ -133,7 +133,7 @@ public class ShowAction implements QualityGatesWsAction { | |||
.addAllConditions(conditions.stream() | |||
.map(toWsCondition(metricsByUuid)) | |||
.collect(toList())) | |||
.setActions(wsSupport.getActions(organization, qualityGate, defaultQualityGate)) | |||
.setActions(wsSupport.getActions(qualityGate, defaultQualityGate)) | |||
.build(); | |||
} | |||
@@ -38,7 +38,6 @@ import org.sonar.api.server.ServerSide; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.qualityprofile.ExportRuleDto; | |||
import org.sonar.db.qualityprofile.ExportRuleParamDto; | |||
import org.sonar.db.qualityprofile.QProfileDto; |
@@ -24,7 +24,6 @@ import java.util.Collection; | |||
import java.util.Date; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
import java.util.Objects; | |||
import java.util.Set; | |||
import javax.annotation.Nullable; | |||
import org.apache.commons.lang.StringUtils; | |||
@@ -32,7 +31,6 @@ import org.sonar.api.utils.System2; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.qualityprofile.DefaultQProfileDto; | |||
import org.sonar.db.qualityprofile.QProfileDto; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
@@ -55,11 +53,6 @@ public class QProfileFactoryImpl implements QProfileFactory { | |||
this.activeRuleIndexer = activeRuleIndexer; | |||
} | |||
private static OrganizationDto requireNonNull(@Nullable OrganizationDto organization) { | |||
Objects.requireNonNull(organization, "Organization is required, when creating a quality profile."); | |||
return organization; | |||
} | |||
@Override | |||
public QProfileDto getOrCreateCustom(DbSession dbSession, QProfileName name) { | |||
QProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, name.getName(), name.getLanguage()); |
@@ -71,13 +71,11 @@ public class CompareAction implements QProfileWsAction { | |||
private final DbClient dbClient; | |||
private final QProfileComparison comparator; | |||
private final Languages languages; | |||
private final QProfileWsSupport wsSupport; | |||
public CompareAction(DbClient dbClient, QProfileComparison comparator, Languages languages, QProfileWsSupport wsSupport) { | |||
public CompareAction(DbClient dbClient, QProfileComparison comparator, Languages languages) { | |||
this.dbClient = dbClient; | |||
this.comparator = comparator; | |||
this.languages = languages; | |||
this.wsSupport = wsSupport; | |||
} | |||
@Override |
@@ -102,10 +102,6 @@ public class QProfileWsSupport { | |||
return group.get(); | |||
} | |||
public void checkPermission(DbSession dbSession) { | |||
userSession.checkPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES); | |||
} | |||
boolean canEdit(DbSession dbSession, QProfileDto profile) { | |||
if (profile.isBuiltIn() || !userSession.isLoggedIn()) { | |||
return false; |
@@ -77,14 +77,12 @@ public class SearchAction implements QProfileWsAction { | |||
private final UserSession userSession; | |||
private final Languages languages; | |||
private final DbClient dbClient; | |||
private final QProfileWsSupport wsSupport; | |||
private final ComponentFinder componentFinder; | |||
public SearchAction(UserSession userSession, Languages languages, DbClient dbClient, QProfileWsSupport wsSupport, ComponentFinder componentFinder) { | |||
public SearchAction(UserSession userSession, Languages languages, DbClient dbClient, ComponentFinder componentFinder) { | |||
this.userSession = userSession; | |||
this.languages = languages; | |||
this.dbClient = dbClient; | |||
this.wsSupport = wsSupport; | |||
this.componentFinder = componentFinder; | |||
} | |||
@@ -44,7 +44,7 @@ public class AppAction implements RulesWsAction { | |||
@Override | |||
public void define(WebService.NewController controller) { | |||
WebService.NewAction action = controller.createAction("app") | |||
controller.createAction("app") | |||
.setDescription("Get data required for rendering the page 'Coding Rules'.") | |||
.setResponseExample(getClass().getResource("app-example.json")) | |||
.setSince("4.5") |
@@ -34,7 +34,6 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.qualityprofile.ActiveRuleInheritance; | |||
import org.sonar.server.rule.index.RuleIndexDefinition; | |||
import org.sonar.server.security.SecurityStandards; | |||
@@ -75,12 +74,10 @@ public class RuleWsSupport { | |||
private final DbClient dbClient; | |||
private final UserSession userSession; | |||
private final DefaultOrganizationProvider defaultOrganizationProvider; | |||
public RuleWsSupport(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider) { | |||
public RuleWsSupport(DbClient dbClient, UserSession userSession) { | |||
this.dbClient = dbClient; | |||
this.userSession = userSession; | |||
this.defaultOrganizationProvider = defaultOrganizationProvider; | |||
} | |||
public void checkQProfileAdminPermissionOnDefaultOrganization() { |
@@ -198,10 +198,9 @@ public class UpdateAction implements RulesWsAction { | |||
private RuleUpdate createRuleUpdate(DbSession dbSession, RuleKey key) { | |||
RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, key) | |||
.orElseThrow(() -> new NotFoundException(format("This rule does not exist: %s", key))); | |||
RuleUpdate ruleUpdate = ofNullable(rule.getTemplateUuid()) | |||
return ofNullable(rule.getTemplateUuid()) | |||
.map(x -> RuleUpdate.createForCustomRule(key)) | |||
.orElseGet(() -> RuleUpdate.createForPluginRule(key)); | |||
return ruleUpdate; | |||
} | |||
private static void readTags(Request request, RuleUpdate update) { |
@@ -25,7 +25,6 @@ import org.sonar.api.web.UserRole; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.permission.GlobalPermission; | |||
import org.sonar.process.ProcessProperties; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.user.UserSession; | |||
import static java.lang.String.format; | |||
@@ -36,11 +35,9 @@ import static org.sonar.api.web.UserRole.ADMIN; | |||
public class SettingsWsSupport { | |||
public static final String DOT_SECURED = ".secured"; | |||
private final DefaultOrganizationProvider defaultOrganizationProvider; | |||
private final UserSession userSession; | |||
public SettingsWsSupport(DefaultOrganizationProvider defaultOrganizationProvider, UserSession userSession) { | |||
this.defaultOrganizationProvider = defaultOrganizationProvider; | |||
public SettingsWsSupport(UserSession userSession) { | |||
this.userSession = userSession; | |||
} | |||
@@ -37,6 +37,7 @@ import org.sonar.server.user.UserSession; | |||
import static com.google.common.base.Preconditions.checkState; | |||
import static java.lang.String.format; | |||
import static org.apache.commons.lang.StringUtils.isNotBlank; | |||
import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; | |||
import static org.sonar.server.webhook.ws.WebhooksWsParameters.ACTION_CREATE; | |||
import static org.sonar.server.webhook.ws.WebhooksWsParameters.NAME_PARAM; | |||
import static org.sonar.server.webhook.ws.WebhooksWsParameters.NAME_PARAM_MAXIMUM_LENGTH; | |||
@@ -52,7 +53,6 @@ import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.NAME_WEBHOOK_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.URL_WEBHOOK_EXAMPLE_001; | |||
import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; | |||
import static org.sonar.server.ws.WsUtils.checkStateWithOptional; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.Webhooks.CreateWsResponse.Webhook; | |||
@@ -150,7 +150,7 @@ public class CreateAction implements WebhooksWsAction { | |||
webhookSupport.checkThatProjectBelongsToOrganization(projectDto, organizationDto, "Project '%s' does not belong to organisation '%s'", projectKey, organizationKey); | |||
webhookSupport.checkPermission(projectDto); | |||
} else { | |||
webhookSupport.checkPermission(organizationDto); | |||
webhookSupport.checkPermission(); | |||
} | |||
webhookSupport.checkUrlPattern(url, "Url parameter with value '%s' is not a valid url", url); |
@@ -25,7 +25,6 @@ import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.webhook.WebhookDto; | |||
import org.sonar.server.user.UserSession; | |||
@@ -76,20 +75,15 @@ public class DeleteAction implements WebhooksWsAction { | |||
Optional<WebhookDto> dtoOptional = dbClient.webhookDao().selectByUuid(dbSession, webhookKey); | |||
WebhookDto webhookDto = checkFoundWithOptional(dtoOptional, "No webhook with key '%s'", webhookKey); | |||
String organizationUuid = webhookDto.getOrganizationUuid(); | |||
if (organizationUuid != null) { | |||
Optional<OrganizationDto> optionalDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid); | |||
OrganizationDto organizationDto = checkStateWithOptional(optionalDto, "the requested organization '%s' was not found", organizationUuid); | |||
webhookSupport.checkPermission(organizationDto); | |||
deleteWebhook(dbSession, webhookDto); | |||
} | |||
String projectUuid = webhookDto.getProjectUuid(); | |||
if (projectUuid != null) { | |||
Optional<ProjectDto> optionalDto = dbClient.projectDao().selectByUuid(dbSession, projectUuid); | |||
ProjectDto projectDto = checkStateWithOptional(optionalDto, "the requested project '%s' was not found", projectUuid); | |||
webhookSupport.checkPermission(projectDto); | |||
deleteWebhook(dbSession, webhookDto); | |||
} else { | |||
webhookSupport.checkPermission(); | |||
deleteWebhook(dbSession, webhookDto); | |||
} | |||
dbSession.commit(); |
@@ -61,7 +61,7 @@ public class ListAction implements WebhooksWsAction { | |||
private final ComponentFinder componentFinder; | |||
public ListAction(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider, | |||
WebhookSupport webhookSupport, ComponentFinder componentFinder) { | |||
WebhookSupport webhookSupport, ComponentFinder componentFinder) { | |||
this.dbClient = dbClient; | |||
this.userSession = userSession; | |||
this.defaultOrganizationProvider = defaultOrganizationProvider; | |||
@@ -127,7 +127,7 @@ public class ListAction implements WebhooksWsAction { | |||
return dbClient.webhookDao().selectByProject(dbSession, projectDto); | |||
} else { | |||
webhookSupport.checkPermission(organizationDto); | |||
webhookSupport.checkPermission(); | |||
return dbClient.webhookDao().selectByOrganization(dbSession, organizationDto); | |||
} | |||
} |
@@ -26,7 +26,6 @@ import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.project.ProjectDto; | |||
import org.sonar.db.webhook.WebhookDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
@@ -45,7 +44,6 @@ import static org.sonar.server.webhook.ws.WebhooksWsParameters.URL_PARAM_MAXIMUM | |||
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.NAME_WEBHOOK_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.URL_WEBHOOK_EXAMPLE_001; | |||
import static org.sonar.server.ws.WsUtils.checkStateWithOptional; | |||
public class UpdateAction implements WebhooksWsAction { | |||
@@ -114,19 +112,14 @@ public class UpdateAction implements WebhooksWsAction { | |||
Optional<WebhookDto> dtoOptional = dbClient.webhookDao().selectByUuid(dbSession, webhookKey); | |||
WebhookDto webhookDto = checkFoundWithOptional(dtoOptional, "No webhook with key '%s'", webhookKey); | |||
String organizationUuid = webhookDto.getOrganizationUuid(); | |||
if (organizationUuid != null) { | |||
Optional<OrganizationDto> optionalDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid); | |||
OrganizationDto organizationDto = checkStateWithOptional(optionalDto, "the requested organization '%s' was not found", organizationUuid); | |||
webhookSupport.checkPermission(organizationDto); | |||
updateWebhook(dbSession, webhookDto, name, url, secret); | |||
} | |||
String projectUuid = webhookDto.getProjectUuid(); | |||
if (projectUuid != null) { | |||
ProjectDto projectDto = componentFinder.getProjectByUuid(dbSession, projectUuid); | |||
webhookSupport.checkPermission(projectDto); | |||
updateWebhook(dbSession, webhookDto, name, url, secret); | |||
} else { | |||
webhookSupport.checkPermission(); | |||
updateWebhook(dbSession, webhookDto, name, url, secret); | |||
} | |||
dbSession.commit(); |
@@ -47,7 +47,7 @@ public class WebhookSupport { | |||
userSession.checkProjectPermission(ADMIN, projectDto); | |||
} | |||
void checkPermission(OrganizationDto organizationDto) { | |||
void checkPermission() { | |||
userSession.checkPermission(ADMINISTER); | |||
} | |||
@@ -75,7 +75,7 @@ public class ChangelogActionTest { | |||
private ComponentDto file; | |||
private IssueFinder issueFinder = new IssueFinder(db.getDbClient(), userSession); | |||
private IssueChangeWSSupport issueChangeSupport = new IssueChangeWSSupport(db.getDbClient(), new AvatarResolverImpl(), userSession); | |||
private ChangelogAction underTest = new ChangelogAction(db.getDbClient(), issueFinder, userSession, issueChangeSupport); | |||
private ChangelogAction underTest = new ChangelogAction(db.getDbClient(), issueFinder, issueChangeSupport); | |||
private WsActionTester tester = new WsActionTester(underTest); | |||
@Before |
@@ -41,9 +41,7 @@ import org.sonar.db.rule.RuleDto; | |||
import org.sonar.db.rule.RuleDto.Scope; | |||
import org.sonar.db.rule.RuleParamDto; | |||
import org.sonar.db.rule.RuleRepositoryDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.language.LanguageTesting; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.qualityprofile.QProfileComparison; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.WsActionTester; | |||
@@ -66,8 +64,7 @@ public class CompareActionTest { | |||
private DbSession session = db.getSession(); | |||
private WsActionTester ws = new WsActionTester( | |||
new CompareAction(db.getDbClient(), new QProfileComparison(db.getDbClient()), new Languages(LanguageTesting.newLanguage("xoo", "Xoo")), | |||
new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db)))); | |||
new CompareAction(db.getDbClient(), new QProfileComparison(db.getDbClient()), new Languages(LanguageTesting.newLanguage("xoo", "Xoo")))); | |||
@Test | |||
public void compare_nominal() { |
@@ -42,8 +42,6 @@ import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.TestRequest; | |||
import org.sonar.server.ws.WsActionTester; | |||
@@ -79,10 +77,8 @@ public class SearchActionTest { | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private QualityProfileDbTester qualityProfileDb = db.qualityProfiles(); | |||
private DbClient dbClient = db.getDbClient(); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
private QProfileWsSupport qProfileWsSupport = new QProfileWsSupport(dbClient, userSession, defaultOrganizationProvider); | |||
private SearchAction underTest = new SearchAction(userSession, LANGUAGES, dbClient, qProfileWsSupport, new ComponentFinder(dbClient, null)); | |||
private SearchAction underTest = new SearchAction(userSession, LANGUAGES, dbClient, new ComponentFinder(dbClient, null)); | |||
private WsActionTester ws = new WsActionTester(underTest); | |||
@Test | |||
@@ -94,7 +90,7 @@ public class SearchActionTest { | |||
@Test | |||
public void empty_when_no_language_installed() { | |||
WsActionTester ws = new WsActionTester(new SearchAction(userSession, new Languages(), dbClient, qProfileWsSupport, new ComponentFinder(dbClient, null))); | |||
WsActionTester ws = new WsActionTester(new SearchAction(userSession, new Languages(), dbClient, new ComponentFinder(dbClient, null))); | |||
db.qualityProfiles().insert(); | |||
SearchWsResponse result = call(ws.newRequest()); | |||
@@ -253,7 +249,7 @@ public class SearchActionTest { | |||
@Test | |||
public void empty_when_filtering_on_project_and_no_language_installed() { | |||
WsActionTester ws = new WsActionTester(new SearchAction(userSession, new Languages(), dbClient, qProfileWsSupport, new ComponentFinder(dbClient, null))); | |||
WsActionTester ws = new WsActionTester(new SearchAction(userSession, new Languages(), dbClient, new ComponentFinder(dbClient, null))); | |||
db.qualityProfiles().insert(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
QProfileDto profileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey())); | |||
@@ -429,7 +425,7 @@ public class SearchActionTest { | |||
db.qualityProfiles().addUserPermission(myBuProfile, user); | |||
userSession.logIn(user); | |||
underTest = new SearchAction(userSession, new Languages(cs, java, python), dbClient, qProfileWsSupport, new ComponentFinder(dbClient, null)); | |||
underTest = new SearchAction(userSession, new Languages(cs, java, python), dbClient, new ComponentFinder(dbClient, null)); | |||
ws = new WsActionTester(underTest); | |||
String result = ws.newRequest().execute().getInput(); | |||
assertJson(result).ignoreFields("ruleUpdatedAt", "lastUsed", "userUpdatedAt") |
@@ -35,8 +35,6 @@ import org.sonar.db.rule.RuleDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.UnauthorizedException; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.rule.RuleCreator; | |||
import org.sonar.server.rule.index.RuleIndexer; | |||
import org.sonar.server.tester.UserSessionRule; | |||
@@ -74,13 +72,12 @@ public class CreateActionTest { | |||
@Rule | |||
public EsTester es = EsTester.create(); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
private UuidFactory uuidFactory = new SequenceUuidFactory(); | |||
private WsActionTester ws = new WsActionTester(new CreateAction(db.getDbClient(), | |||
new RuleCreator(system2, new RuleIndexer(es.client(), db.getDbClient()), db.getDbClient(), newFullTypeValidations(), uuidFactory), | |||
new RuleMapper(new Languages(), createMacroInterpreter()), | |||
new RuleWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider))); | |||
new RuleWsSupport(db.getDbClient(), userSession))); | |||
@Test | |||
public void check_definition() { |
@@ -31,8 +31,6 @@ import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.UnauthorizedException; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.qualityprofile.QProfileRules; | |||
import org.sonar.server.rule.index.RuleIndexer; | |||
import org.sonar.server.tester.UserSessionRule; | |||
@@ -57,12 +55,11 @@ public class DeleteActionTest { | |||
public EsTester es = EsTester.create(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester); | |||
private DbClient dbClient = dbTester.getDbClient(); | |||
private DbSession dbSession = dbTester.getSession(); | |||
private RuleIndexer ruleIndexer = spy(new RuleIndexer(es.client(), dbClient)); | |||
private QProfileRules qProfileRules = mock(QProfileRules.class); | |||
private RuleWsSupport ruleWsSupport = new RuleWsSupport(mock(DbClient.class), userSession, defaultOrganizationProvider); | |||
private RuleWsSupport ruleWsSupport = new RuleWsSupport(mock(DbClient.class), userSession); | |||
private DeleteAction underTest = new DeleteAction(System2.INSTANCE, ruleIndexer, dbClient, qProfileRules, ruleWsSupport); | |||
private WsActionTester tester = new WsActionTester(underTest); | |||
@@ -47,8 +47,6 @@ import org.sonar.db.user.UserDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.language.LanguageTesting; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.qualityprofile.ActiveRuleChange; | |||
import org.sonar.server.qualityprofile.QProfileRules; | |||
import org.sonar.server.qualityprofile.QProfileRulesImpl; | |||
@@ -104,7 +102,6 @@ public class SearchActionTest { | |||
@org.junit.Rule | |||
public EsTester es = EsTester.create(); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
private RuleIndex ruleIndex = new RuleIndex(es.client(), system2); | |||
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient()); | |||
private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db.getDbClient(), es.client()); | |||
@@ -114,7 +111,7 @@ public class SearchActionTest { | |||
private MacroInterpreter macroInterpreter = mock(MacroInterpreter.class); | |||
private RuleMapper ruleMapper = new RuleMapper(languages, macroInterpreter); | |||
private SearchAction underTest = new SearchAction(ruleIndex, activeRuleCompleter, ruleQueryFactory, db.getDbClient(), ruleMapper, | |||
new RuleWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider)); | |||
new RuleWsSupport(db.getDbClient(), userSession)); | |||
private TypeValidations typeValidations = new TypeValidations(asList(new StringTypeValidation(), new IntegerTypeValidation())); | |||
private RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, db.getDbClient(), typeValidations, userSession); | |||
private QProfileRules qProfileRules = new QProfileRulesImpl(db.getDbClient(), ruleActivator, ruleIndex, activeRuleIndexer); |
@@ -37,8 +37,6 @@ import org.sonar.db.rule.RuleDto; | |||
import org.sonar.db.rule.RuleMetadataDto; | |||
import org.sonar.db.rule.RuleParamDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.text.MacroInterpreter; | |||
import org.sonar.server.ws.WsActionTester; | |||
@@ -73,7 +71,6 @@ public class ShowActionTest { | |||
public DbTester db = DbTester.create(); | |||
@org.junit.Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
private MacroInterpreter macroInterpreter = mock(MacroInterpreter.class); | |||
private Languages languages = new Languages(newLanguage("xoo", "Xoo")); | |||
@@ -81,7 +78,7 @@ public class ShowActionTest { | |||
private WsActionTester ws = new WsActionTester( | |||
new ShowAction(db.getDbClient(), new RuleMapper(languages, macroInterpreter), | |||
new ActiveRuleCompleter(db.getDbClient(), languages), | |||
new RuleWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider))); | |||
new RuleWsSupport(db.getDbClient(), userSession))); | |||
@Before | |||
public void before() { |
@@ -36,8 +36,6 @@ import org.sonar.server.es.EsClient; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.UnauthorizedException; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.rule.RuleUpdater; | |||
import org.sonar.server.rule.index.RuleIndexer; | |||
import org.sonar.server.tester.UserSessionRule; | |||
@@ -80,7 +78,7 @@ public class UpdateActionTest { | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
private DbClient dbClient = db.getDbClient(); | |||
private EsClient esClient = es.client(); | |||
@@ -88,7 +86,7 @@ public class UpdateActionTest { | |||
private RuleMapper mapper = new RuleMapper(languages, createMacroInterpreter()); | |||
private RuleIndexer ruleIndexer = new RuleIndexer(esClient, dbClient); | |||
private RuleUpdater ruleUpdater = new RuleUpdater(dbClient, ruleIndexer, System2.INSTANCE); | |||
private WsAction underTest = new UpdateAction(dbClient, ruleUpdater, mapper, userSession, new RuleWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider)); | |||
private WsAction underTest = new UpdateAction(dbClient, ruleUpdater, mapper, userSession, new RuleWsSupport(db.getDbClient(), userSession)); | |||
private WsActionTester ws = new WsActionTester(underTest); | |||
@Test |
@@ -40,8 +40,6 @@ import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.component.TestComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.TestRequest; | |||
import org.sonar.server.ws.WsActionTester; | |||
@@ -86,8 +84,7 @@ public class ListDefinitionsActionTest { | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private ComponentDto project; | |||
private PropertyDefinitions propertyDefinitions = new PropertyDefinitions(System2.INSTANCE); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
private SettingsWsSupport support = new SettingsWsSupport(defaultOrganizationProvider, userSession); | |||
private SettingsWsSupport support = new SettingsWsSupport(userSession); | |||
private WsActionTester ws = new WsActionTester( | |||
new ListDefinitionsAction(dbClient, TestComponentFinder.from(db), userSession, propertyDefinitions, support)); | |||
@@ -48,8 +48,6 @@ import org.sonar.process.ProcessProperties; | |||
import org.sonar.server.component.TestComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.organization.TestDefaultOrganizationProvider; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.TestRequest; | |||
import org.sonar.server.ws.WsActionTester; | |||
@@ -90,8 +88,7 @@ public class ValuesActionTest { | |||
private PropertyDbTester propertyDb = new PropertyDbTester(db); | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private PropertyDefinitions definitions = new PropertyDefinitions(System2.INSTANCE); | |||
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); | |||
private SettingsWsSupport support = new SettingsWsSupport(defaultOrganizationProvider, userSession); | |||
private SettingsWsSupport support = new SettingsWsSupport(userSession); | |||
private ComponentDto project; | |||
@Before |