Skip to content

Commit 70ad8ab

Browse files
committed
Add constraints on Organization
- organization's name is no longer required for updating an organization - organization's name should have size between 1 and 50 for creation or update
1 parent 8279dd9 commit 70ad8ab

File tree

5 files changed

+105
-33
lines changed

5 files changed

+105
-33
lines changed

doc/Models/OrganizationUpdateRequest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
| Name | Type | Description | Notes |
55
|------------ | ------------- | ------------- | -------------|
6-
| **name** | **String** | the Organization name | [default to null] |
6+
| **name** | **String** | the Organization name | [optional] [default to null] |
77

88
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
99

openapi/plantuml/schemas.plantuml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ entity OrganizationSecurity {
187187
}
188188

189189
entity OrganizationUpdateRequest {
190-
* name: String
190+
name: String
191191
}
192192

193193
entity QueryResult {

organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceIntegrationTest.kt

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,26 @@ class OrganizationServiceIntegrationTest : CsmRedisTestBase() {
283283
val name = "o-connector-test-1"
284284
val organizationRegistered =
285285
organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name))
286+
val newName ="my-new-name"
287+
val organizationUpdated = organizationApiService.updateOrganization(
288+
organizationRegistered.id, OrganizationUpdateRequest(newName))
286289

