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;
|
||||
|
||||
import com.appsmith.external.helpers.AppsmithBeanUtils;
|
||||
import com.appsmith.server.acl.AclPermission;
|
||||
import com.appsmith.server.acl.AppsmithRole;
|
||||
import com.appsmith.server.acl.RoleGraph;
|
||||
|
|
@ -216,7 +217,22 @@ public class OrganizationServiceCEImpl extends BaseService<OrganizationRepositor
|
|||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -262,12 +262,11 @@ public class OrganizationServiceTest {
|
|||
|
||||
Mono<Organization> createOrganization = organizationService.create(organization);
|
||||
Mono<Organization> updateOrganization = createOrganization
|
||||
.map(t -> {
|
||||
t.setDomain("abc.com");
|
||||
return t;
|
||||
})
|
||||
.flatMap(t -> organizationService.update(t.getId(), t))
|
||||
.flatMap(t -> organizationService.getById(t.getId()));
|
||||
.flatMap(t -> {
|
||||
Organization newOrganization = new Organization();
|
||||
newOrganization.setDomain("abc.com");
|
||||
return organizationService.update(t.getId(), newOrganization);
|
||||
});
|
||||
|
||||
StepVerifier.create(updateOrganization)
|
||||
.assertNext(t -> {
|
||||
|
|
@ -280,6 +279,40 @@ public class OrganizationServiceTest {
|
|||
.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
|
||||
@WithUserDetails(value = "api_user")
|
||||
public void uniqueSlugs() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user