From 03a785abc2a2c6771007d83b20be05a52534ac21 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 10 Jul 2018 13:47:02 +0200 Subject: [PATCH 1/3] Fix PathPiece for ZIPArchiveName & submission original archive link --- src/Model/Types.hs | 9 +++------ templates/submission.hamlet | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Model/Types.hs b/src/Model/Types.hs index 64be64f45..8a2b908d7 100644 --- a/src/Model/Types.hs +++ b/src/Model/Types.hs @@ -285,15 +285,12 @@ instance Default Theme where derivePersistField "Theme" -newtype ZIPArchiveName obj = ZIPArchiveName obj +newtype ZIPArchiveName obj = ZIPArchiveName { unZIPArchiveName :: obj } deriving (Show, Read, Eq) instance PathPiece obj => PathPiece (ZIPArchiveName obj) where - fromPathPiece (map CI.mk . unpack -> s) - | Just s' <- stripSuffix (map CI.mk ".zip") s = fromPathPiece . pack $ map CI.original s' - | otherwise = Nothing - - toPathPiece (ZIPArchiveName obj) = toPathPiece obj <> ".zip" + fromPathPiece = fmap ZIPArchiveName . fromPathPiece <=< (stripSuffix `on` CI.foldCase) ".zip" + toPathPiece = (<> ".zip") . toPathPiece . unZIPArchiveName newtype DateTimeFormat = DateTimeFormat { unDateTimeFormat :: String } deriving (Eq, Ord, Read, Show, ToJSON, FromJSON, PersistField, PersistFieldSql) diff --git a/templates/submission.hamlet b/templates/submission.hamlet index 5ebbf522a..1672ee052 100644 --- a/templates/submission.hamlet +++ b/templates/submission.hamlet @@ -1,7 +1,8 @@ $maybe cID <- mcid -
+

Archiv + (Original) $if not (null lastEdits)

_{MsgLastEdits}
    From a7fb5a7d9e330d019262db9e9ea2b01c3fc9e805 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 10 Jul 2018 13:47:26 +0200 Subject: [PATCH 2/3] Only show submission form if authorized --- src/Handler/Submission.hs | 5 ++++- templates/submission.hamlet | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Handler/Submission.hs b/src/Handler/Submission.hs index 130bfaa73..1f0d3c5a4 100644 --- a/src/Handler/Submission.hs +++ b/src/Handler/Submission.hs @@ -246,6 +246,8 @@ submissionHelper tid csh shn (SubmissionMode mcid) = do Nothing -> return () actionUrl <- Data.Maybe.fromJust <$> getCurrentRoute + maySubmit <- (== Authorized) <$> isAuthorized actionUrl True + -- Maybe construct a table to display uploaded archive files let colonnadeFiles :: _ -> Colonnade Sortable _ (DBCell (WidgetT UniWorX IO) ()) colonnadeFiles cid = mconcat @@ -355,7 +357,8 @@ getSubArchiveR tid csh shn cID@CryptoID{..} (ZIPArchiveName sfType) = do fileSource' = do fileSource .| Conduit.map entityVal - maybe (return ()) (yieldM . ratingFile cID) rating + when (sfType == SubmissionCorrected) $ + maybe (return ()) (yieldM . ratingFile cID) rating zipComment = Text.encodeUtf8 . pack $ CI.foldedCase ciphertext diff --git a/templates/submission.hamlet b/templates/submission.hamlet index 1672ee052..e2c77382d 100644 --- a/templates/submission.hamlet +++ b/templates/submission.hamlet @@ -12,6 +12,7 @@ $maybe cID <- mcid

    _{MsgSubmissionFiles} ^{fileTable} -
    -
    - ^{formWidget} +$if maySubmit +
    + + ^{formWidget} From cacf0658218fd8810ed5e5ec573628b45348e1f6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 10 Jul 2018 13:47:36 +0200 Subject: [PATCH 3/3] Restrict correctors more --- routes | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes b/routes index 778805719..27263ba9a 100644 --- a/routes +++ b/routes @@ -64,10 +64,10 @@ /subs SSubsR GET POST /subs/new SubmissionNewR GET POST !timeANDregistered /subs/own SubmissionOwnR GET !free -- just redirect - /sub/#CryptoFileNameSubmission SubmissionR !corrector: + /sub/#CryptoFileNameSubmission SubmissionR !correctorANDisRead: / SubShowR GET POST !ownerANDtime !ownerANDisRead /archive/#{ZIPArchiveName SubmissionFileType} SubArchiveR GET !owner - /correction CorrectionR GET POST !ownerANDisRead + /correction CorrectionR GET POST !corrector !ownerANDisRead !/#SubmissionFileType/*FilePath SubDownloadR GET !owner /correctors SCorrR GET POST !/#SheetFileType/*FilePath SFileR GET !timeANDregistered !timeANDmaterials !corrector