diff --git a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/domain/topic/validator/TopicValidator.java b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/domain/topic/validator/TopicValidator.java index fd1e22d8d..eaa69ef2c 100644 --- a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/domain/topic/validator/TopicValidator.java +++ b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/domain/topic/validator/TopicValidator.java @@ -9,7 +9,6 @@ import pl.allegro.tech.hermes.api.RetentionTime; import pl.allegro.tech.hermes.api.Topic; import pl.allegro.tech.hermes.management.api.validator.ApiPreconditions; -import pl.allegro.tech.hermes.management.config.TopicProperties; import pl.allegro.tech.hermes.management.domain.auth.RequestUser; import pl.allegro.tech.hermes.management.domain.owner.validator.OwnerIdValidator; import pl.allegro.tech.hermes.management.domain.topic.CreatorRights; @@ -28,21 +27,18 @@ public class TopicValidator { private final TopicLabelsValidator topicLabelsValidator; private final SchemaRepository schemaRepository; private final ApiPreconditions apiPreconditions; - private final TopicProperties topicProperties; @Autowired public TopicValidator(OwnerIdValidator ownerIdValidator, ContentTypeValidator contentTypeValidator, TopicLabelsValidator topicLabelsValidator, SchemaRepository schemaRepository, - ApiPreconditions apiPreconditions, - TopicProperties topicProperties) { + ApiPreconditions apiPreconditions) { this.ownerIdValidator = ownerIdValidator; this.contentTypeValidator = contentTypeValidator; this.topicLabelsValidator = topicLabelsValidator; this.schemaRepository = schemaRepository; this.apiPreconditions = apiPreconditions; - this.topicProperties = topicProperties; } public void ensureCreatedTopicIsValid(Topic created, RequestUser createdBy, CreatorRights creatorRights) { @@ -51,8 +47,8 @@ public void ensureCreatedTopicIsValid(Topic created, RequestUser createdBy, Crea checkContentType(created); checkTopicLabels(created); - if ((created.isFallbackToRemoteDatacenterEnabled() != topicProperties.isDefaultFallbackToRemoteDatacenterEnabled()) && !createdBy.isAdmin()) { - throw new TopicValidationException("User is not allowed to set non-default fallback to remote datacenter for this topic"); + if (created.isFallbackToRemoteDatacenterEnabled() && !createdBy.isAdmin()) { + throw new TopicValidationException("User is not allowed to enable fallback to remote datacenter"); } if (created.getChaos().mode() != ChaosMode.DISABLED && !createdBy.isAdmin()) { @@ -76,8 +72,8 @@ public void ensureUpdatedTopicIsValid(Topic updated, Topic previous, RequestUser checkOwner(updated); checkTopicLabels(updated); - if ((previous.isFallbackToRemoteDatacenterEnabled() != updated.isFallbackToRemoteDatacenterEnabled()) && !modifiedBy.isAdmin()) { - throw new TopicValidationException("User is not allowed to update fallback to remote datacenter for this topic"); + if (!previous.isFallbackToRemoteDatacenterEnabled() && updated.isFallbackToRemoteDatacenterEnabled() && !modifiedBy.isAdmin()) { + throw new TopicValidationException("User is not allowed to enable fallback to remote datacenter"); } if (!previous.getChaos().equals(updated.getChaos()) && !modifiedBy.isAdmin()) { diff --git a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/TopicManagementTest.java b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/TopicManagementTest.java index 461492ccd..d097604b4 100644 --- a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/TopicManagementTest.java +++ b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/TopicManagementTest.java @@ -603,7 +603,7 @@ public void shouldCreateTopicEvenIfExistsInBrokers() { } @Test - public void shouldNotAllowNonAdminUserCreateTopicWithNonDefaultFallbackToRemoteDatacenter() { + public void shouldNotAllowNonAdminUserCreateTopicWithFallbackToRemoteDatacenterEnabled() { // given TestSecurityProvider.setUserIsAdmin(false); TopicWithSchema topic = topicWithSchema( @@ -619,11 +619,11 @@ public void shouldNotAllowNonAdminUserCreateTopicWithNonDefaultFallbackToRemoteD //then response.expectStatus().isBadRequest(); assertThat(response.expectBody(String.class).returnResult().getResponseBody()) - .contains("User is not allowed to set non-default fallback to remote datacenter"); + .contains("User is not allowed to enable fallback to remote datacenter"); } @Test - public void shouldAllowAdminUserCreateTopicWithNonDefaultFallbackToRemoteDatacenterEnabled() { + public void shouldAllowAdminUserCreateTopicWithFallbackToRemoteDatacenterEnabled() { // given TestSecurityProvider.setUserIsAdmin(true); TopicWithSchema topic = topicWithSchema( @@ -641,12 +641,11 @@ public void shouldAllowAdminUserCreateTopicWithNonDefaultFallbackToRemoteDatacen } @Test - public void shouldNotAllowNonAdminUserToChangeFallbackToRemoteDatacenter() { + public void shouldNotAllowNonAdminUserToEnableFallbackToRemoteDatacenter() { // given - Topic topic = hermes.initHelper().createTopic(topicWithRandomName() - .withFallbackToRemoteDatacenterEnabled().build()); + Topic topic = hermes.initHelper().createTopic(topicWithRandomName().build()); TestSecurityProvider.setUserIsAdmin(false); - PatchData patchData = PatchData.from(ImmutableMap.of("fallbackToRemoteDatacenterEnabled", false)); + PatchData patchData = PatchData.from(ImmutableMap.of("fallbackToRemoteDatacenterEnabled", true)); // when WebTestClient.ResponseSpec response = hermes.api().updateTopic(topic.getQualifiedName(), patchData); @@ -654,17 +653,15 @@ public void shouldNotAllowNonAdminUserToChangeFallbackToRemoteDatacenter() { //then response.expectStatus().isBadRequest(); assertThat(response.expectBody(String.class).returnResult().getResponseBody()) - .contains("User is not allowed to update fallback to remote datacenter for this topic"); + .contains("User is not allowed to enable fallback to remote datacenter"); } @Test - public void shouldAllowAdminUserToChangeFallbackToRemoteDatacenter() { + public void shouldAllowAdminUserToEnableFallbackToRemoteDatacenter() { // given - Topic topic = hermes.initHelper().createTopic(topicWithRandomName() - .withFallbackToRemoteDatacenterEnabled() - .build()); + Topic topic = hermes.initHelper().createTopic(topicWithRandomName().build()); TestSecurityProvider.setUserIsAdmin(true); - PatchData patchData = PatchData.from(ImmutableMap.of("fallbackToRemoteDatacenterEnabled", false)); + PatchData patchData = PatchData.from(ImmutableMap.of("fallbackToRemoteDatacenterEnabled", true)); // when WebTestClient.ResponseSpec response = hermes.api().updateTopic(topic.getQualifiedName(), patchData);