on master help sign in
Removed the snitizer

This reverts commit bae9b6a5915fe821f94abb588d53e4122580a807

commitdede69b7ff070e94510d2f42ef62890d6939da9a authoriko <ilyakooo0@gmail.com> dateSat 27 Apr 2019, 20:46 (7 years ago) parentbae9b6a
4 files changed+22−73
denis/src/Data/Post.hs+8−12 denis/src/Data/PostElement.hs+8−19 denis/src/Data/Query.hs+6−10 denis/src/Data/Sanitizer.hs−32
denis/src/Data/Post.hs+8−12
@@ -15,7 +15,7 @@ module Data.Post (
1515 QuoteId,
1616 PostRowResponse(..),
1717 PostCreation(..)
18−) where
18+) where
1919
2020import Data.Int (Int64)
2121import qualified Generics.SOP as SOP
@@ -29,7 +29,6 @@ import Data.Function (on)
2929import Data.Time.Clock
3030import Data.Time.Calendar
3131import qualified Data.Vector as V
32−import Data.Sanitizer
3332
3433-- MARK: Documentation
3534
@@ -38,10 +37,10 @@ instance ToSample Post where
3837 where time = UTCTime (ModifiedJulianDay 1000) 8
3938
4039instance ToSample PostCreation where
41− toSamples _ = samples $ PostCreation <$> (map snd $ toSamples Proxy) <*> [(V.fromList ["hse", "cs", "machineLearning"])]
40+ toSamples _ = samples $ PostCreation <$> (map snd $ toSamples Proxy) <*> [(V.fromList ["hse", "cs", "machineLearning"])]
41+
4242
43−
44−-- MARK: Actual type
43+-- MARK: Actual type
4544
4645type PostId = Int64
4746type QuoteId = Int64
@@ -60,28 +59,25 @@ instance ToJSON Post where
6059 "authorId" .= aId,
6160 "updated" .= tm,
6261 "tags" .= tags,
63− "body" .= pb ]
62+ "body" .= pb ]
6463
6564data PostCreation = PostCreation {
6665 postCreationBody :: [PostElement Post],
6766 postCreationTags :: V.Vector Text
6867} deriving GHC.Generic
6968
70−instance Sanitizable PostCreation where
71− sanitize f (PostCreation b t) = PostCreation (sanitize f b) (sanitize f t)
72−
7369instance SOP.Generic PostCreation
7470instance SOP.HasDatatypeInfo PostCreation
7571
7672instance ToJSON PostCreation where
7773 toJSON (PostCreation body tags) = object [
7874 "tags" .= tags,
79− "body" .= body ]
75+ "body" .= body ]
8076
8177instance FromJSON PostCreation where
82− parseJSON = withObject "post creation" $ \e ->
78+ parseJSON = withObject "post creation" $ \e ->
8379 PostCreation <$> e .: "body" <*> e .: "tags"
84−
80+
8581
8682-- MARK: Rows
8783
denis/src/Data/PostElement.hs+8−19
@@ -16,7 +16,7 @@ module Data.PostElement (
1616 MkElementRow,
1717 PostElementRow(..),
1818 elementsToRows
19−) where
19+) where
2020
2121import Data.Int (Int64)
2222import qualified Generics.SOP as SOP
@@ -25,7 +25,6 @@ import Data.Text (Text)
2525import Data.Aeson
2626import Control.Applicative ((<|>))
2727import Servant.Docs (ToSample, toSamples, samples)
28−import Data.Sanitizer
2928
3029-- MARK: Documentation
3130
@@ -44,14 +43,7 @@ data PostElement a = Markdown Text
4443 | Quote PostQuote
4544 | Attachment Text
4645
47−instance {-# Overlapping #-} Sanitizable (PostElement t) where
48− sanitize f (Markdown m) = Markdown (sanitize f m)
49− sanitize f (Latex l) = Latex (sanitize f l)
50− sanitize f (Image i) = Image (sanitize f i)
51− sanitize f (Quote q) = Quote (sanitize f q)
52− sanitize f (Attachment a) = Attachment (sanitize f a)
53−
54−instance ToJSON (PostElement t) where
46+instance ToJSON (PostElement t) where
5547 toJSON (Markdown m) = object ["markdown" .= m]
5648 toJSON (Latex l) = object ["latex" .= l]
5749 toJSON (Image i) = object ["image" .= i]
@@ -59,7 +51,7 @@ instance ToJSON (PostElement t) where
5951 toJSON (Attachment a) = object ["attachment" .= a]
6052
6153instance FromJSON (PostElement t) where
62− parseJSON = withObject "post element" $ \e ->
54+ parseJSON = withObject "post element" $ \e ->
6355 Markdown <$> e .: "markdown" <|>
6456 Latex <$> e .: "latex" <|>
6557 Image <$> e .: "image" <|>
@@ -83,7 +75,7 @@ rowsToElement :: MkElementRow (Maybe (PostElement p))
8375rowsToElement (Just m) Nothing Nothing Nothing Nothing = Just $ Markdown m
8476rowsToElement Nothing (Just l) Nothing Nothing Nothing = Just $ Latex l
8577rowsToElement Nothing Nothing (Just i) Nothing Nothing = Just $ Image i
86−-- rowsToElement Nothing Nothing Nothing (Just q) Nothing =
78+-- rowsToElement Nothing Nothing Nothing (Just q) Nothing =
8779-- fmap Quote $ M.lookup q pqrs >>= rowsToQuote erqs pqrs
8880rowsToElement Nothing Nothing Nothing Nothing (Just a) = Just $ Attachment a
8981rowsToElement _ _ _ _ _ = Nothing
@@ -106,7 +98,7 @@ elementsToRows :: Int64 -> [PostElement a] -> [PostElementRow a]
10698elementsToRows pId els = map (\(el, f) -> elemenToRow f el) . zip els . map (PostElementRow pId) $ [0..]
10799
108100
109−-- -- MARK: Quote
101+-- -- MARK: Quote
110102
111103data PostQuote = PostQuote {
112104 quoteId :: Int64,
@@ -114,16 +106,13 @@ data PostQuote = PostQuote {
114106 quotePostId :: Int64
115107}
116108
117−instance Sanitizable PostQuote where
118− sanitize f (PostQuote qId qB qPId) = PostQuote qId (sanitize f qB) qPId
119−
120109instance ToJSON PostQuote where
121110 toJSON (PostQuote qId pb pId) = object [
122− "id" .= qId,
111+ "id" .= qId,
123112 "postId" .= pId,
124113 "quoteBody" .= pb ]
125114
126−
115+
127116-- -- MARK: PostQuoteRow
128117
129118-- data PostQuoteRow = PostQuoteRow {
@@ -133,7 +122,7 @@ instance ToJSON PostQuote where
133122
134123-- instance SOP.Generic PostQuoteRow
135124-- instance SOP.HasDatatypeInfo PostQuoteRow
136−
125+
137126-- rowsToQuote :: M.Map Int64 [ElementRow PostQuote] -> M.Map Int64 PostQuoteRow -> PostQuoteRow -> Maybe PostQuote
138127-- rowsToQuote erqs pqrs (PostQuoteRow qId pId) = do
139128-- elementRows <- M.lookup qId erqs
denis/src/Data/Query.hs+6−10
@@ -56,12 +56,10 @@ import Data.Aeson
5656import Servant.Docs
5757import Data.Proxy
5858import Data.Vector (Vector, toList, fromList)
59−import qualified Data.Vector as V
6059import Data.Text (Text)
6160import Data.Channel.NamedChannel
6261import Data.Channel.AnonymousChannel
6362import Data.Maybe (fromMaybe)
64−import Data.Sanitizer
6563
6664-- MARK: Documentation
6765
@@ -307,23 +305,21 @@ getAllUsers = runQuery getAllUsersQ >>= getRows
307305
308306publishPost :: UserId -> PostCreation -> StaticPQ PostId
309307publishPost uId pc = commitedTransactionallyUpdate $ do
310− pId' <- manipulateParams createPostRowQ (uId, V.map sanitizeHtml . postCreationTags $ pc) >>= firstRow
308+ pId' <- manipulateParams createPostRowQ (uId, postCreationTags pc) >>= firstRow
311309 case pId' of
312310 (Just (Only pId)) -> do
313− traversePrepared_ createPostElementRowsQ $ elementsToRows pId (sanitizeHtml . postCreationBody $ pc)
311+ traversePrepared_ createPostElementRowsQ $ elementsToRows pId (postCreationBody pc)
314312 return pId
315313 _ -> lift $ S.throwError S.err404
316314
317315createNewChannel :: UserId -> NamedChannelCreationRequest -> StaticPQ (Maybe NamedChannelId)
318−createNewChannel uId (NamedChannelCreationRequest cName cTags cPeople) = commitedTransactionallyUpdate $ do
319− uIds <- verifiedUsers . toList $ cPeople
320− cId <- manipulateParams createNamedChannelQ (addUserToChannelCreate uId
321− (NamedChannelCreationRequest (sanitizeHtml cName) (sanitizeHtml cTags) (fromList uIds))) >>= firstRow
316+createNewChannel uId req = commitedTransactionallyUpdate $ do
317+ uIds <- verifiedUsers . toList $ namedChannelCreationRequestPeopleIds req
318+ cId <- manipulateParams createNamedChannelQ (addUserToChannelCreate uId (req {namedChannelCreationRequestPeopleIds = fromList uIds})) >>= firstRow
322319 return $ fmap fromOnly cId
323320
324321updateChannel :: UserId -> NamedChannel UserId -> StaticPQ ()
325−updateChannel uId (NamedChannel nId nName nTags nPeople) = commitedTransactionallyUpdate $ do
326− let req = NamedChannel nId (sanitizeHtml nName) (sanitizeHtml nTags) nPeople
322+updateChannel uId req = commitedTransactionallyUpdate $ do
327323 uIds <- fmap fromList . verifiedUsers . toList $ namedChannelPeopleIds req
328324 _ <- getChannelForUser uId $ namedChannelId req
329325 _ <- manipulateParams updateNamedChannelQ $ addUserToChannelUpdate uId (req {namedChannelPeopleIds = uIds})
denis/src/Data/Sanitizer.hsdeleted−32
@@ -1,32 +0,0 @@
1−{-# LANGUAGE OverloadedStrings,
2− FlexibleInstances #-}
3−
4−module Data.Sanitizer (
5− sanitizeHtml,
6− sanitizeHtml',
7− Sanitizable(..)
8− ) where
9−
10−import qualified Data.Text as T
11−
12−sanitizeHtml :: Sanitizable s => s -> s
13−sanitizeHtml = sanitize sanitizeHtml'
14−
15−sanitizeHtml' :: T.Text -> T.Text
16−sanitizeHtml' = foldl1 (.) $ map (uncurry T.replace) htmlCharMap
17−
18−htmlCharMap :: [(T.Text, T.Text)]
19−htmlCharMap = [
20− ("<", "&lt;"),
21− (">", "&gt;"),
22− ("&", "&amp;")
23− ]
24−
25−class Sanitizable s where
26− sanitize :: (T.Text -> T.Text) -> s -> s
27−
28−instance Sanitizable T.Text where
29− sanitize = id
30−
31−instance (Sanitizable e, Functor f) => Sanitizable (f e) where
32− sanitize = fmap . sanitize