feat(ratings): i18n rating file names
This commit is contained in:
parent
69c61a4bb4
commit
1195231bc3
@ -2614,4 +2614,6 @@ TestDownloadInTransaction: Generierung während Datenbank-Transaktion
|
|||||||
TestDownloadFromDatabase: Generierung während Download aus Datenbank
|
TestDownloadFromDatabase: Generierung während Download aus Datenbank
|
||||||
|
|
||||||
ValueRequiredLabeledSimple fieldLabel@Text: #{fieldLabel} wird benötigt
|
ValueRequiredLabeledSimple fieldLabel@Text: #{fieldLabel} wird benötigt
|
||||||
ValueRequiredLabeledMultiWord fieldLabel@Text: „#{fieldLabel}“ wird benötigt
|
ValueRequiredLabeledMultiWord fieldLabel@Text: „#{fieldLabel}“ wird benötigt
|
||||||
|
|
||||||
|
RatingFileTitle subId@CryptoFileNameSubmission: bewertung_#{toPathPiece subId}.txt
|
||||||
@ -2615,3 +2615,5 @@ TestDownloadFromDatabase: Generate while streaming from database
|
|||||||
|
|
||||||
ValueRequiredLabeledSimple fieldLabel: #{fieldLabel} is required
|
ValueRequiredLabeledSimple fieldLabel: #{fieldLabel} is required
|
||||||
ValueRequiredLabeledMultiWord fieldLabel: “#{fieldLabel}” is required
|
ValueRequiredLabeledMultiWord fieldLabel: “#{fieldLabel}” is required
|
||||||
|
|
||||||
|
RatingFileTitle subId: rating_#{toPathPiece subId}.txt
|
||||||
|
|||||||
@ -17,14 +17,15 @@ import qualified Data.Text as Text
|
|||||||
|
|
||||||
import qualified Data.ByteString.Lazy as Lazy.ByteString
|
import qualified Data.ByteString.Lazy as Lazy.ByteString
|
||||||
|
|
||||||
import qualified System.FilePath.Cryptographic as FilePath (decrypt)
|
|
||||||
|
|
||||||
import qualified Database.Esqueleto as E
|
import qualified Database.Esqueleto as E
|
||||||
|
|
||||||
import qualified Data.Conduit.List as Conduit
|
import qualified Data.Conduit.List as Conduit
|
||||||
|
|
||||||
import Handler.Utils.Rating.Format
|
import Handler.Utils.Rating.Format
|
||||||
|
|
||||||
|
import qualified Data.Set as Set
|
||||||
|
import qualified Data.CaseInsensitive as CI
|
||||||
|
|
||||||
|
|
||||||
validateRating :: SheetType -> Rating' -> [RatingException]
|
validateRating :: SheetType -> Rating' -> [RatingException]
|
||||||
validateRating ratingSheetType Rating'{ ratingPoints=Just rp, .. }
|
validateRating ratingSheetType Rating'{ ratingPoints=Just rp, .. }
|
||||||
@ -76,13 +77,21 @@ getRating submissionId = runMaybeT $ do
|
|||||||
|
|
||||||
return Rating{ ratingValues = Rating'{..}, .. }
|
return Rating{ ratingValues = Rating'{..}, .. }
|
||||||
|
|
||||||
ratingFile :: MonadIO m => CryptoFileNameSubmission -> Rating -> m File
|
extensionRating :: String
|
||||||
|
extensionRating = "txt"
|
||||||
|
|
||||||
|
ratingFile :: ( MonadHandler m
|
||||||
|
, HandlerSite m ~ UniWorX
|
||||||
|
)
|
||||||
|
=> CryptoFileNameSubmission -> Rating -> m File
|
||||||
ratingFile cID rating@Rating{ ratingValues = Rating'{..}, .. } = do
|
ratingFile cID rating@Rating{ ratingValues = Rating'{..}, .. } = do
|
||||||
|
MsgRenderer mr <- getMsgRenderer
|
||||||
fileModified <- maybe (liftIO getCurrentTime) return ratingTime
|
fileModified <- maybe (liftIO getCurrentTime) return ratingTime
|
||||||
let
|
let
|
||||||
fileTitle = "bewertung_" <> Text.unpack (toPathPiece cID) <.> "txt"
|
fileTitle = ensureExtension extensionRating . unpack . mr $ MsgRatingFileTitle cID
|
||||||
fileContent = Just . Lazy.ByteString.toStrict $ formatRating cID rating
|
fileContent = Just . Lazy.ByteString.toStrict $ formatRating cID rating
|
||||||
return File{..}
|
return File{..}
|
||||||
|
where ensureExtension ext fName = bool (`addExtension` ext) id (ext `isExtensionOf` fName) fName
|
||||||
|
|
||||||
type SubmissionContent = Either File (SubmissionId, Rating')
|
type SubmissionContent = Either File (SubmissionId, Rating')
|
||||||
|
|
||||||
@ -98,27 +107,26 @@ extractRatings = Conduit.mapM $ \f@File{..} -> do
|
|||||||
-> handle (throwM . RatingFileException fileTitle) $ Right . (sId, ) <$> parseRating f
|
-> handle (throwM . RatingFileException fileTitle) $ Right . (sId, ) <$> parseRating f
|
||||||
| otherwise -> return $ Left f
|
| otherwise -> return $ Left f
|
||||||
|
|
||||||
isRatingFile :: ( MonadHandler m
|
isRatingFile :: forall m.
|
||||||
|
( MonadHandler m
|
||||||
, HandlerSite m ~ UniWorX
|
, HandlerSite m ~ UniWorX
|
||||||
, MonadCatch m
|
|
||||||
) => FilePath -> m (Maybe SubmissionId)
|
) => FilePath -> m (Maybe SubmissionId)
|
||||||
isRatingFile fName
|
isRatingFile fName = liftHandler $
|
||||||
| Just cID <- isRatingFile' fName = do
|
fmap getFirst . flip foldMapM segments' $ fmap First . tryDecrypt
|
||||||
cIDKey <- getsYesod appCryptoIDKey
|
|
||||||
(Just <$> FilePath.decrypt cIDKey cID) `catch` decryptErrors
|
|
||||||
| otherwise = return Nothing
|
|
||||||
where
|
where
|
||||||
|
tryDecrypt :: Text -> Handler (Maybe SubmissionId)
|
||||||
|
tryDecrypt ciphertext
|
||||||
|
| Just cID <- fromPathPiece ciphertext
|
||||||
|
= (Just <$> decrypt (cID :: CryptoFileNameSubmission)) `catch` decryptErrors
|
||||||
|
| otherwise
|
||||||
|
= return Nothing
|
||||||
|
|
||||||
decryptErrors (CiphertextConversionFailed _) = return Nothing
|
decryptErrors (CiphertextConversionFailed _) = return Nothing
|
||||||
decryptErrors InvalidNamespaceDetected = return Nothing
|
decryptErrors InvalidNamespaceDetected = return Nothing
|
||||||
decryptErrors DeserializationError = return Nothing
|
decryptErrors DeserializationError = return Nothing
|
||||||
decryptErrors err = throwM err
|
decryptErrors err = throwM err
|
||||||
|
|
||||||
isRatingFile' :: FilePath -> Maybe CryptoFileNameSubmission
|
segments' = filter (not . Text.null) . Text.split (flip Set.notMember cryptoIdChars . CI.mk) . Text.pack $ takeFileName fName
|
||||||
isRatingFile' (takeFileName -> fName)
|
|
||||||
| (bName, ".txt") <- splitExtension fName
|
cryptoIdChars :: Set (CI Char)
|
||||||
, Just piece <- stripPrefix "bewertung_" bName
|
cryptoIdChars = Set.fromList . map CI.mk $ "uwa" ++ "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
|
||||||
, Just cID <- fromPathPiece $ Text.pack piece
|
|
||||||
= Just cID
|
|
||||||
| otherwise
|
|
||||||
= Nothing
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user