Skip to content

Commit

Permalink
feat: Allow project admins to create users which are not a system adm…
Browse files Browse the repository at this point in the history
…in (DEV-3266) (#3099)
  • Loading branch information
seakayone authored Mar 6, 2024
1 parent b56580d commit 79e1963
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,29 @@ class UsersADME2ESpec
}

"used to create a user" should {
"not allow a projectAdmin to create a System Admin" in {
val createUserRequest: String =
s"""{
| "username": "daisy.duck",
| "email": "[email protected]",
| "givenName": "Daisy",
| "familyName": "Duck",
| "password": "test",
| "status": true,
| "lang": "en",
| "systemAdmin": true
|}""".stripMargin

val request = Post(
baseApiUrl + s"/admin/users",
HttpEntity(ContentTypes.`application/json`, createUserRequest),
) ~> addProjectAdminUserCredentials()

val response: HttpResponse = singleAwaitingRequest(request)

response.status should be(StatusCodes.Forbidden)
}

"create the user if the supplied email and username are unique" in {
val createUserRequest: String =
s"""{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ final case class UsersRestService(

def createUser(requestingUser: User, userCreateRequest: Requests.UserCreateRequest): Task[UserResponseADM] =
for {
_ <- auth.ensureSystemAdmin(requestingUser)
_ <- if (userCreateRequest.systemAdmin.value) { auth.ensureSystemAdmin(requestingUser) }
else { auth.ensureSystemAdminOrProjectAdminInAnyProject(requestingUser) }
internal <- knoraUserService.createNewUser(userCreateRequest)
external <- asExternalUserResponseADM(requestingUser, internal)
} yield external
Expand Down

0 comments on commit 79e1963

Please sign in to comment.