Add isOwner field to the leaderboard end-point

This commit is contained in:
Filip Gralinski 2021-09-15 12:55:16 +02:00
parent 76b84637c9
commit 9260d74b08
2 changed files with 8 additions and 3 deletions

View File

@ -90,6 +90,7 @@ instance ToJSON LeaderboardEntry where
, "times" .= leaderboardNumberOfSubmissions entry
, "hash" .= (fromSHA1ToText $ submissionCommit $ leaderboardBestSubmission entry)
, "isPublic" .= (submissionIsPublic $ leaderboardBestSubmission entry)
, "isOwner" .= (leaderboardIsOwner entry)
, "isReevaluable" .= (leaderboardIsReevaluable entry)
, "isVisible" .= (leaderboardIsVisible entry)
, "id" .= (leaderboardBestSubmissionId entry)
@ -228,6 +229,7 @@ instance ToSchema LeaderboardEntryView where
& example .~ Just (toJSON (2:: Int)))
, ("hash", hashSchema)
, ("evaluations", evaluationsSchema)
, ("isOwner", boolSchema)
, ("isPublic", isPublicSchema)
, ("isReevaluable", boolSchema)
, ("isVisible", isVisibleSchema)
@ -1415,7 +1417,7 @@ convertEvaluationToView theMapping entTest =
-- convertTableEntryToView :: Maybe UserId -> [Entity Test] -> TableEntry -> SubmissionView
convertTableEntryToView :: [Entity Test] -> TableEntry -> HandlerFor App SubmissionView
convertTableEntryToView tests entry = do
mUserId <- maybeAuthPossiblyByToken
mUserEnt <- maybeAuthPossiblyByToken
isReevaluable <- runDB $ canBeReevaluated $ entityKey $ tableEntrySubmission entry
let isVisible = True
@ -1433,7 +1435,7 @@ convertTableEntryToView tests entry = do
submissionViewTags = Import.map convertTagInfoToView $ tableEntryTagsInfo entry,
submissionViewHash = fromSHA1ToText $ submissionCommit submission,
submissionViewEvaluations = catMaybes $ Import.map (convertEvaluationToView $ tableEntryMapping entry) tests,
submissionViewIsOwner = (entityKey <$> mUserId) == Just (submissionSubmitter submission),
submissionViewIsOwner = (entityKey <$> mUserEnt) == Just (submissionSubmitter submission),
submissionViewIsReevaluable = isReevaluable,
submissionViewIsVisible = isVisible,
submissionViewIsPublic = submissionIsPublic submission,

View File

@ -74,6 +74,7 @@ data LeaderboardEntry = LeaderboardEntry {
leaderboardTags :: [(Entity Import.Tag, Entity SubmissionTag)],
leaderboardParams :: [Parameter],
leaderboardVersion :: (Int, Int, Int),
leaderboardIsOwner :: Bool,
leaderboardIsVisible :: Bool,
leaderboardIsReevaluable :: Bool,
leaderboardTeam :: Maybe (Entity Team)
@ -392,7 +393,8 @@ toLeaderboardEntry challengeId tests ss = do
SubmissionSubmitter ==. entityKey user]
[Desc SubmissionStamp]
mUserId <- maybeAuthPossiblyByToken
mUserEnt <- maybeAuthPossiblyByToken
let isOwner = (entityKey <$> mUserEnt) == Just (submissionSubmitter submission)
isReevaluable <- runDB $ canBeReevaluated $ entityKey $ tableEntrySubmission bestOne
let isVisible = True
@ -415,6 +417,7 @@ toLeaderboardEntry challengeId tests ss = do
leaderboardTags = tagEnts,
leaderboardParams = map entityVal theParameters,
leaderboardVersion = theVersion,
leaderboardIsOwner = isOwner,
leaderboardIsReevaluable = isReevaluable,
leaderboardIsVisible = isVisible,
leaderboardTeam = mTeam