fix: Organization name can be empty
fix: Organization name can be empty
This commit is contained in:
commit
c7a4ac7353
|
|
@ -1,5 +1,6 @@
|
||||||
package com.appsmith.server.services.ce;
|
package com.appsmith.server.services.ce;
|
||||||
|
|
||||||
|
import com.appsmith.external.helpers.AppsmithBeanUtils;
|
||||||
import com.appsmith.server.acl.AclPermission;
|
import com.appsmith.server.acl.AclPermission;
|
||||||
import com.appsmith.server.acl.AppsmithRole;
|
import com.appsmith.server.acl.AppsmithRole;
|
||||||
import com.appsmith.server.acl.RoleGraph;
|
import com.appsmith.server.acl.RoleGraph;
|
||||||
|
|
@ -216,7 +217,22 @@ public class OrganizationServiceCEImpl extends BaseService<OrganizationRepositor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Organization> update(String id, Organization resource) {
|
public Mono<Organization> update(String id, Organization resource) {
|
||||||
return repository.updateById(id, resource, MANAGE_ORGANIZATIONS)
|
Mono<Organization> findOrganizationMono = repository.findById(id, MANAGE_ORGANIZATIONS)
|
||||||
|
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, id)));
|
||||||
|
|
||||||
|
// In case the update is not used to update the policies, then set the policies to null to ensure that the
|
||||||
|
// existing policies are not overwritten.
|
||||||
|
if (resource.getPolicies().isEmpty()) {
|
||||||
|
resource.setPolicies(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return findOrganizationMono
|
||||||
|
.map(existingOrganization -> {
|
||||||
|
AppsmithBeanUtils.copyNewFieldValuesIntoOldObject(resource, existingOrganization);
|
||||||
|
return existingOrganization;
|
||||||
|
})
|
||||||
|
.flatMap(this::validateObject)
|
||||||
|
.flatMap(repository::save)
|
||||||
.flatMap(analyticsService::sendUpdateEvent);
|
.flatMap(analyticsService::sendUpdateEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,12 +262,11 @@ public class OrganizationServiceTest {
|
||||||
|
|
||||||
Mono<Organization> createOrganization = organizationService.create(organization);
|
Mono<Organization> createOrganization = organizationService.create(organization);
|
||||||
Mono<Organization> updateOrganization = createOrganization
|
Mono<Organization> updateOrganization = createOrganization
|
||||||
.map(t -> {
|
.flatMap(t -> {
|
||||||
t.setDomain("abc.com");
|
Organization newOrganization = new Organization();
|
||||||
return t;
|
newOrganization.setDomain("abc.com");
|
||||||
})
|
return organizationService.update(t.getId(), newOrganization);
|
||||||
.flatMap(t -> organizationService.update(t.getId(), t))
|
});
|
||||||
.flatMap(t -> organizationService.getById(t.getId()));
|
|
||||||
|
|
||||||
StepVerifier.create(updateOrganization)
|
StepVerifier.create(updateOrganization)
|
||||||
.assertNext(t -> {
|
.assertNext(t -> {
|
||||||
|
|
@ -280,6 +279,40 @@ public class OrganizationServiceTest {
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test tests for updating the organization with an empty name.
|
||||||
|
* The organization name should not be empty.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@WithUserDetails(value = "api_user")
|
||||||
|
public void inValidUpdateOrganizationEmptyName() {
|
||||||
|
Policy manageOrgAppPolicy = Policy.builder().permission(ORGANIZATION_MANAGE_APPLICATIONS.getValue())
|
||||||
|
.users(Set.of("api_user"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Policy manageOrgPolicy = Policy.builder().permission(MANAGE_ORGANIZATIONS.getValue())
|
||||||
|
.users(Set.of("api_user"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Organization organization = new Organization();
|
||||||
|
organization.setName("Test Update Name");
|
||||||
|
organization.setDomain("example.com");
|
||||||
|
organization.setWebsite("https://example.com");
|
||||||
|
organization.setSlug("test-update-name");
|
||||||
|
Mono<Organization> createOrganization = organizationService.create(organization);
|
||||||
|
Mono<Organization> updateOrganization = createOrganization
|
||||||
|
.flatMap(t -> {
|
||||||
|
Organization newOrganization = new Organization();
|
||||||
|
newOrganization.setName("");
|
||||||
|
return organizationService.update(t.getId(), newOrganization);
|
||||||
|
});
|
||||||
|
|
||||||
|
StepVerifier.create(updateOrganization)
|
||||||
|
.expectErrorMatches(throwable -> throwable instanceof AppsmithException &&
|
||||||
|
throwable.getMessage().equals(AppsmithError.INVALID_PARAMETER.getMessage(FieldName.NAME)))
|
||||||
|
.verify();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithUserDetails(value = "api_user")
|
@WithUserDetails(value = "api_user")
|
||||||
public void uniqueSlugs() {
|
public void uniqueSlugs() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user