forked from filipg/gonito
Add isOwner field to the leaderboard end-point
This commit is contained in:
parent
76b84637c9
commit
9260d74b08
@ -90,6 +90,7 @@ instance ToJSON LeaderboardEntry where
|
|||||||
, "times" .= leaderboardNumberOfSubmissions entry
|
, "times" .= leaderboardNumberOfSubmissions entry
|
||||||
, "hash" .= (fromSHA1ToText $ submissionCommit $ leaderboardBestSubmission entry)
|
, "hash" .= (fromSHA1ToText $ submissionCommit $ leaderboardBestSubmission entry)
|
||||||
, "isPublic" .= (submissionIsPublic $ leaderboardBestSubmission entry)
|
, "isPublic" .= (submissionIsPublic $ leaderboardBestSubmission entry)
|
||||||
|
, "isOwner" .= (leaderboardIsOwner entry)
|
||||||
, "isReevaluable" .= (leaderboardIsReevaluable entry)
|
, "isReevaluable" .= (leaderboardIsReevaluable entry)
|
||||||
, "isVisible" .= (leaderboardIsVisible entry)
|
, "isVisible" .= (leaderboardIsVisible entry)
|
||||||
, "id" .= (leaderboardBestSubmissionId entry)
|
, "id" .= (leaderboardBestSubmissionId entry)
|
||||||
@ -228,6 +229,7 @@ instance ToSchema LeaderboardEntryView where
|
|||||||
& example .~ Just (toJSON (2:: Int)))
|
& example .~ Just (toJSON (2:: Int)))
|
||||||
, ("hash", hashSchema)
|
, ("hash", hashSchema)
|
||||||
, ("evaluations", evaluationsSchema)
|
, ("evaluations", evaluationsSchema)
|
||||||
|
, ("isOwner", boolSchema)
|
||||||
, ("isPublic", isPublicSchema)
|
, ("isPublic", isPublicSchema)
|
||||||
, ("isReevaluable", boolSchema)
|
, ("isReevaluable", boolSchema)
|
||||||
, ("isVisible", isVisibleSchema)
|
, ("isVisible", isVisibleSchema)
|
||||||
@ -1415,7 +1417,7 @@ convertEvaluationToView theMapping entTest =
|
|||||||
-- convertTableEntryToView :: Maybe UserId -> [Entity Test] -> TableEntry -> SubmissionView
|
-- convertTableEntryToView :: Maybe UserId -> [Entity Test] -> TableEntry -> SubmissionView
|
||||||
convertTableEntryToView :: [Entity Test] -> TableEntry -> HandlerFor App SubmissionView
|
convertTableEntryToView :: [Entity Test] -> TableEntry -> HandlerFor App SubmissionView
|
||||||
convertTableEntryToView tests entry = do
|
convertTableEntryToView tests entry = do
|
||||||
mUserId <- maybeAuthPossiblyByToken
|
mUserEnt <- maybeAuthPossiblyByToken
|
||||||
|
|
||||||
isReevaluable <- runDB $ canBeReevaluated $ entityKey $ tableEntrySubmission entry
|
isReevaluable <- runDB $ canBeReevaluated $ entityKey $ tableEntrySubmission entry
|
||||||
let isVisible = True
|
let isVisible = True
|
||||||
@ -1433,7 +1435,7 @@ convertTableEntryToView tests entry = do
|
|||||||
submissionViewTags = Import.map convertTagInfoToView $ tableEntryTagsInfo entry,
|
submissionViewTags = Import.map convertTagInfoToView $ tableEntryTagsInfo entry,
|
||||||
submissionViewHash = fromSHA1ToText $ submissionCommit submission,
|
submissionViewHash = fromSHA1ToText $ submissionCommit submission,
|
||||||
submissionViewEvaluations = catMaybes $ Import.map (convertEvaluationToView $ tableEntryMapping entry) tests,
|
submissionViewEvaluations = catMaybes $ Import.map (convertEvaluationToView $ tableEntryMapping entry) tests,
|
||||||
submissionViewIsOwner = (entityKey <$> mUserId) == Just (submissionSubmitter submission),
|
submissionViewIsOwner = (entityKey <$> mUserEnt) == Just (submissionSubmitter submission),
|
||||||
submissionViewIsReevaluable = isReevaluable,
|
submissionViewIsReevaluable = isReevaluable,
|
||||||
submissionViewIsVisible = isVisible,
|
submissionViewIsVisible = isVisible,
|
||||||
submissionViewIsPublic = submissionIsPublic submission,
|
submissionViewIsPublic = submissionIsPublic submission,
|
||||||
|
@ -74,6 +74,7 @@ data LeaderboardEntry = LeaderboardEntry {
|
|||||||
leaderboardTags :: [(Entity Import.Tag, Entity SubmissionTag)],
|
leaderboardTags :: [(Entity Import.Tag, Entity SubmissionTag)],
|
||||||
leaderboardParams :: [Parameter],
|
leaderboardParams :: [Parameter],
|
||||||
leaderboardVersion :: (Int, Int, Int),
|
leaderboardVersion :: (Int, Int, Int),
|
||||||
|
leaderboardIsOwner :: Bool,
|
||||||
leaderboardIsVisible :: Bool,
|
leaderboardIsVisible :: Bool,
|
||||||
leaderboardIsReevaluable :: Bool,
|
leaderboardIsReevaluable :: Bool,
|
||||||
leaderboardTeam :: Maybe (Entity Team)
|
leaderboardTeam :: Maybe (Entity Team)
|
||||||
@ -392,7 +393,8 @@ toLeaderboardEntry challengeId tests ss = do
|
|||||||
SubmissionSubmitter ==. entityKey user]
|
SubmissionSubmitter ==. entityKey user]
|
||||||
[Desc SubmissionStamp]
|
[Desc SubmissionStamp]
|
||||||
|
|
||||||
mUserId <- maybeAuthPossiblyByToken
|
mUserEnt <- maybeAuthPossiblyByToken
|
||||||
|
let isOwner = (entityKey <$> mUserEnt) == Just (submissionSubmitter submission)
|
||||||
|
|
||||||
isReevaluable <- runDB $ canBeReevaluated $ entityKey $ tableEntrySubmission bestOne
|
isReevaluable <- runDB $ canBeReevaluated $ entityKey $ tableEntrySubmission bestOne
|
||||||
let isVisible = True
|
let isVisible = True
|
||||||
@ -415,6 +417,7 @@ toLeaderboardEntry challengeId tests ss = do
|
|||||||
leaderboardTags = tagEnts,
|
leaderboardTags = tagEnts,
|
||||||
leaderboardParams = map entityVal theParameters,
|
leaderboardParams = map entityVal theParameters,
|
||||||
leaderboardVersion = theVersion,
|
leaderboardVersion = theVersion,
|
||||||
|
leaderboardIsOwner = isOwner,
|
||||||
leaderboardIsReevaluable = isReevaluable,
|
leaderboardIsReevaluable = isReevaluable,
|
||||||
leaderboardIsVisible = isVisible,
|
leaderboardIsVisible = isVisible,
|
||||||
leaderboardTeam = mTeam
|
leaderboardTeam = mTeam
|
||||||
|
Loading…
Reference in New Issue
Block a user