From 2b92f10ae5dab7c78718db4b701e866ac85d99cb Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 18 Dec 2022 19:10:03 +0100 Subject: ... --- overlays/spm/server/Spm/Server.hs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'overlays/spm/server/Spm/Server.hs') diff --git a/overlays/spm/server/Spm/Server.hs b/overlays/spm/server/Spm/Server.hs index d8efd826..6bb9dfe6 100644 --- a/overlays/spm/server/Spm/Server.hs +++ b/overlays/spm/server/Spm/Server.hs @@ -223,6 +223,7 @@ spmServer dom mbox = whoami :<|> getMapping :<|> patchMapping :<|> putMapping + :<|> deleteMapping where whoami = do Entity _ Mailbox{mailboxIdent} <- maybe (throwError err404) return <=< spmSql . getBy $ UniqueMailbox mbox @@ -314,19 +315,9 @@ spmServer dom mbox = whoami update mmId [ MailboxMappingReject =. view _SpmMappingStateReject mappingState ] return NoContent - putMapping spmMapping mappingState = spmSql $ do + assertAuthorizedAncestor spmMapping = do Entity mailboxId _ <- maybe (throwError err404) return <=< getBy $ UniqueMailbox mbox - existing <- selectList - [ MailboxMappingLocal ==. (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) - , MailboxMappingExtension ==. (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) - , MailboxMappingDomain ==. dom - ] - [ LimitTo 1 - ] - unless (null existing) $ - throwError err409 - let go [] = throwError err403 go (SpmMapping{..} : ancestors) = do candidate <- selectList @@ -344,6 +335,21 @@ spmServer dom mbox = whoami _other -> throwError err500 in go $ spmMappingAncestors spmMapping + putMapping spmMapping mappingState = spmSql $ do + Entity mailboxId _ <- maybe (throwError err404) return <=< getBy $ UniqueMailbox mbox + + existing <- selectList + [ MailboxMappingLocal ==. (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) + , MailboxMappingExtension ==. (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) + , MailboxMappingDomain ==. dom + ] + [ LimitTo 1 + ] + unless (null existing) $ + throwError err409 + + assertAuthorizedAncestor spmMapping + insert_ MailboxMapping { mailboxMappingLocal = (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) , mailboxMappingExtension = (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) @@ -353,6 +359,13 @@ spmServer dom mbox = whoami } return NoContent + deleteMapping spmMapping = spmSql $ do + Entity mmId MailboxMapping{} <- getUniqueMapping spmMapping + assertAuthorizedAncestor spmMapping + + delete mmId + return NoContent + main :: IO () main = runSystemdWarp systemdSettings warpSettings =<< mkSpmApp where -- cgit v1.2.3