import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentUpdater;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.project.Visibility;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsProjects.CreateWsResponse;
import org.sonarqube.ws.client.project.CreateRequest;
-import static java.util.Optional.ofNullable;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
import static org.sonar.server.component.NewComponent.newComponentBuilder;
private final DbClient dbClient;
private final UserSession userSession;
private final ComponentUpdater componentUpdater;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public CreateAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession, ComponentUpdater componentUpdater,
- DefaultOrganizationProvider defaultOrganizationProvider) {
+ public CreateAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession, ComponentUpdater componentUpdater) {
this.support = support;
this.dbClient = dbClient;
this.userSession = userSession;
this.componentUpdater = componentUpdater;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
}
@Override
private CreateWsResponse doHandle(CreateRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization())
- .orElseGet(defaultOrganizationProvider.get()::getKey));
+ OrganizationDto organization = support.getOrganization(dbSession, request.getOrganization());
userSession.checkPermission(PROVISION_PROJECTS, organization);
String visibility = request.getVisibility();
Boolean changeToPrivate = visibility == null ? dbClient.organizationDao().getNewProjectPrivate(dbSession, organization) : "private".equals(visibility);
*/
package org.sonar.server.project.ws;
+import javax.annotation.Nullable;
import org.sonar.api.server.ServerSide;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.organization.BillingValidations;
import org.sonar.server.organization.BillingValidationsProxy;
+import org.sonar.server.organization.DefaultOrganizationProvider;
import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
public static final String PARAM_ORGANIZATION = "organization";
private final DbClient dbClient;
-
+ private final DefaultOrganizationProvider organizationProvider;
private final BillingValidationsProxy billingValidations;
- public ProjectsWsSupport(DbClient dbClient, BillingValidationsProxy billingValidations) {
+ public ProjectsWsSupport(DbClient dbClient, DefaultOrganizationProvider organizationProvider, BillingValidationsProxy billingValidations) {
this.dbClient = dbClient;
+ this.organizationProvider = organizationProvider;
this.billingValidations = billingValidations;
}
.setSince("6.3");
}
- OrganizationDto getOrganization(DbSession dbSession, String organizationKey) {
+ OrganizationDto getOrganization(DbSession dbSession, @Nullable String organizationKeyParam) {
+ String organizationKey = organizationKeyParam == null ? organizationProvider.get().getKey() : organizationKeyParam;
return checkFoundWithOptional(
- dbClient.organizationDao().selectByKey(dbSession, organizationKey),
- "No organization for key '%s'", organizationKey);
+ dbClient.organizationDao().selectByKey(dbSession, organizationKey),
+ "No organization for key '%s'", organizationKey);
}
void checkCanUpdateProjectsVisibility(OrganizationDto organization, boolean newProjectsPrivate) {
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentQuery;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Common.Paging;
import org.sonarqube.ws.WsComponents.ProvisionedWsResponse;
public class ProvisionedAction implements ProjectsWsAction {
- private static final Set<String> QUALIFIERS_FILTER = newHashSet(Qualifiers.PROJECT);
private static final Set<String> POSSIBLE_FIELDS = newHashSet("uuid", "key", "name", "creationDate", "visibility");
private final ProjectsWsSupport support;
private final DbClient dbClient;
private final UserSession userSession;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public ProvisionedAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider) {
+ public ProvisionedAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession) {
this.support = support;
this.dbClient = dbClient;
this.userSession = userSession;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
}
@Override
String query = request.param(Param.TEXT_QUERY);
try (DbSession dbSession = dbClient.openSession(false)) {
- OrganizationDto organization = support.getOrganization(dbSession,
- request.getParam(PARAM_ORGANIZATION).or(defaultOrganizationProvider.get()::getKey));
+ OrganizationDto organization = support.getOrganization(dbSession, request.param(PARAM_ORGANIZATION));
userSession.checkPermission(PROVISION_PROJECTS, organization);
ComponentQuery dbQuery = buildDbQuery(query);
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.project.Visibility;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsProjects.SearchWsResponse;
import org.sonarqube.ws.client.project.SearchWsRequest;
import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Optional.ofNullable;
import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.VIEW;
private final DbClient dbClient;
private final UserSession userSession;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
private final ProjectsWsSupport support;
- public SearchAction(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider, ProjectsWsSupport support) {
+ public SearchAction(DbClient dbClient, UserSession userSession, ProjectsWsSupport support) {
this.dbClient = dbClient;
this.userSession = userSession;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
this.support = support;
}
private SearchWsResponse doHandle(SearchWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization()).orElseGet(defaultOrganizationProvider.get()::getKey));
+ OrganizationDto organization = support.getOrganization(dbSession, request.getOrganization());
userSession.checkPermission(OrganizationPermission.ADMINISTER, organization);
ComponentQuery query = buildDbQuery(request);
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.BillingValidationsProxy;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
private ComponentCleanerService componentCleanerService = mock(ComponentCleanerService.class);
private WsTester ws;
private DbClient dbClient = db.getDbClient();
- private BulkDeleteAction underTest = new BulkDeleteAction(componentCleanerService, dbClient, userSession, new ProjectsWsSupport(dbClient, mock(BillingValidationsProxy.class)));
+ private ProjectsWsSupport support = new ProjectsWsSupport(dbClient, TestDefaultOrganizationProvider.from(db), mock(BillingValidationsProxy.class));
+ private BulkDeleteAction underTest = new BulkDeleteAction(componentCleanerService, dbClient, userSession, support);
private OrganizationDto org1;
private OrganizationDto org2;
private TestProjectIndexers projectIndexers = new TestProjectIndexers();
private WsActionTester ws = new WsActionTester(
new CreateAction(
- new ProjectsWsSupport(db.getDbClient(), billingValidations),
+ new ProjectsWsSupport(db.getDbClient(), defaultOrganizationProvider, billingValidations),
db.getDbClient(), userSession,
new ComponentUpdater(db.getDbClient(), i18n, system2, mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()),
- projectIndexers),
- defaultOrganizationProvider));
+ projectIndexers)
+ ));
@Test
public void create_project() throws Exception {
private DbClient dbClient = db.getDbClient();
private WsActionTester ws = new WsActionTester(
- new ProvisionedAction(new ProjectsWsSupport(dbClient, mock(BillingValidationsProxy.class)), dbClient, userSessionRule, defaultOrganizationProvider));
+ new ProvisionedAction(new ProjectsWsSupport(dbClient, defaultOrganizationProvider, mock(BillingValidationsProxy.class)), dbClient, userSessionRule));
@Test
public void definition() {
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private WsActionTester ws = new WsActionTester(
- new SearchAction(db.getDbClient(), userSession, defaultOrganizationProvider, new ProjectsWsSupport(db.getDbClient(), mock(BillingValidationsProxy.class))));
+ new SearchAction(db.getDbClient(), userSession, new ProjectsWsSupport(db.getDbClient(), defaultOrganizationProvider, mock(BillingValidationsProxy.class))));
@Test
public void search_by_key_query_with_partial_match_case_insensitive() throws IOException {
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.BillingValidations;
import org.sonar.server.organization.BillingValidationsProxy;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.permission.index.FooIndexDefinition;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
private TestProjectIndexers projectIndexers = new TestProjectIndexers();
private BillingValidationsProxy billingValidations = mock(BillingValidationsProxy.class);
- private ProjectsWsSupport wsSupport = new ProjectsWsSupport(dbClient, billingValidations);
+ private ProjectsWsSupport wsSupport = new ProjectsWsSupport(dbClient, TestDefaultOrganizationProvider.from(dbTester), billingValidations);
private UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, TestComponentFinder.from(dbTester), userSessionRule, projectIndexers, wsSupport);
private WsActionTester actionTester = new WsActionTester(underTest);