-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SW-4242 Admin UI feature to assign Terraformation Contact (nice to ha…
…ve feature) (#1374) - introduced `assignTerraformationContact` function in OrganizationService which handles removing existing contact and assigning new contact - updated AdminController and Admin UI to show/reassign Terraformation Contact (made some assumptions here as this is an interim solution) - caveat, super admin needs to be part of the org in order to assign a Terraformation Contact (for now at least)
- Loading branch information
Karthik B
authored
Sep 21, 2023
1 parent
bb5be4a
commit e243817
Showing
7 changed files
with
215 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ import com.terraformation.backend.customer.model.SystemUser | |
import com.terraformation.backend.customer.model.TerrawareUser | ||
import com.terraformation.backend.db.DatabaseTest | ||
import com.terraformation.backend.db.OrganizationHasOtherUsersException | ||
import com.terraformation.backend.db.UserNotFoundException | ||
import com.terraformation.backend.db.UserNotFoundForEmailException | ||
import com.terraformation.backend.db.default_schema.OrganizationId | ||
import com.terraformation.backend.db.default_schema.Role | ||
import com.terraformation.backend.db.default_schema.UserId | ||
|
@@ -43,6 +45,7 @@ import org.jooq.Table | |
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNotEquals | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
import org.junit.jupiter.api.Assertions.assertNull | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
@@ -276,4 +279,94 @@ internal class OrganizationServiceTest : DatabaseTest(), RunsAsUser { | |
UserAddedToTerrawareEvent( | ||
userId = newUser!!.userId, organizationId = organizationId, addedBy = user.userId))) | ||
} | ||
|
||
@Test | ||
fun `assigning a Terraformation Contact throws exception without permission`() { | ||
every { user.canAddTerraformationContact(organizationId) } returns false | ||
assertThrows<AccessDeniedException> { | ||
service.assignTerraformationContact("[email protected]", organizationId) | ||
} | ||
} | ||
|
||
@Test | ||
fun `assigning a Terraformation Contact throws exception when user does not exist`() { | ||
every { user.canAddTerraformationContact(organizationId) } returns true | ||
assertThrows<UserNotFoundForEmailException> { | ||
service.assignTerraformationContact("[email protected]", organizationId) | ||
} | ||
} | ||
|
||
@Test | ||
fun `assigns a brand new Terraformation Contact`() { | ||
insertUser(user.userId) | ||
insertUser(userId = UserId(5), email = "[email protected]") | ||
insertOrganization(organizationId) | ||
|
||
assertNull( | ||
organizationStore.fetchTerraformationContact(organizationId), | ||
"Should not find a Terraformation Contact") | ||
|
||
every { user.canAddTerraformationContact(organizationId) } returns true | ||
|
||
val result = service.assignTerraformationContact("[email protected]", organizationId) | ||
assertNotNull(result, "Should have a valid result") | ||
assertEquals( | ||
organizationStore.fetchTerraformationContact(organizationId), | ||
result, | ||
"Should find a matching Terraformation Contact") | ||
} | ||
|
||
@Test | ||
fun `removes existing Terraformation Contact and assigns a new one`() { | ||
insertUser(user.userId) | ||
insertUser(userId = UserId(5), email = "[email protected]") | ||
insertUser(userId = UserId(6), email = "[email protected]") | ||
insertOrganization(organizationId) | ||
|
||
every { user.canAddTerraformationContact(organizationId) } returns true | ||
every { user.canRemoveTerraformationContact(organizationId) } returns true | ||
|
||
val userToRemove = | ||
service.assignTerraformationContact("[email protected]", organizationId) | ||
assertNotNull(userToRemove, "Should have a valid result") | ||
val reassignedUser = | ||
service.assignTerraformationContact("[email protected]", organizationId) | ||
assertNotNull(reassignedUser, "Should have a valid new result") | ||
assertEquals( | ||
organizationStore.fetchTerraformationContact(organizationId), | ||
reassignedUser, | ||
"Should find a matching Terraformation Contact") | ||
assertThrows<UserNotFoundException> { | ||
organizationStore.fetchUser(organizationId, userToRemove) | ||
} | ||
} | ||
|
||
@Test | ||
fun `removes existing Terraformation Contact and sets the role for reassigned Terraformation Contact if user already exists`() { | ||
insertUser(user.userId) | ||
insertUser(userId = UserId(5), email = "[email protected]") | ||
insertOrganization(organizationId) | ||
|
||
every { user.canAddTerraformationContact(organizationId) } returns true | ||
every { user.canRemoveTerraformationContact(organizationId) } returns true | ||
every { user.canSetTerraformationContact(organizationId) } returns true | ||
every { user.canAddOrganizationUser(organizationId) } returns true | ||
every { user.canSetOrganizationUserRole(organizationId, Role.Admin) } returns true | ||
|
||
val adminUser = service.addUser("[email protected]", organizationId, Role.Admin) | ||
assertNotNull(adminUser, "Should have a valid result") | ||
val userToRemove = | ||
service.assignTerraformationContact("[email protected]", organizationId) | ||
assertNotNull(userToRemove, "Should have a valid result") | ||
val reassignedUser = | ||
service.assignTerraformationContact("[email protected]", organizationId) | ||
assertEquals(adminUser, reassignedUser, "Should reassign role on existing user") | ||
assertEquals( | ||
organizationStore.fetchTerraformationContact(organizationId), | ||
reassignedUser, | ||
"Should find a matching Terraformation Contact") | ||
assertThrows<UserNotFoundException> { | ||
organizationStore.fetchUser(organizationId, userToRemove) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters