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

Add second (non-admin) default user to "initial data" trigger #6666

Merged
merged 7 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions app/controllers/InitialDataController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class InitialDataService @Inject()(userService: UserService,
implicit val ctx: GlobalAccessContext.type = GlobalAccessContext

private val defaultUserEmail = conf.WebKnossos.SampleOrganization.User.email
private val defaultUserEmail2 = conf.WebKnossos.SampleOrganization.User.email2
private val defaultUserPassword = conf.WebKnossos.SampleOrganization.User.password
private val defaultUserToken = conf.WebKnossos.SampleOrganization.User.token
private val additionalInformation = """**Sample Organization**
Expand All @@ -75,9 +76,11 @@ Samplecountry
PricingPlan.Custom,
ObjectId.generate)
private val organizationTeam =
Team(organizationTeamId, defaultOrganization._id, defaultOrganization.name, isOrganizationTeam = true)
Team(organizationTeamId, defaultOrganization._id, "Default", isOrganizationTeam = true)
private val userId = ObjectId.generate
private val multiUserId = ObjectId.generate
private val userId2 = ObjectId.generate
private val multiUserId2 = ObjectId.generate
private val defaultMultiUser = MultiUser(
multiUserId,
defaultUserEmail,
Expand All @@ -99,6 +102,27 @@ Samplecountry
isDeactivated = false,
lastTaskTypeId = None
)
private val defaultMultiUser2 = MultiUser(
multiUserId2,
defaultUserEmail2,
userService.createPasswordInfo(defaultUserPassword),
isSuperUser = false,
)
private val defaultUser2 = User(
userId2,
multiUserId2,
defaultOrganization._id,
"Non-Admin",
"User",
System.currentTimeMillis(),
Json.obj(),
userService.createLoginInfo(userId2),
isAdmin = false,
isDatasetManager = false,
isUnlisted = false,
isDeactivated = false,
lastTaskTypeId = None
)
private val defaultPublication = Publication(
ObjectId("5c766bec6c01006c018c7459"),
Some(System.currentTimeMillis()),
Expand All @@ -119,7 +143,8 @@ Samplecountry
_ <- insertRootFolder()
_ <- insertOrganization()
_ <- insertTeams()
_ <- insertDefaultUser()
_ <- insertDefaultUser(defaultUserEmail, defaultMultiUser, defaultUser, true)
_ <- insertDefaultUser(defaultUserEmail2, defaultMultiUser2, defaultUser2, false)
_ <- insertToken()
_ <- insertTaskType()
_ <- insertProject()
Expand All @@ -143,19 +168,23 @@ Samplecountry
case _ => folderDAO.insertAsRoot(Folder(defaultOrganization._rootFolder, folderService.defaultRootName))
}

private def insertDefaultUser(): Fox[Unit] =
private def insertDefaultUser(userEmail: String,
multiUser: MultiUser,
user: User,
isTeamManager: Boolean): Fox[Unit] =
userService
.userFromMultiUserEmail(defaultUserEmail)
.userFromMultiUserEmail(userEmail)
.futureBox
.flatMap {
case Full(_) => Fox.successful(())
case _ =>
for {
_ <- multiUserDAO.insertOne(defaultMultiUser)
_ <- userDAO.insertOne(defaultUser)
_ <- userExperiencesDAO.updateExperiencesForUser(defaultUser, Map("sampleExp" -> 10))
_ <- userTeamRolesDAO.insertTeamMembership(defaultUser._id,
TeamMembership(organizationTeam._id, isTeamManager = true))
_ <- multiUserDAO.insertOne(multiUser)
_ <- userDAO.insertOne(user)
_ <- userExperiencesDAO.updateExperiencesForUser(user, Map("sampleExp" -> 10))
_ <- userTeamRolesDAO.insertTeamMembership(
user._id,
TeamMembership(organizationTeam._id, isTeamManager = isTeamManager))
_ = logger.info("Inserted default user")
} yield ()
}
Expand Down
1 change: 1 addition & 0 deletions app/utils/WkConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class WkConf @Inject()(configuration: Configuration) extends ConfigReader with L

object User {
val email: String = get[String]("webKnossos.sampleOrganization.user.email")
val email2: String = get[String]("webKnossos.sampleOrganization.user.email2")
val password: String = get[String]("webKnossos.sampleOrganization.user.password")
val token: String = get[String]("webKnossos.sampleOrganization.user.token")
val isSuperUser: Boolean = get[Boolean]("webKnossos.sampleOrganization.user.isSuperUser")
Expand Down
1 change: 1 addition & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ webKnossos {
enabled = true
user {
email = "[email protected]"
email2 = "[email protected]"
password = "secret"
token = "secretSampleUserToken"
isSuperUser = true
Expand Down