diff --git a/Handler/EditSubmission.hs b/Handler/EditSubmission.hs index 8c5277e..9376055 100644 --- a/Handler/EditSubmission.hs +++ b/Handler/EditSubmission.hs @@ -83,12 +83,11 @@ getPossibleAchievements userId submissionId = do doEditSubmission formWidget formEnctype submissionId mVariantId = do submission <- runDB $ get404 submissionId submissionFull <- getFullInfo (Entity submissionId submission) - let view = queryResult submissionFull + (Entity userId _) <- requireAuth + let view = queryResult (Just userId) submissionFull tagsAvailableAsJSON <- runDB $ getAvailableTagsAsJSON - (Entity userId _) <- requireAuth - achievements <- runDB $ getPossibleAchievements userId submissionId variantParams <- case mVariantId of diff --git a/Handler/Query.hs b/Handler/Query.hs index f0c9212..ca13799 100644 --- a/Handler/Query.hs +++ b/Handler/Query.hs @@ -149,7 +149,6 @@ groupBySecond lst = map putOut $ groupOn (fsiSubmissionId . fst) lst findSubmissions :: Text -> Handler [(FullSubmissionInfo, [SHA1])] findSubmissions sha1Prefix = do - mauthId <- maybeAuth allSubmissions <- runDB $ rawCommitQuery sha1Prefix justSubmissions' <- mapM getFullInfo allSubmissions let justSubmissions = map (\s -> (s, [])) justSubmissions' @@ -275,6 +274,8 @@ isFullQuery query = length query == 40 processQuery :: Text -> Handler Html processQuery query = do + mUserId <- maybeAuthId + submissions' <- findSubmissions query let submissions = map fst submissions' defaultLayout $ do @@ -365,7 +366,6 @@ data ViewVariantData = ViewVariantData { fetchViewVariantData :: VariantId -> Handler ViewVariantData fetchViewVariantData variantId = do - mauthId <- maybeAuth variant <- runDB $ get404 variantId let theSubmissionId = variantSubmission variant theSubmission <- runDB $ get404 theSubmissionId @@ -423,6 +423,8 @@ nullSHA1 = fromTextToSHA1 "da39a3ee5e6b4b0d3255bfef95601890afd80709" doViewVariantTestR :: Diff VariantId -> TestId -> Handler Html doViewVariantTestR variantId testId = do + mUserId <- maybeAuthId + testSelected <- runDB $ get404 testId let testSelectedEnt = Entity testId testSelected @@ -504,7 +506,7 @@ maximumNumberOfItemsToBeShown :: Int maximumNumberOfItemsToBeShown = 40 getOut :: Maybe UserId -> TableEntry -> WidgetFor App (Maybe (FilePath, FilePath)) -getOut mauthId entry = do +getOut _ entry = do let variant = variantName $ entityVal $ tableEntryVariant entry let isViewable = True @@ -691,8 +693,16 @@ adjustNumberOfColumnsShown maximumNumberOfColumns tests = adjustNumberOfColumnsS minimumNumberOfTests = 2 -submissionHeader :: Diff (FullSubmissionInfo, Maybe Text) -> WidgetFor App () -submissionHeader param = +canFullInfoBeShown (OneThing (fsi, _)) mUserId = checkWhetherVisible (fsiSubmission fsi) mUserId +canFullInfoBeShown (TwoThings (fsiA, _) (fsiB, _)) mUserId = do + checkA <- checkWhetherVisible (fsiSubmission fsiA) mUserId + checkB <- checkWhetherVisible (fsiSubmission fsiB) mUserId + return (checkA && checkB) + +submissionHeader :: Maybe UserId -> Diff (FullSubmissionInfo, Maybe Text) -> WidgetFor App () +submissionHeader mUserId param = do + showFullInfo <- handlerToWidget $ runDB $ canFullInfoBeShown param mUserId + $(widgetFile "submission-header") where variantSettings = ("out", ()) submission = fst <$> param @@ -707,9 +717,8 @@ submissionHeader param = submissionToSubmissionUrl submission' = getReadOnlySubmissionUrl (fsiScheme submission') (fsiChallengeRepo submission') $ challengeName $ fsiChallenge submission' submissionToBrowsableUrl submission' = browsableGitRepoBranch (fsiScheme submission') (fsiChallengeRepo submission') (challengeName $ fsiChallenge submission') (getPublicSubmissionBranch $ fsiSubmissionId submission') - -queryResult :: FullSubmissionInfo -> WidgetFor App () -queryResult submission = do +queryResult :: Maybe UserId -> FullSubmissionInfo -> WidgetFor App () +queryResult mUserId submission = do $(widgetFile "query-result") queryForm :: Form Text diff --git a/Handler/Tables.hs b/Handler/Tables.hs index 3464958..0a19d6c 100644 --- a/Handler/Tables.hs +++ b/Handler/Tables.hs @@ -295,19 +295,9 @@ statusCellWidget challengeName repoScheme challengeRepo (submissionId, submissio Nothing getInfoLink :: Submission -> Maybe UserId -> Maybe (Route App) -getInfoLink submission mauthId = if checkSimpleVisibility submission mauthId - then Just $ QueryResultsR commitHash - else Nothing +getInfoLink submission _ = Just $ QueryResultsR commitHash where commitHash = fromSHA1ToText $ submissionCommit submission --- sometimes we checker whether we got a teacher, but sometimes --- fall back to a simpler check... -checkSimpleVisibility :: Submission -> Maybe UserId -> Bool -checkSimpleVisibility submission mauthId = isPublic || isOwner - where isPublic = submissionIsPublic submission - isOwner = (mauthId == Just userId) - userId = submissionSubmitter submission - checkWhetherVisible :: (MonadIO m, BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistUniqueRead backend) => Submission -> Maybe (Key User) -> ReaderT backend m Bool checkWhetherVisible submission Nothing = return $ submissionIsPublic submission diff --git a/templates/query-result.hamlet b/templates/query-result.hamlet index 19cd5ca..6c51a21 100644 --- a/templates/query-result.hamlet +++ b/templates/query-result.hamlet @@ -3,10 +3,10 @@
No results found.
$else
$forall submission <- submissions
- ^{queryResult submission}
+ ^{queryResult mUserId submission}
downstream submissions
$forall superSubmission <- (fsiSuperSubmissions submission)
- ^{queryResult superSubmission}
+ ^{queryResult mUserId superSubmission}
diff --git a/templates/query-results.hamlet b/templates/query-results.hamlet
index 7f73f8e..66bdacb 100644
--- a/templates/query-results.hamlet
+++ b/templates/query-results.hamlet
@@ -5,5 +5,5 @@ $if null submissions
diff --git a/templates/submission-header.hamlet b/templates/submission-header.hamlet
index 4e4db25..a938144 100644
--- a/templates/submission-header.hamlet
+++ b/templates/submission-header.hamlet
@@ -10,12 +10,13 @@
#{repoUrl $ fsiRepo $ current submission}
/ branch #{repoBranch $ fsiRepo $ current submission}
- $nothing
- #{repoUrl $ fsiRepo $ current submission}
/ branch #{repoBranch $ fsiRepo $ current submission}
+ $if showFullInfo
+ #{repoUrl $ fsiRepo $ current submission}
/ branch #{repoBranch $ fsiRepo $ current submission}
+ $nothing
+ #{repoUrl $ fsiRepo $ current submission}
/ branch #{repoBranch $ fsiRepo $ current submission}
$if submissionIsPublic $ fsiSubmission $ current submission
#{publicSubmissionRepo}
/ branch #{publicSubmissionBranch}
diff --git a/templates/view-variant.hamlet b/templates/view-variant.hamlet
index f137f99..2b4df0d 100644
--- a/templates/view-variant.hamlet
+++ b/templates/view-variant.hamlet
@@ -3,7 +3,7 @@