Skip to content

Commit

Permalink
refactor: Migrate user group endpoints to Tapir and remove UserRouteA…
Browse files Browse the repository at this point in the history
…DM (#3046)
  • Loading branch information
seakayone authored Feb 15, 2024
1 parent 5949e85 commit 52c798d
Show file tree
Hide file tree
Showing 24 changed files with 707 additions and 1,104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.knora.webapi.slice.admin.api.service.StoreRestService
import org.knora.webapi.slice.admin.api.service.UsersRestService
import org.knora.webapi.slice.admin.domain.service.*
import org.knora.webapi.slice.admin.repo.service.KnoraProjectRepoLive
import org.knora.webapi.slice.admin.repo.service.KnoraUserGroupRepoLive
import org.knora.webapi.slice.admin.repo.service.KnoraUserRepoLive
import org.knora.webapi.slice.common.api.*
import org.knora.webapi.slice.common.repo.service.PredicateObjectMapper
Expand Down Expand Up @@ -179,6 +180,7 @@ object LayersTest {
KnoraProjectRepoLive.layer,
KnoraResponseRenderer.layer,
KnoraUserRepoLive.layer,
KnoraUserGroupRepoLive.layer,
ListRestService.layer,
ListsEndpoints.layer,
ListsEndpointsHandlers.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,16 @@ class UsersADME2ESpec
}

"used to modify project membership" should {

"NOT add a user to project if the requesting user is not a SystemAdmin or ProjectAdmin" in {
val request = Post(
baseApiUrl + s"/admin/users/iri/${URLEncoder.encode(normalUser.id, "utf-8")}/project-memberships/$imagesProjectIriEnc"
) ~> addCredentials(BasicHttpCredentials(normalUser.email, "test654321"))
val response: HttpResponse = singleAwaitingRequest(request)

assert(response.status === StatusCodes.Forbidden)
}

"add user to project" in {
val membershipsBeforeUpdate = getUserProjectMemberships(normalUser.id)
membershipsBeforeUpdate should equal(Seq())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.knora.webapi.messages.admin.responder.usersmessages

import dsp.errors.BadRequestException
import org.knora.webapi.*
import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionProfileType
import org.knora.webapi.sharedtestdata.SharedTestDataADM
Expand Down Expand Up @@ -74,62 +73,4 @@ class UsersMessagesADMSpec extends CoreSpec {
)
}
}

"The ChangeUserApiRequestADM case class" should {

"throw a BadRequestException if number of parameters is wrong" in {

// all parameters are None
assertThrows[BadRequestException](
ChangeUserApiRequestADM()
)

val errorNoParameters = the[BadRequestException] thrownBy ChangeUserApiRequestADM()
errorNoParameters.getMessage should equal("No data sent in API request.")

// more than one parameter for status update
assertThrows[BadRequestException](
ChangeUserApiRequestADM(status = Some(true), systemAdmin = Some(true))
)

val errorTooManyParametersStatusUpdate =
the[BadRequestException] thrownBy ChangeUserApiRequestADM(status = Some(true), systemAdmin = Some(true))
errorTooManyParametersStatusUpdate.getMessage should equal("Too many parameters sent for change request.")

// more than one parameter for systemAdmin update
assertThrows[BadRequestException](
ChangeUserApiRequestADM(systemAdmin = Some(true), status = Some(true))
)

val errorTooManyParametersSystemAdminUpdate =
the[BadRequestException] thrownBy ChangeUserApiRequestADM(systemAdmin = Some(true), status = Some(true))
errorTooManyParametersSystemAdminUpdate.getMessage should equal("Too many parameters sent for change request.")

// more than 5 parameters for basic user information update
assertThrows[BadRequestException](
ChangeUserApiRequestADM(
username = Some("newUsername"),
email = Some("[email protected]"),
givenName = Some("newGivenName"),
familyName = Some("familyName"),
lang = Some("en"),
status = Some(true),
systemAdmin = Some(false)
)
)

val errorTooManyParametersBasicInformationUpdate = the[BadRequestException] thrownBy ChangeUserApiRequestADM(
username = Some("newUsername"),
email = Some("[email protected]"),
givenName = Some("newGivenName"),
familyName = Some("familyName"),
lang = Some("en"),
status = Some(true),
systemAdmin = Some(false)
)
errorTooManyParametersBasicInformationUpdate.getMessage should equal(
"Too many parameters sent for change request."
)
}
}
}
Loading

0 comments on commit 52c798d

Please sign in to comment.