287-
organizationRegistered.name = "my-new-name"
288-
organizationApiService.updateOrganization(
289-
organizationRegistered.id, OrganizationUpdateRequest(organizationRegistered.name))
290+
assertEquals(
291+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
290292

291-
assertEquals(
292-
organizationRegistered,
293-
organizationApiService.getOrganization(organizationRegistered.id))
293+
// Update organization with empty body
294+
organizationApiService.updateOrganization(
295+
organizationUpdated.id, OrganizationUpdateRequest())
296+
297+
assertEquals(
298+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
299+
300+
// Update organization with null value as name
301+
organizationApiService.updateOrganization(
302+
organizationUpdated.id, OrganizationUpdateRequest(null))
303+
304+
assertEquals(
305+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
294306
}
295307
}
296308

@@ -306,13 +318,26 @@ class OrganizationServiceIntegrationTest : CsmRedisTestBase() {
306318

307319
runAsOrganizationUser()
308320

309-
organizationRegistered.name = "my-new-name"
310-
organizationApiService.updateOrganization(
311-
organizationRegistered.id, OrganizationUpdateRequest(organizationRegistered.name))
321+
val newName ="my-new-name"
322+
val organizationUpdated = organizationApiService.updateOrganization(
323+
organizationRegistered.id, OrganizationUpdateRequest(newName))
312324

313-
assertEquals(
314-
organizationRegistered,
315-
organizationApiService.getOrganization(organizationRegistered.id))
325+
assertEquals(
326+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
327+
328+
// Update organization with empty body
329+
organizationApiService.updateOrganization(
330+
organizationUpdated.id, OrganizationUpdateRequest())
331+
332+
assertEquals(
333+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
334+
335+
// Update organization with null value as name
336+
organizationApiService.updateOrganization(
337+
organizationUpdated.id, OrganizationUpdateRequest(null))
338+
339+
assertEquals(
340+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
316341
}
317342
}
318343

@@ -1214,16 +1239,29 @@ class OrganizationServiceIntegrationTest : CsmRedisTestBase() {
12141239
@Test
12151240
fun `updateOrganization as resource admin organization name`() {
12161241
assertDoesNotThrow {
1217-
val name = "o-connector-test-1"
1218-
val organizationRegistered =
1219-
organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name))
12201242

1221-
organizationRegistered.name = "my-new-name"
1222-
organizationApiService.updateOrganization(
1223-
organizationRegistered.id, OrganizationUpdateRequest("my-new-name"))
1243+
val organizationRegistered =
1244+
organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest("o-connector-test-1"))
1245+
val newName ="my-new-name"
1246+
val organizationUpdated = organizationApiService.updateOrganization(
1247+
organizationRegistered.id, OrganizationUpdateRequest(newName))
12241248

12251249
assertEquals(
1226-
organizationRegistered, organizationApiService.getOrganization(organizationRegistered.id))
1250+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
1251+
1252+
// Update organization with empty body
1253+
organizationApiService.updateOrganization(
1254+
organizationUpdated.id, OrganizationUpdateRequest())
1255+
1256+
assertEquals(
1257+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
1258+
1259+
// Update organization with null value as name
1260+
organizationApiService.updateOrganization(
1261+
organizationUpdated.id, OrganizationUpdateRequest(null))
1262+
1263+
assertEquals(
1264+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
12271265
}
12281266
}
12291267

@@ -1239,12 +1277,26 @@ class OrganizationServiceIntegrationTest : CsmRedisTestBase() {
12391277

12401278
runAsPlatformAdmin()
12411279

1242-
organizationRegistered.name = "my-new-name"
1243-
organizationApiService.updateOrganization(
1244-
organizationRegistered.id, OrganizationUpdateRequest(organizationRegistered.name))
1280+
val newName ="my-new-name"
1281+
val organizationUpdated = organizationApiService.updateOrganization(
1282+
organizationRegistered.id, OrganizationUpdateRequest(newName))
12451283

1246-
assertEquals(
1247-
organizationRegistered, organizationApiService.getOrganization(organizationRegistered.id))
1284+
assertEquals(
1285+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
1286+
1287+
// Update organization with empty body
1288+
organizationApiService.updateOrganization(
1289+
organizationUpdated.id, OrganizationUpdateRequest())
1290+
1291+
assertEquals(
1292+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
1293+
1294+
// Update organization with null value as name
1295+
organizationApiService.updateOrganization(
1296+
organizationUpdated.id, OrganizationUpdateRequest(null))
1297+
1298+
assertEquals(
1299+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
12481300
}
12491301
}
12501302

@@ -1256,8 +1308,26 @@ class OrganizationServiceIntegrationTest : CsmRedisTestBase() {
12561308
val organizationRegistered =
12571309
organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name))
12581310
runAsPlatformAdmin()
1259-
organizationApiService.updateOrganization(
1260-
organizationRegistered.id, OrganizationUpdateRequest("name"))
1311+
val newName ="my-new-name"
1312+
val organizationUpdated = organizationApiService.updateOrganization(
1313+
organizationRegistered.id, OrganizationUpdateRequest(newName))
1314+
1315+
assertEquals(
1316+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
1317+
1318+
// Update organization with empty body
1319+
organizationApiService.updateOrganization(
1320+
organizationUpdated.id, OrganizationUpdateRequest())
1321+
1322+
assertEquals(
1323+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
1324+
1325+
// Update organization with null value as name
1326+
organizationApiService.updateOrganization(
1327+
organizationUpdated.id, OrganizationUpdateRequest(null))
1328+
1329+
assertEquals(
1330+
newName, organizationApiService.getOrganization(organizationUpdated.id).name)
12611331
}
12621332
}
12631333

organization/src/main/openapi/organization.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ components:
469469
type: string
470470
x-field-extra-annotation: "@com.redis.om.spring.annotations.Searchable"
471471
description: the Organization name
472+
minLength: 1
473+
maxLength: 50
472474
security:
473475
$ref: '#/components/schemas/OrganizationSecurity'
474476
required:
@@ -481,8 +483,8 @@ components:
481483
name:
482484
type: string
483485
description: the Organization name
484-
required:
485-
- name
486+
minLength: 1
487+
maxLength: 50
486488

487489
# Security Operation Schemas
488490
OrganizationSecurity:

organization/src/test/kotlin/com/cosmotech/organization/service/OrganizationServiceImplTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class OrganizationServiceImplTests {
8181
val rbacSecurity =
8282
RbacSecurity(
8383
organization.id,
84-
organization.security.default!!,
84+
organization.security.default,
8585
mutableListOf(RbacAccessControl("ID", ROLE_VIEWER)))
8686
val rbacAccessControl = RbacAccessControl(USER_ID, ROLE_ADMIN)
8787
every { organizationRepository.findByIdOrNull(any()) } returns organization
@@ -91,9 +91,9 @@ class OrganizationServiceImplTests {
9191

9292
assertEquals(organization.security.default, rbacSecurity.default)
9393
assertEquals(
94-
organization.security.accessControlList!![0].id, rbacSecurity.accessControlList[0].id)
94+
organization.security.accessControlList[0].id, rbacSecurity.accessControlList[0].id)
9595
assertEquals(
96-
organization.security.accessControlList!![0].role, rbacSecurity.accessControlList[0].role)
96+
organization.security.accessControlList[0].role, rbacSecurity.accessControlList[0].role)
9797

9898
every { organizationRepository.save(any()) } returns organization
9999
every { csmRbac.getAccessControl(any(), any()) } returns rbacAccessControl

0 commit comments

Comments
 (0)