Skip to content

Commit

Permalink
Merge pull request lichess-org#16315 from veloce/study_mobile_scopes
Browse files Browse the repository at this point in the history
[Mobile] Add missing mobile scopes to study endpoints
  • Loading branch information
ornicar authored Nov 3, 2024
2 parents b0da0fa + 3020054 commit eab13f7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions app/controllers/Study.scala
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ final class Study(
def pgn(id: StudyId) = Open:
pgnWithFlags(id, identity)

def apiPgn(id: StudyId) = AnonOrScoped(_.Study.Read): ctx ?=>
def apiPgn(id: StudyId) = AnonOrScoped(_.Study.Read, _.Web.Mobile): ctx ?=>
pgnWithFlags(id, identity)

def pgnWithFlags(id: StudyId, flags: Update[WithFlags])(using Context) =
Expand All @@ -439,14 +439,15 @@ final class Study(
def chapterPgn(id: StudyId, chapterId: StudyChapterId) = Open:
doChapterPgn(id, chapterId, notFound, privateUnauthorizedFu, privateForbiddenFu)

def apiChapterPgn(id: StudyId, chapterId: StudyChapterId) = AnonOrScoped(_.Study.Read): ctx ?=>
doChapterPgn(
id,
chapterId,
fuccess(studyNotFoundText),
_ => fuccess(privateUnauthorizedText),
_ => fuccess(privateForbiddenText)
)
def apiChapterPgn(id: StudyId, chapterId: StudyChapterId) =
AnonOrScoped(_.Study.Read, _.Web.Mobile): ctx ?=>
doChapterPgn(
id,
chapterId,
fuccess(studyNotFoundText),
_ => fuccess(privateUnauthorizedText),
_ => fuccess(privateForbiddenText)
)

private def doChapterPgn(
id: StudyId,
Expand All @@ -467,7 +468,7 @@ final class Study(
}
}

def exportPgn(username: UserStr) = OpenOrScoped(_.Study.Read): ctx ?=>
def exportPgn(username: UserStr) = OpenOrScoped(_.Study.Read, _.Web.Mobile): ctx ?=>
val name =
if username.value == "me"
then ctx.me.fold(UserName("me"))(_.username)
Expand All @@ -485,7 +486,7 @@ final class Study(
.pipe(asAttachmentStream(s"${name}-${if isMe then "all" else "public"}-studies.pgn"))
.as(pgnContentType)

def apiListByOwner(username: UserStr) = OpenOrScoped(_.Study.Read): ctx ?=>
def apiListByOwner(username: UserStr) = OpenOrScoped(_.Study.Read, _.Web.Mobile): ctx ?=>
val isMe = ctx.is(username)
apiC.jsonDownload:
env.study.studyRepo
Expand Down

0 comments on commit eab13f7

Please sign in to comment.