Skip to content

Commit

Permalink
Restructure isSuperUser check to account for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljdelight committed Nov 20, 2023
1 parent 17a98d1 commit a980220
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions app/org/maproulette/permissions/Permission.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ class Permission @Inject() (
* Determines if the given user has been configured as a superuser
*/
def isSuperUser(user: User): Boolean = {
config.superAccounts.headOption match {
case Some("*") => true
case _ => serviceManager.user.isSuperUser(user.id)
}
// Check if the user is the system super user (id=-999)
if (user.id == User.DEFAULT_SUPER_USER_ID) true
else
config.superAccounts match {
case List("*") if config.isDevMode => true
case _ => serviceManager.user.isSuperUser(user.id)
}
}

private def getItem(
Expand Down
2 changes: 1 addition & 1 deletion test/org/maproulette/utils/TestSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ trait TestSpec extends PlaySpec with MockitoSugar {

// Mocks for users
when(this.userService.retrieve(-999L)).thenReturn(Some(User.superUser))
// when(this.userService.isSuperUser(-999L)).thenReturn(true)
when(this.userService.isSuperUser(-999L)).thenReturn(true)
when(this.userService.retrieve(-998L)).thenReturn(Some(User.guestUser))
doAnswer(_ => Some(User.superUser)).when(this.userService).retrieve(-999L)
when(this.userService.retrieve(-1L)).thenReturn(Some(User.guestUser))
Expand Down

0 comments on commit a980220

Please sign in to comment.