From 595101972d2abc86df6b781028e449c80b520a1d Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 30 May 2024 04:42:19 -0700 Subject: [PATCH] Pivotal ID # 186859974: Switch URl on basis of user upload mode (#831) https://www.pivotaltracker.com/story/show/186859974 - added home user type --- .../client/api/CommonOperationsClient.kt | 5 +++ .../client/integration/web/SubmitClient.kt | 2 ++ .../ebi/ac/uk/api/security/UserProfile.kt | 1 + .../PmcSingleSubmissionSubmitterTest.kt | 1 + .../pmc/submit/PmcSubmissionSubmitterTest.kt | 1 + .../integration/model/api/SecurityUser.kt | 9 +++-- .../itest/test/security/SecurityApiTest.kt | 36 +++++++++++++++++++ .../itestsInventory/itestsInventory.md | 2 ++ .../ebi/biostd/security/web/SecurityMapper.kt | 1 + 9 files changed, 56 insertions(+), 2 deletions(-) diff --git a/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/api/CommonOperationsClient.kt b/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/api/CommonOperationsClient.kt index 8f2fcef62a..5add8dca25 100644 --- a/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/api/CommonOperationsClient.kt +++ b/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/api/CommonOperationsClient.kt @@ -2,6 +2,7 @@ package ac.uk.ebi.biostd.client.api import ac.uk.ebi.biostd.client.integration.web.GeneralOperations import ebi.ac.uk.api.dto.UserGroupDto +import ebi.ac.uk.api.security.UserProfile import ebi.ac.uk.commons.http.builder.linkedMultiValueMapOf import ebi.ac.uk.commons.http.ext.RequestParams import ebi.ac.uk.commons.http.ext.getForObject @@ -47,4 +48,8 @@ class CommonOperationsClient( val body = linkedMapOf("groupName" to groupName, "userName" to userName) client.put(GROUP_URL, RequestParams(body = body)) } + + override fun getProfile(): UserProfile { + return client.getForObject("/auth/profile") + } } diff --git a/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/integration/web/SubmitClient.kt b/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/integration/web/SubmitClient.kt index 7cfaa8b88e..c170a7d2c3 100644 --- a/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/integration/web/SubmitClient.kt +++ b/client/bio-webclient/src/main/kotlin/ac/uk/ebi/biostd/client/integration/web/SubmitClient.kt @@ -153,6 +153,8 @@ interface GeneralOperations { groupName: String, userName: String, ) + + fun getProfile(): UserProfile } interface StatsOperations { diff --git a/commons/commons-bio/src/main/kotlin/ebi/ac/uk/api/security/UserProfile.kt b/commons/commons-bio/src/main/kotlin/ebi/ac/uk/api/security/UserProfile.kt index 06887de655..b193eee991 100644 --- a/commons/commons-bio/src/main/kotlin/ebi/ac/uk/api/security/UserProfile.kt +++ b/commons/commons-bio/src/main/kotlin/ebi/ac/uk/api/security/UserProfile.kt @@ -11,4 +11,5 @@ class UserProfile( val orcid: String, val allow: List, val deny: List, + val uploadType: String, ) diff --git a/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSingleSubmissionSubmitterTest.kt b/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSingleSubmissionSubmitterTest.kt index fc9eedad1a..5e474b1b56 100644 --- a/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSingleSubmissionSubmitterTest.kt +++ b/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSingleSubmissionSubmitterTest.kt @@ -96,6 +96,7 @@ internal class PmcSingleSubmissionSubmitterTest(private val tempFolder: Temporar "orcid" to "orcid" "allow" to jsonArray("allow") "deny" to jsonArray("deny") + "uploadType" to "nfs" }.toString(), ), ), diff --git a/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSubmissionSubmitterTest.kt b/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSubmissionSubmitterTest.kt index 2cee6c0578..c7555a043b 100644 --- a/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSubmissionSubmitterTest.kt +++ b/scheduler/tasks/pmc-processor-task/src/test/kotlin/ac/uk/ebi/pmc/submit/PmcSubmissionSubmitterTest.kt @@ -95,6 +95,7 @@ internal class PmcSubmissionSubmitterTest { "orcid" to "orcid" "allow" to jsonArray("allow") "deny" to jsonArray("deny") + "uploadType" to "nfs" }.toString(), ), ), diff --git a/submission/submission-security/src/main/kotlin/ebi/ac/uk/security/integration/model/api/SecurityUser.kt b/submission/submission-security/src/main/kotlin/ebi/ac/uk/security/integration/model/api/SecurityUser.kt index 05bf275956..650ee28821 100644 --- a/submission/submission-security/src/main/kotlin/ebi/ac/uk/security/integration/model/api/SecurityUser.kt +++ b/submission/submission-security/src/main/kotlin/ebi/ac/uk/security/integration/model/api/SecurityUser.kt @@ -25,6 +25,7 @@ data class SecurityPermission(val accessType: AccessType, val accessTag: String) sealed interface UserFolder { val relativePath: Path val path: Path + val type: String } data class FtpUserFolder( @@ -36,9 +37,13 @@ data class FtpUserFolder( * The File system ftp path. Used to access ftp files as file system file. */ override val path: Path, -) : UserFolder +) : UserFolder { + override val type = "ftp" +} -data class NfsUserFolder(override val relativePath: Path, override val path: Path) : UserFolder +data class NfsUserFolder(override val relativePath: Path, override val path: Path) : UserFolder { + override val type = "nfs" +} fun NfsUserFolder.resolve(subPath: String): Path = path.resolve(subPath) diff --git a/submission/submission-webapp/src/itest/kotlin/ac/uk/ebi/biostd/itest/test/security/SecurityApiTest.kt b/submission/submission-webapp/src/itest/kotlin/ac/uk/ebi/biostd/itest/test/security/SecurityApiTest.kt index 844f1cb132..16fc03a5be 100644 --- a/submission/submission-webapp/src/itest/kotlin/ac/uk/ebi/biostd/itest/test/security/SecurityApiTest.kt +++ b/submission/submission-webapp/src/itest/kotlin/ac/uk/ebi/biostd/itest/test/security/SecurityApiTest.kt @@ -2,11 +2,15 @@ package ac.uk.ebi.biostd.itest.test.security import ac.uk.ebi.biostd.client.exception.WebClientException import ac.uk.ebi.biostd.client.integration.web.SecurityWebClient +import ac.uk.ebi.biostd.itest.common.SecurityTestService +import ac.uk.ebi.biostd.itest.entities.FtpSuperUser import ac.uk.ebi.biostd.itest.entities.TestUser +import ac.uk.ebi.biostd.itest.itest.getWebClient import ac.uk.ebi.biostd.persistence.repositories.UserDataRepository import ebi.ac.uk.api.security.CheckUserRequest import ebi.ac.uk.api.security.LoginRequest import ebi.ac.uk.api.security.RegisterRequest +import kotlinx.coroutines.test.runTest import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.junit.jupiter.api.BeforeAll @@ -23,6 +27,7 @@ import kotlin.test.assertNotNull class SecurityApiTest( @LocalServerPort val serverPort: Int, @Autowired private val userDataRepository: UserDataRepository, + @Autowired val securityTestService: SecurityTestService, ) { private lateinit var webClient: SecurityWebClient @@ -74,6 +79,37 @@ class SecurityApiTest( assertThat(user.email).isEqualTo("case-insensitive-inactive@mail.org") } + @Test + fun `22-6 check ftp home type user`() = + runTest { + securityTestService.ensureUserRegistration(FtpSuperUser) + val client = getWebClient(serverPort, FtpSuperUser) + + val result = client.getProfile() + + assertThat(result.uploadType).isEqualTo("ftp") + } + + @Test + fun `22-7 check Nfs home type user`() = + runTest { + securityTestService.ensureUserRegistration(NfsUser) + val client = getWebClient(serverPort, NfsUser) + + val result = client.getProfile() + + assertThat(result.uploadType).isEqualTo("nfs") + } + + object NfsUser : TestUser { + override val username = "New Nfs User" + override val email = "new-nfs-biostudies-mgmt@ebi.ac.uk" + override val password = "12345" + override val superUser = true + + override fun asRegisterRequest() = RegisterRequest(username, email, password) + } + object NewUser : TestUser { override val username = "New User" override val email = "new-biostudies-mgmt@ebi.ac.uk" diff --git a/submission/submission-webapp/src/itest/resources/itestsInventory/itestsInventory.md b/submission/submission-webapp/src/itest/resources/itestsInventory/itestsInventory.md index 1a255c5c07..6dc44cf673 100644 --- a/submission/submission-webapp/src/itest/resources/itestsInventory/itestsInventory.md +++ b/submission/submission-webapp/src/itest/resources/itestsInventory/itestsInventory.md @@ -136,6 +136,8 @@ | SecurityApiTest | 22-3 | login when inactive | | | SecurityApiTest | 22-4 | case insensitive user registration | | | SecurityApiTest | 22-5 | case insensitive inactive registration | | +| SecurityApiTest | 22-6 | check ftp home type user | | +| SecurityApiTest | 22-7 | check Nfs home type user | | | SubmissionDraftListApiTest | 23-1 | get draft by key | Shows how to get drafts, paginated or not. | | SubmissionDraftListApiTest | 23-2 | get drafts without pagination | | | SubmissionDraftListApiTest | 23-3 | get drafts with pagination | | diff --git a/submission/submission-webapp/src/main/kotlin/ac/uk/ebi/biostd/security/web/SecurityMapper.kt b/submission/submission-webapp/src/main/kotlin/ac/uk/ebi/biostd/security/web/SecurityMapper.kt index 51bfb1479e..b715638df8 100644 --- a/submission/submission-webapp/src/main/kotlin/ac/uk/ebi/biostd/security/web/SecurityMapper.kt +++ b/submission/submission-webapp/src/main/kotlin/ac/uk/ebi/biostd/security/web/SecurityMapper.kt @@ -20,6 +20,7 @@ class SecurityMapper { orcid = user.orcid.orEmpty(), allow = getAllow(user), secret = user.userFolder.relativePath.toString(), + uploadType = user.userFolder.type, ) }