Skip to content

Commit

Permalink
Merge branch 'main' into wip/continue-rdf-model
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt authored Feb 16, 2024
2 parents ea66703 + 61f04e0 commit 51fb1a5
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

package org.knora.webapi.responders.admin

import org.apache.pekko.actor.Status.Failure
import org.apache.pekko.testkit.ImplicitSender

import java.util.UUID

import dsp.errors.BadRequestException
import dsp.errors.DuplicateValueException
import dsp.errors.ForbiddenException
import dsp.valueobjects.LanguageCode
import org.knora.webapi.*
import org.knora.webapi.messages.StringFormatter
Expand All @@ -36,9 +34,8 @@ import org.knora.webapi.util.ZioScalaTestUtil.assertFailsWithA
*/
class UsersResponderSpec extends CoreSpec with ImplicitSender {

private val rootUser = SharedTestDataADM.rootUser
private val anythingAdminUser = SharedTestDataADM.anythingAdminUser
private val normalUser = SharedTestDataADM.normalUser
private val rootUser = SharedTestDataADM.rootUser
private val normalUser = SharedTestDataADM.normalUser

private val imagesProject = SharedTestDataADM.imagesProject
private val incunabulaProject = SharedTestDataADM.incunabulaProject
Expand All @@ -49,35 +46,19 @@ class UsersResponderSpec extends CoreSpec with ImplicitSender {
"The UsersResponder " when {
"asked about all users" should {
"return a list if asked by SystemAdmin" in {
appActor ! UsersGetRequestADM(
requestingUser = rootUser
)
val response = expectMsgType[UsersGetResponseADM](timeout)
val response = UnsafeZioRun.runOrThrow(UsersResponder.findAllUsers())
response.users.nonEmpty should be(true)
response.users.size should be(18)
}

"return a list if asked by ProjectAdmin" in {
appActor ! UsersGetRequestADM(
requestingUser = anythingAdminUser
)
val response = expectMsgType[UsersGetResponseADM](timeout)
val response = UnsafeZioRun.runOrThrow(UsersResponder.findAllUsers())
response.users.nonEmpty should be(true)
response.users.size should be(18)
}

"return 'ForbiddenException' if asked by normal user'" in {
appActor ! UsersGetRequestADM(
requestingUser = normalUser
)
expectMsg(timeout, Failure(ForbiddenException("ProjectAdmin or SystemAdmin permissions are required.")))
}

"not return the system and anonymous users" in {
appActor ! UsersGetRequestADM(
requestingUser = rootUser
)
val response = expectMsgType[UsersGetResponseADM](timeout)
val response = UnsafeZioRun.runOrThrow(UsersResponder.findAllUsers())
response.users.nonEmpty should be(true)
response.users.size should be(18)
response.users.count(_.id == KnoraSystemInstances.Users.AnonymousUser.id) should be(0)
Expand Down Expand Up @@ -169,7 +150,7 @@ class UsersResponderSpec extends CoreSpec with ImplicitSender {
password = Password.unsafeFrom("test"),
status = UserStatus.from(true),
lang = LanguageCode.en,
systemAdmin = SystemAdmin.from(false)
systemAdmin = SystemAdmin.IsNotSystemAdmin
),
apiRequestID = UUID.randomUUID
)
Expand All @@ -194,7 +175,7 @@ class UsersResponderSpec extends CoreSpec with ImplicitSender {
password = Password.unsafeFrom("test"),
status = UserStatus.from(true),
lang = LanguageCode.en,
systemAdmin = SystemAdmin.from(false)
systemAdmin = SystemAdmin.IsNotSystemAdmin
),
UUID.randomUUID
)
Expand All @@ -213,7 +194,7 @@ class UsersResponderSpec extends CoreSpec with ImplicitSender {
password = Password.unsafeFrom("test"),
status = UserStatus.from(true),
lang = LanguageCode.en,
systemAdmin = SystemAdmin.from(false)
systemAdmin = SystemAdmin.IsNotSystemAdmin
),
UUID.randomUUID
)
Expand Down Expand Up @@ -358,7 +339,7 @@ class UsersResponderSpec extends CoreSpec with ImplicitSender {
val response1 = UnsafeZioRun.runOrThrow(
UsersResponder.changeSystemAdmin(
SharedTestDataADM.normalUser.userIri,
SystemAdmin.from(true),
SystemAdmin.IsSystemAdmin,
UUID.randomUUID()
)
)
Expand All @@ -367,7 +348,7 @@ class UsersResponderSpec extends CoreSpec with ImplicitSender {
val response2 = UnsafeZioRun.runOrThrow(
UsersResponder.changeSystemAdmin(
SharedTestDataADM.normalUser.userIri,
SystemAdmin.from(false),
SystemAdmin.IsNotSystemAdmin,
UUID.randomUUID()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ import org.knora.webapi.slice.admin.domain.model.*
*/
sealed trait UsersResponderRequestADM extends KnoraRequestADM with RelayedMessage

/**
* Get all information about all users in form of [[UsersGetResponseADM]]. The UsersResponderRequestADM returns either
* something or a NotFound exception if there are no users found. Administration permission checking is performed.
*
* @param requestingUser the user initiating the request.
*/
case class UsersGetRequestADM(requestingUser: User) extends UsersResponderRequestADM

/**
* A message that requests a user's profile by IRI. A successful response will be a [[User]].
*
Expand Down
Loading

0 comments on commit 51fb1a5

Please sign in to comment.