Merge branch 'master' of gitlab.cip.ifi.lmu.de:jost/UniWorX
This commit is contained in:
commit
1c9b121edb
12
routes
12
routes
@ -50,20 +50,22 @@
|
|||||||
!/ex/new SheetNewR GET POST
|
!/ex/new SheetNewR GET POST
|
||||||
/ex/#Text SheetR:
|
/ex/#Text SheetR:
|
||||||
/show SShowR GET !timeANDregistered !timeANDmaterials !corrector
|
/show SShowR GET !timeANDregistered !timeANDmaterials !corrector
|
||||||
/#SheetFileType/#FilePath SFileR GET !timeANDregistered !timeANDmaterials !corrector
|
!/#SheetFileType/*FilePath SFileR GET !timeANDregistered !timeANDmaterials !corrector
|
||||||
/edit SEditR GET POST
|
/edit SEditR GET POST
|
||||||
/delete SDelR GET POST
|
/delete SDelR GET POST
|
||||||
!/sub/new SubmissionNewR GET POST !timeANDregistered
|
!/sub/new SubmissionNewR GET POST !timeANDregistered
|
||||||
!/sub/own SubmissionOwnR GET !free
|
!/sub/own SubmissionOwnR GET !free
|
||||||
!/sub/#CryptoUUIDSubmission SubmissionR GET POST !owner !corrector
|
!/sub/#CryptoFileNameSubmission SubmissionR GET POST !owner !corrector
|
||||||
|
|
||||||
|
|
||||||
!/#UUID CryptoUUIDDispatchR GET !free -- just redirect
|
|
||||||
|
|
||||||
-- TODO below
|
-- TODO below
|
||||||
!/#{ZIPArchiveName SubmissionId} SubmissionDownloadArchiveR GET !deprecated
|
!/#{ZIPArchiveName SubmissionId} SubmissionDownloadArchiveR GET !deprecated
|
||||||
!/#CryptoUUIDSubmission/#FilePath SubmissionDownloadSingleR GET !deprecated
|
!/#CryptoFileNameSubmission/*FilePath SubmissionDownloadSingleR GET !deprecated
|
||||||
|
|
||||||
/submission SubmissionListR GET !deprecated
|
/submission SubmissionListR GET !deprecated
|
||||||
/submission/#CryptoUUIDSubmission SubmissionDemoR GET POST !deprecated
|
/submission/#CryptoUUIDSubmission SubmissionDemoR GET POST !deprecated
|
||||||
/submissions.zip SubmissionDownloadMultiArchiveR POST !deprecated
|
/submissions.zip SubmissionDownloadMultiArchiveR POST !deprecated
|
||||||
|
-- TODO above
|
||||||
|
|
||||||
|
!/#UUID CryptoUUIDDispatchR GET !free -- just redirect
|
||||||
|
!/*{CI FilePath} CryptoFileNameDispatchR GET !free
|
||||||
@ -24,6 +24,8 @@ import Data.CryptoID.Poly.ImplicitNamespace
|
|||||||
import Data.UUID.Cryptographic.ImplicitNamespace
|
import Data.UUID.Cryptographic.ImplicitNamespace
|
||||||
import System.FilePath.Cryptographic.ImplicitNamespace
|
import System.FilePath.Cryptographic.ImplicitNamespace
|
||||||
|
|
||||||
|
import qualified Data.Text as Text
|
||||||
|
|
||||||
import Data.UUID.Types
|
import Data.UUID.Types
|
||||||
import Web.PathPieces
|
import Web.PathPieces
|
||||||
|
|
||||||
@ -35,24 +37,33 @@ instance PathPiece UUID where
|
|||||||
fromPathPiece = fromString . unpack
|
fromPathPiece = fromString . unpack
|
||||||
toPathPiece = pack . toString
|
toPathPiece = pack . toString
|
||||||
|
|
||||||
|
instance (CI.FoldCase s, PathPiece s) => PathPiece (CI s) where
|
||||||
|
fromPathPiece = fmap CI.mk . fromPathPiece
|
||||||
|
toPathPiece = toPathPiece . CI.original
|
||||||
|
|
||||||
-- Generates CryptoUUID... Datatypes
|
instance {-# OVERLAPS #-} PathMultiPiece FilePath where
|
||||||
|
fromPathMultiPiece = Just . unpack . intercalate "/"
|
||||||
|
toPathMultiPiece = Text.splitOn "/" . pack
|
||||||
|
|
||||||
|
instance (CI.FoldCase s, PathMultiPiece s) => PathMultiPiece (CI s) where
|
||||||
|
fromPathMultiPiece = fmap CI.mk . fromPathMultiPiece
|
||||||
|
toPathMultiPiece = toPathMultiPiece . CI.original
|
||||||
|
|
||||||
|
|
||||||
|
-- Generates CryptoUUID... and CryptoFileName... Datatypes
|
||||||
decCryptoIDs [ ''SubmissionId
|
decCryptoIDs [ ''SubmissionId
|
||||||
, ''CourseId
|
|
||||||
, ''SheetId
|
|
||||||
, ''FileId
|
, ''FileId
|
||||||
, ''UserId
|
|
||||||
]
|
]
|
||||||
{- TODO: Do we need/want CryptoUUIDs for Sheet numbers? -}
|
{- TODO: Do we need/want CryptoUUIDs for Sheet numbers? -}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
newtype SubmissionMode = SubmissionMode (Maybe CryptoUUIDSubmission)
|
newtype SubmissionMode = SubmissionMode (Maybe CryptoFileNameSubmission)
|
||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
|
|
||||||
pattern NewSubmission :: SubmissionMode
|
pattern NewSubmission :: SubmissionMode
|
||||||
pattern NewSubmission = SubmissionMode Nothing
|
pattern NewSubmission = SubmissionMode Nothing
|
||||||
pattern ExistingSubmission :: CryptoUUIDSubmission -> SubmissionMode
|
pattern ExistingSubmission :: CryptoFileNameSubmission -> SubmissionMode
|
||||||
pattern ExistingSubmission cID = SubmissionMode (Just cID)
|
pattern ExistingSubmission cID = SubmissionMode (Just cID)
|
||||||
|
|
||||||
instance PathPiece SubmissionMode where
|
instance PathPiece SubmissionMode where
|
||||||
@ -62,6 +73,7 @@ instance PathPiece SubmissionMode where
|
|||||||
toPathPiece (SubmissionMode Nothing) = "new"
|
toPathPiece (SubmissionMode Nothing) = "new"
|
||||||
toPathPiece (SubmissionMode (Just x)) = toPathPiece x
|
toPathPiece (SubmissionMode (Just x)) = toPathPiece x
|
||||||
|
|
||||||
|
|
||||||
newtype ZIPArchiveName objID = ZIPArchiveName (CryptoID (CI FilePath) objID)
|
newtype ZIPArchiveName objID = ZIPArchiveName (CryptoID (CI FilePath) objID)
|
||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
|
|
||||||
|
|||||||
@ -142,12 +142,6 @@ postCEditR tid csh = do
|
|||||||
course <- runDB $ getBy $ CourseTermShort tid csh
|
course <- runDB $ getBy $ CourseTermShort tid csh
|
||||||
courseEditHandler False course
|
courseEditHandler False course
|
||||||
|
|
||||||
getCourseEditIDR :: CryptoUUIDCourse -> Handler Html
|
|
||||||
getCourseEditIDR cID = do
|
|
||||||
cIDKey <- getsYesod appCryptoIDKey
|
|
||||||
courseID <- UUID.decrypt cIDKey cID
|
|
||||||
courseEditHandler True =<< runDB (getEntity courseID)
|
|
||||||
|
|
||||||
|
|
||||||
courseDeleteHandler :: Handler Html -- not called anywhere yet
|
courseDeleteHandler :: Handler Html -- not called anywhere yet
|
||||||
courseDeleteHandler = undefined
|
courseDeleteHandler = undefined
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
module Handler.CryptoIDDispatch
|
module Handler.CryptoIDDispatch
|
||||||
( getCryptoUUIDDispatchR
|
( getCryptoUUIDDispatchR
|
||||||
|
, getCryptoFileNameDispatchR
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import hiding (Proxy)
|
import Import hiding (Proxy)
|
||||||
@ -26,11 +27,25 @@ import Yesod.Core.Types (HandlerContents(..), ErrorResponse(..))
|
|||||||
|
|
||||||
import qualified Control.Monad.Catch as E (Handler(..))
|
import qualified Control.Monad.Catch as E (Handler(..))
|
||||||
|
|
||||||
|
import Data.CaseInsensitive (CI)
|
||||||
|
import qualified Data.CaseInsensitive as CI
|
||||||
|
|
||||||
|
|
||||||
class CryptoRoute ciphertext plaintext where
|
class CryptoRoute ciphertext plaintext where
|
||||||
cryptoIDRoute :: p plaintext -> ciphertext -> Handler (Route UniWorX)
|
cryptoIDRoute :: p plaintext -> ciphertext -> Handler (Route UniWorX)
|
||||||
|
|
||||||
instance CryptoRoute UUID SubmissionId where
|
instance CryptoRoute UUID SubmissionId where
|
||||||
|
cryptoIDRoute _ (CryptoID -> cID) = do
|
||||||
|
(smid :: SubmissionId) <- decrypt cID
|
||||||
|
cID' <- encrypt smid
|
||||||
|
(tid,csh,shn) <- runDB $ do
|
||||||
|
shid <- submissionSheet <$> get404 smid
|
||||||
|
Sheet{..} <- get404 shid
|
||||||
|
Course{..} <- get404 sheetCourse
|
||||||
|
return (courseTerm, courseShorthand, sheetName)
|
||||||
|
return $ CSheetR tid csh shn $ SubmissionR cID'
|
||||||
|
|
||||||
|
instance CryptoRoute (CI FilePath) SubmissionId where
|
||||||
cryptoIDRoute _ (CryptoID -> cID) = do
|
cryptoIDRoute _ (CryptoID -> cID) = do
|
||||||
(smid :: SubmissionId) <- decrypt cID
|
(smid :: SubmissionId) <- decrypt cID
|
||||||
(tid,csh,shn) <- runDB $ do
|
(tid,csh,shn) <- runDB $ do
|
||||||
@ -66,3 +81,9 @@ getCryptoUUIDDispatchR uuid = dispatchID p uuid >>= maybe notFound (redirectWith
|
|||||||
p :: Proxy '[ SubmissionId
|
p :: Proxy '[ SubmissionId
|
||||||
]
|
]
|
||||||
p = Proxy
|
p = Proxy
|
||||||
|
|
||||||
|
getCryptoFileNameDispatchR :: CI FilePath -> Handler ()
|
||||||
|
getCryptoFileNameDispatchR path = dispatchID p path >>= maybe notFound (redirectWith found302)
|
||||||
|
where
|
||||||
|
p :: Proxy '[ SubmissionId ]
|
||||||
|
p = Proxy
|
||||||
|
|||||||
@ -79,7 +79,7 @@ getSubmissionNewR = postSubmissionNewR
|
|||||||
postSubmissionNewR tid csh shn = submissionHelper tid csh shn NewSubmission
|
postSubmissionNewR tid csh shn = submissionHelper tid csh shn NewSubmission
|
||||||
|
|
||||||
|
|
||||||
getSubmissionR, postSubmissionR :: TermId -> Text -> Text -> CryptoUUIDSubmission -> Handler Html
|
getSubmissionR, postSubmissionR :: TermId -> Text -> Text -> CryptoFileNameSubmission -> Handler Html
|
||||||
getSubmissionR = postSubmissionR
|
getSubmissionR = postSubmissionR
|
||||||
postSubmissionR tid csh shn cid = submissionHelper tid csh shn $ ExistingSubmission cid
|
postSubmissionR tid csh shn cid = submissionHelper tid csh shn $ ExistingSubmission cid
|
||||||
|
|
||||||
@ -289,16 +289,15 @@ submissionFileQuery submissionID (sf `E.InnerJoin` f) = E.distinctOnOrderBy [E.a
|
|||||||
E.orderBy [E.desc $ sf E.^. SubmissionFileIsUpdate] -- E.desc returns corrector updated data first
|
E.orderBy [E.desc $ sf E.^. SubmissionFileIsUpdate] -- E.desc returns corrector updated data first
|
||||||
return f
|
return f
|
||||||
|
|
||||||
getSubmissionDownloadSingleR :: CryptoUUIDSubmission -> FilePath -> Handler TypedContent
|
getSubmissionDownloadSingleR :: CryptoFileNameSubmission -> FilePath -> Handler TypedContent
|
||||||
getSubmissionDownloadSingleR cID path = do
|
getSubmissionDownloadSingleR cID path = do
|
||||||
submissionID <- decrypt cID
|
submissionID <- decrypt cID
|
||||||
cID' <- encrypt submissionID
|
|
||||||
|
|
||||||
runDB $ do
|
runDB $ do
|
||||||
isRating <- maybe False (== submissionID) <$> isRatingFile path
|
isRating <- maybe False (== submissionID) <$> isRatingFile path
|
||||||
case isRating of
|
case isRating of
|
||||||
True -> do
|
True -> do
|
||||||
file <- runMaybeT $ lift . ratingFile cID' =<< MaybeT (getRating submissionID)
|
file <- runMaybeT $ lift . ratingFile cID =<< MaybeT (getRating submissionID)
|
||||||
maybe notFound (return . toTypedContent . Text.decodeUtf8) $ fileContent =<< file
|
maybe notFound (return . toTypedContent . Text.decodeUtf8) $ fileContent =<< file
|
||||||
False -> do
|
False -> do
|
||||||
results <- E.select . E.from $ \(sf `E.InnerJoin` f) -> E.distinctOnOrderBy [E.asc $ f E.^. FileTitle] $ do
|
results <- E.select . E.from $ \(sf `E.InnerJoin` f) -> E.distinctOnOrderBy [E.asc $ f E.^. FileTitle] $ do
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
#{fileTitle file}
|
#{fileTitle file}
|
||||||
<span .label .label-warning>Gelöscht
|
<span .label .label-warning>Gelöscht
|
||||||
$else
|
$else
|
||||||
<a href=@{SubmissionDownloadSingleR cID $ fileTitle file} download .list-group-item>
|
<a href=@{SubmissionDownloadSingleR cID' $ fileTitle file} download .list-group-item>
|
||||||
#{fileTitle file}
|
#{fileTitle file}
|
||||||
$if submissionFileIsUpdate sFile
|
$if submissionFileIsUpdate sFile
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user