fix team oAuth API

pull/5337/head
Thibault Duplessis 2019-07-23 14:32:03 +02:00
parent 47da85dfb5
commit 82419ac46b
4 changed files with 12 additions and 5 deletions

View File

@ -164,7 +164,7 @@ object Team extends LilaController {
case Some(Motivate(team)) => Redirect(routes.Team.requestForm(team.id)).fuccess
case _ => notFound(ctx)
},
scoped = req => me => Env.oAuth.server.fetchAppOwner(req) flatMap {
scoped = req => me => Env.oAuth.server.fetchAppAuthor(req) flatMap {
_ ?? { api.joinApi(id, me, _) }
} map {
case Some(Joined(_)) => jsonOkResult

View File

@ -24,8 +24,11 @@ final class Env(
private val tokenColl = db(CollectionAccessToken)
private val appColl = db(CollectionApp)
lazy val appApi = new OAuthAppApi(appColl)
lazy val server = new OAuthServer(
tokenColl = tokenColl,
appApi = appApi,
asyncCache = asyncCache
)
@ -33,8 +36,6 @@ final class Env(
tokenColl = tokenColl
)
lazy val appApi = new OAuthAppApi(appColl)
def forms = OAuthForm
}

View File

@ -22,6 +22,9 @@ final class OAuthAppApi(appColl: Coll) {
F.author -> user.id
))
def authorOf(clientId: OAuthApp.Id): Fu[Option[User.ID]] =
appColl.primitiveOne[User.ID]($doc(F.clientId -> clientId), F.author)
def update(from: OAuthApp)(f: OAuthApp => OAuthApp): Fu[OAuthApp] = {
val app = f(from)
if (app == from) fuccess(app)

View File

@ -11,6 +11,7 @@ import lila.user.{ User, UserRepo }
final class OAuthServer(
tokenColl: Coll,
appApi: OAuthAppApi,
asyncCache: lila.memo.AsyncCache.Builder
) {
@ -31,9 +32,11 @@ final class OAuthServer(
case e: AuthError => Left(e)
}
def fetchAppOwner(req: RequestHeader): Fu[Option[User.ID]] =
def fetchAppAuthor(req: RequestHeader): Fu[Option[User.ID]] =
reqToTokenId(req) ?? { tokenId =>
tokenColl.primitiveOne[User.ID]($doc(F.id -> tokenId), F.clientId)
tokenColl.primitiveOne[OAuthApp.Id]($doc(F.id -> tokenId), F.clientId) flatMap {
_ ?? appApi.authorOf
}
}
private def reqToTokenId(req: RequestHeader): Option[AccessToken.Id] =