Skip to content

Commit

Permalink
[pull] staging from SpongePowered:staging (#13)
Browse files Browse the repository at this point in the history
See [Commits](//pull/13/commits) and
[Changes](//pull/13/files) for more details.

-----
Created by [<img src="https://prod.download/pull-18h-svg"
valign="bottom"/> **pull[bot]**](https://github.com/wei/pull)

_Can you help keep this open source service alive? **[💖 Please sponsor :
)](https://prod.download/pull-pr-sponsor)**_
  • Loading branch information
LoboMetalurgico authored Nov 24, 2022
2 parents 7feaf61 + 868566c commit 834ce92
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
29 changes: 26 additions & 3 deletions orePlayCommon/app/db/impl/access/OrganizationBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package db.impl.access

import scala.language.higherKinds

import scala.concurrent.duration._

import ore.OreConfig
import ore.auth.SpongeAuthApi
import ore.auth.{AuthUser, SpongeAuthApi}
import ore.data.user.notification.NotificationType
import ore.db.access.ModelView
import ore.db.impl.OrePostgresDriver.api._
Expand All @@ -18,11 +20,12 @@ import util.syntax._

import cats.Parallel
import cats.data.{EitherT, NonEmptyList}
import cats.effect.Sync
import cats.effect.{Sync, Timer}
import cats.syntax.all._
import cats.tagless.autoFunctorK
import com.typesafe.scalalogging
import slick.lifted.TableQuery
import zio.Schedule

@autoFunctorK
trait OrganizationBase[+F[_]] {
Expand Down Expand Up @@ -60,7 +63,8 @@ object OrganizationBase {
config: OreConfig,
auth: SpongeAuthApi[F],
F: Sync[F],
par: Parallel[F]
par: Parallel[F],
timer: Timer[F]
) extends OrganizationBase[F] {

private val Logger = scalalogging.Logger("Organizations")
Expand Down Expand Up @@ -88,12 +92,31 @@ object OrganizationBase {
val dummyEmail = name.replaceAll("[^a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]", "") + '@' + config.ore.orgs.dummyEmailDomain
val spongeResult = EitherT.right[List[String]](logging) *> EitherT(auth.createDummyUser(name, dummyEmail))

def waitTilUserExists(authUser: AuthUser, sleepDur: FiniteDuration, sleptTime: FiniteDuration): F[Boolean] = {
val hasUser = ModelView.now(User).get(authUser.id).isDefined

//Do a quick check first if the user is already present
hasUser.flatMap {
case true => F.pure(true)
case false =>
if (sleptTime > 20.seconds) F.pure(false)
else timer.sleep(sleepDur) *> waitTilUserExists(authUser, sleepDur * 2, sleptTime + sleepDur * 2)
}
}

// Check for error
spongeResult
.leftMap { err =>
MDCLogger.debug("<FAILURE> " + err)
err
}
.flatMap { spongeUser =>
EitherT.right[List[String]](waitTilUserExists(spongeUser, 50.millis, 0.millis)).flatMap {
case true => EitherT.rightT[F, List[String]](spongeUser)
// Exit early if we never got the user
case false => EitherT.leftT[F, AuthUser](List("Timed out while waiting for SSO sync"))
}
}
.semiflatMap { spongeUser =>
MDCLogger.debug("<SUCCESS> " + spongeUser)
// Next we will create the Organization on Ore itself. This contains a
Expand Down
2 changes: 1 addition & 1 deletion project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Settings {
val scalaVer = "2.13.6"

val commonSettings = Seq(
version := "2.0.0-M2.8",
version := "2.0.0-M2.9",
scalaVersion := scalaVer,
scalacOptions ++= Seq(
"-deprecation",
Expand Down
2 changes: 1 addition & 1 deletion project/dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object Version {
val circeDerivation = "0.13.0-M5"

val akka = "2.6.15"
val akkaHttp = "10.1.14"
val akkaHttp = "10.1.15"
val scalaLogging = "3.9.4"

val simulacrum = "0.19.0"
Expand Down

0 comments on commit 834ce92

Please sign in to comment.