aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lièvremont <jb.lievremont@gmail.com>2019-01-10 14:40:39 +0100
committerSonarTech <sonartech@sonarsource.com>2019-01-18 20:21:03 +0100
commitc173166cd399c3d5b93381a0a98244c1baf73650 (patch)
treee59e780b907f9628b40a663816c8f9571d9cce5a
parent5c110414621fcfb2db1083f76ff09c4b6364757f (diff)
downloadsonarqube-c173166cd399c3d5b93381a0a98244c1baf73650.tar.gz
sonarqube-c173166cd399c3d5b93381a0a98244c1baf73650.zip
SONARCLOUD-312 Use key instead of UUID to send downgrade feedback (#1140)
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java2
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/organization/BillingValidations.java8
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/organization/BillingValidationsProxyImplTest.java29
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java2
8 files changed, 27 insertions, 25 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java
index aa2d15a9926..bcf7b193e59 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java
@@ -43,7 +43,7 @@ public class VerifyBillingStep implements ComputationStep {
public void execute(ComputationStep.Context context) {
try {
Organization organization = analysisMetadata.getOrganization();
- BillingValidations.Organization billingOrganization = new BillingValidations.Organization(organization.getKey(), organization.getUuid());
+ BillingValidations.Organization billingOrganization = new BillingValidations.Organization(organization.getKey(), organization.getUuid(), organization.getName());
billingValidations.checkBeforeProjectAnalysis(billingOrganization);
} catch (BillingValidations.BillingValidationsException e) {
throw MessageException.of(e.getMessage());
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java
index 37dc38d55e1..0001f84f8f2 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java
@@ -76,6 +76,8 @@ public class VerifyBillingStepTest {
verify(validations).checkBeforeProjectAnalysis(orgCaptor.capture());
BillingValidations.Organization calledOrg = orgCaptor.getValue();
assertThat(calledOrg.getKey()).isEqualTo(organization.getKey());
+ assertThat(calledOrg.getUuid()).isEqualTo(organization.getUuid());
+ assertThat(calledOrg.getName()).isEqualTo(organization.getName());
}
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/organization/BillingValidations.java b/server/sonar-server-common/src/main/java/org/sonar/server/organization/BillingValidations.java
index d8a765b2f38..a10acbe3d10 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/organization/BillingValidations.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/organization/BillingValidations.java
@@ -57,10 +57,12 @@ public interface BillingValidations {
class Organization {
private final String key;
private final String uuid;
+ private final String name;
- public Organization(String key, String uuid) {
+ public Organization(String key, String uuid, String name) {
this.key = requireNonNull(key, "Organization key cannot be null");
this.uuid = requireNonNull(uuid, "Organization uuid cannot be null");
+ this.name = requireNonNull(name, "Organization name cannot be null");
}
public String getKey() {
@@ -70,6 +72,10 @@ public interface BillingValidations {
public String getUuid() {
return uuid;
}
+
+ public String getName() {
+ return name;
+ }
}
class BillingValidationsException extends MessageException {
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/organization/BillingValidationsProxyImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/organization/BillingValidationsProxyImplTest.java
index c9039fb626e..46e574a186e 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/organization/BillingValidationsProxyImplTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/organization/BillingValidationsProxyImplTest.java
@@ -30,8 +30,7 @@ import static org.sonar.server.organization.BillingValidations.Organization;
public class BillingValidationsProxyImplTest {
- private static String ORGANIZATION_KEY = "ORGANIZATION_KEY";
- private static String ORGANIZATION_UUID = "ORGANIZATION_UUID";
+ private static final Organization ORGANIZATION = new Organization("ORGANIZATION_KEY", "ORGANIZATION_UUID", "ORGANIZATION_NAME");
private BillingValidationsExtension billingValidationsExtension = mock(BillingValidationsExtension.class);
@@ -40,19 +39,17 @@ public class BillingValidationsProxyImplTest {
@Test
public void checkOnProjectAnalysis_calls_extension_when_available() {
underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
- Organization organization = new Organization(ORGANIZATION_KEY, ORGANIZATION_UUID);
- underTest.checkBeforeProjectAnalysis(organization);
+ underTest.checkBeforeProjectAnalysis(ORGANIZATION);
- verify(billingValidationsExtension).checkBeforeProjectAnalysis(organization);
+ verify(billingValidationsExtension).checkBeforeProjectAnalysis(ORGANIZATION);
}
@Test
public void checkOnProjectAnalysis_does_nothing_when_no_extension_available() {
underTest = new BillingValidationsProxyImpl();
- Organization organization = new Organization(ORGANIZATION_KEY, ORGANIZATION_UUID);
- underTest.checkBeforeProjectAnalysis(organization);
+ underTest.checkBeforeProjectAnalysis(ORGANIZATION);
verifyZeroInteractions(billingValidationsExtension);
}
@@ -60,19 +57,17 @@ public class BillingValidationsProxyImplTest {
@Test
public void checkCanUpdateProjectsVisibility_calls_extension_when_available() {
underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
- Organization organization = new Organization(ORGANIZATION_KEY, ORGANIZATION_UUID);
- underTest.checkCanUpdateProjectVisibility(organization, true);
+ underTest.checkCanUpdateProjectVisibility(ORGANIZATION, true);
- verify(billingValidationsExtension).checkCanUpdateProjectVisibility(organization, true);
+ verify(billingValidationsExtension).checkCanUpdateProjectVisibility(ORGANIZATION, true);
}
@Test
public void checkCanUpdateProjectsVisibility_does_nothing_when_no_extension_available() {
underTest = new BillingValidationsProxyImpl();
- Organization organization = new Organization(ORGANIZATION_KEY, ORGANIZATION_UUID);
- underTest.checkCanUpdateProjectVisibility(organization, true);
+ underTest.checkCanUpdateProjectVisibility(ORGANIZATION, true);
verifyZeroInteractions(billingValidationsExtension);
}
@@ -80,21 +75,19 @@ public class BillingValidationsProxyImplTest {
@Test
public void canUpdateProjectsVisibilityToPrivate_calls_extension_when_available() {
underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
- Organization organization = new Organization(ORGANIZATION_KEY, ORGANIZATION_UUID);
- when(billingValidationsExtension.canUpdateProjectVisibilityToPrivate(organization)).thenReturn(false);
+ when(billingValidationsExtension.canUpdateProjectVisibilityToPrivate(ORGANIZATION)).thenReturn(false);
- boolean result = underTest.canUpdateProjectVisibilityToPrivate(organization);
+ boolean result = underTest.canUpdateProjectVisibilityToPrivate(ORGANIZATION);
assertThat(result).isFalse();
- verify(billingValidationsExtension).canUpdateProjectVisibilityToPrivate(organization);
+ verify(billingValidationsExtension).canUpdateProjectVisibilityToPrivate(ORGANIZATION);
}
@Test
public void canUpdateProjectsVisibilityToPrivate_return_true_when_no_extension() {
underTest = new BillingValidationsProxyImpl();
- Organization organization = new Organization(ORGANIZATION_KEY, ORGANIZATION_UUID);
- boolean result = underTest.canUpdateProjectVisibilityToPrivate(organization);
+ boolean result = underTest.canUpdateProjectVisibilityToPrivate(ORGANIZATION);
assertThat(result).isTrue();
verifyZeroInteractions(billingValidationsExtension);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
index 017decc9c1e..f02b990843b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
@@ -122,7 +122,7 @@ public class DeleteAction implements OrganizationsWsAction {
deleteQualityGates(dbSession, organization);
deleteOrganizationAlmBinding(dbSession, organization);
deleteOrganization(dbSession, organization);
- billingValidations.onDelete(new BillingValidations.Organization(organization.getKey(), organization.getUuid()));
+ billingValidations.onDelete(new BillingValidations.Organization(organization.getKey(), organization.getUuid(), organization.getName()));
response.noContent();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
index 3366f711bf9..fcbfe4cf3b4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
@@ -60,9 +60,10 @@ public class ProjectsWsSupport {
"No organization for key '%s'", organizationKey);
}
- void checkCanUpdateProjectsVisibility(OrganizationDto organization, boolean newProjectsPrivate) {
+ void checkCanUpdateProjectsVisibility(OrganizationDto organizationDto, boolean newProjectsPrivate) {
try {
- billingValidations.checkCanUpdateProjectVisibility(new BillingValidations.Organization(organization.getKey(), organization.getUuid()), newProjectsPrivate);
+ BillingValidations.Organization organization = new BillingValidations.Organization(organizationDto.getKey(), organizationDto.getUuid(), organizationDto.getName());
+ billingValidations.checkCanUpdateProjectVisibility(organization, newProjectsPrivate);
} catch (BillingValidations.BillingValidationsException e) {
throw new IllegalArgumentException(e.getMessage());
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
index 469ab761b3d..1429bb1cdcb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
@@ -314,7 +314,7 @@ public class ComponentAction implements NavigationWsAction {
json.prop("showBackgroundTasks", showBackgroundTasks);
json.prop("canApplyPermissionTemplate", isOrganizationAdmin);
json.prop("canUpdateProjectVisibilityToPrivate", isProjectAdmin &&
- billingValidations.canUpdateProjectVisibilityToPrivate(new BillingValidations.Organization(organization.getKey(), organization.getUuid())));
+ billingValidations.canUpdateProjectVisibilityToPrivate(new BillingValidations.Organization(organization.getKey(), organization.getUuid(), organization.getName())));
}
private boolean componentTypeHasProperty(ComponentDto component, String resourceTypeProperty) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java
index 2cc406e626f..a3df9cc4da0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java
@@ -117,7 +117,7 @@ public class OrganizationAction implements NavigationWsAction {
.prop("subscription", organization.getSubscription().name())
.prop("canUpdateProjectsVisibilityToPrivate",
userSession.hasPermission(ADMINISTER, organization) &&
- billingValidations.canUpdateProjectVisibilityToPrivate(new BillingValidations.Organization(organization.getKey(), organization.getUuid())));
+ billingValidations.canUpdateProjectVisibilityToPrivate(new BillingValidations.Organization(organization.getKey(), organization.getUuid(), organization.getName())));
writeAlm(json, organizationAlmBinding);
json.name("pages");
writePages(json, pageRepository.getOrganizationPages(false));