Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webapi): unique username/email check on change user #1561

Merged
merged 19 commits into from Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
98b8ba1
test(webapi): add unique username/email check to change user
LukasStoeckli Dec 17, 2019
4cb2450
Merge branch 'develop' into wip/fix-change-user
LukasStoeckli Dec 23, 2019
0b4cdee
fix(webapi): fix unique username and email check
LukasStoeckli Dec 23, 2019
1c8899e
fix(webapi): remove mean blocking awaits
LukasStoeckli Jan 7, 2020
4571343
fix(webapi): remove unnecessary comparison in change user
LukasStoeckli Jan 7, 2020
2901f7f
refactor(webapi): remove unused import
LukasStoeckli Jan 7, 2020
70a8759
Merge branch 'develop' into wip/fix-change-user
LukasStoeckli Jan 10, 2020
7c147bf
Merge branch 'develop' into wip/fix-change-user
subotic Feb 7, 2020
0985159
fix(webapi):check if requested email and username equal current values
LukasStoeckli Apr 27, 2020
ac7d4f7
merge develop into wip/fix-change-user
LukasStoeckli Apr 28, 2020
44e068c
fix(webapi): replace '""' with 'None' for values that don't exist
LukasStoeckli Apr 29, 2020
e8a4a8a
Merge branch 'develop' into wip/fix-change-user
Apr 30, 2020
2bcb8c9
Merge branch 'develop' into wip/fix-change-user
May 6, 2020
3e19738
Merge branch 'develop' into wip/fix-change-user
Jun 4, 2020
ec1f67c
refactor(UsersResponderADM): Avoid using Option.get.
Jun 4, 2020
908bafd
Merge branch 'develop' into wip/fix-change-user
Jun 9, 2020
3ce6c3f
test: Fix tests by making error messages consistent.
Jun 24, 2020
f83c5ac
Merge branch 'develop' into wip/fix-change-user
Jun 24, 2020
431b6e0
Merge branch 'develop' into wip/fix-change-user
Jun 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,7 +39,7 @@ import org.knora.webapi.util.IriConversions._
import org.knora.webapi.util.{InstrumentationSupport, SmartIri}
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder

import scala.concurrent.Future
import scala.concurrent.{Await, Future}

/**
* Provides information about Knora users to other responders.
Expand Down Expand Up @@ -261,28 +261,19 @@ class UsersResponderADM(responderData: ResponderData) extends Responder(responde

// check if we want to change the email
_ = if (changeUserRequest.email.isDefined) {
benjamingeer marked this conversation as resolved.
Show resolved Hide resolved
currentUserInformation.map { user =>
// check if current email differs from the one in the change request
if (!user.email.equals(changeUserRequest.email.get)) {
// check if new email is free
userByEmailExists(changeUserRequest.email.get).map(result =>
if (result) throw DuplicateValueException("A user with this email exists already. Cannot change")
)
}
val email = currentUserInformation.get.email
if (!email.equals(changeUserRequest.email.get)) {
val result = userByEmailExists(changeUserRequest.email.get)
benjamingeer marked this conversation as resolved.
Show resolved Hide resolved
if (Await.result(result, timeout.duration)) throw DuplicateValueException(s"User with the email: '${changeUserRequest.email.get}' already exists")
}
}

// check if we want to change the username
_ = if (changeUserRequest.username.isDefined) {
currentUserInformation.map { user =>
// check if the current username differs from the one in the change request
if (!user.username.equals(changeUserRequest.username.get)) {
// check if new username is free
userByUsernameExists(changeUserRequest.email.get).map(result =>
if (result) throw DuplicateValueException("A user with this username exists already. Cannot change")
)
}

val user = currentUserInformation.get.username
if (!user.equals(changeUserRequest.username.get)) {
val result = userByUsernameExists(changeUserRequest.username.get)
if (Await.result(result, timeout.duration)) throw DuplicateValueException(s"User with the username: '${changeUserRequest.username.get}' already exists")
}
}

Expand Down
Expand Up @@ -333,6 +333,30 @@ class UsersResponderADMSpec extends CoreSpec(UsersResponderADMSpec.config) with
response3.user.familyName should equal (SharedTestDataADM.normalUser.familyName)

}

"return a 'DuplicateValueException' if the supplied 'username' is not unique" in {
responderManager ! UserChangeBasicUserInformationRequestADM(
userIri = SharedTestDataADM.normalUser.id,
changeUserRequest = ChangeUserApiRequestADM(
username = Some("root")
),
SharedTestDataADM.superUser,
UUID.randomUUID
)
expectMsg(Failure(DuplicateValueException(s"User with the username: 'root' already exists")))
}

"return a 'DuplicateValueException' if the supplied 'email' is not unique" in {
responderManager ! UserChangeBasicUserInformationRequestADM(
userIri = SharedTestDataADM.normalUser.id,
changeUserRequest = ChangeUserApiRequestADM(
email = Some("root@example.com")
),
SharedTestDataADM.superUser,
UUID.randomUUID
)
expectMsg(Failure(DuplicateValueException(s"User with the email: 'root@example.com' already exists")))
}

"UPDATE the user's password (by himself)" in {
responderManager ! UserChangePasswordRequestADM(
Expand Down