diff options
Diffstat (limited to 'overlays/spm/server')
| -rw-r--r-- | overlays/spm/server/Spm/Server.hs | 35 |
1 files changed, 24 insertions, 11 deletions
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 | |||
| 223 | :<|> getMapping | 223 | :<|> getMapping |
| 224 | :<|> patchMapping | 224 | :<|> patchMapping |
| 225 | :<|> putMapping | 225 | :<|> putMapping |
| 226 | :<|> deleteMapping | ||
| 226 | where | 227 | where |
| 227 | whoami = do | 228 | whoami = do |
| 228 | Entity _ Mailbox{mailboxIdent} <- maybe (throwError err404) return <=< spmSql . getBy $ UniqueMailbox mbox | 229 | Entity _ Mailbox{mailboxIdent} <- maybe (throwError err404) return <=< spmSql . getBy $ UniqueMailbox mbox |
| @@ -314,19 +315,9 @@ spmServer dom mbox = whoami | |||
| 314 | update mmId [ MailboxMappingReject =. view _SpmMappingStateReject mappingState ] | 315 | update mmId [ MailboxMappingReject =. view _SpmMappingStateReject mappingState ] |
| 315 | return NoContent | 316 | return NoContent |
| 316 | 317 | ||
| 317 | putMapping spmMapping mappingState = spmSql $ do | 318 | assertAuthorizedAncestor spmMapping = do |
| 318 | Entity mailboxId _ <- maybe (throwError err404) return <=< getBy $ UniqueMailbox mbox | 319 | Entity mailboxId _ <- maybe (throwError err404) return <=< getBy $ UniqueMailbox mbox |
| 319 | 320 | ||
| 320 | existing <- selectList | ||
| 321 | [ MailboxMappingLocal ==. (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) | ||
| 322 | , MailboxMappingExtension ==. (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) | ||
| 323 | , MailboxMappingDomain ==. dom | ||
| 324 | ] | ||
| 325 | [ LimitTo 1 | ||
| 326 | ] | ||
| 327 | unless (null existing) $ | ||
| 328 | throwError err409 | ||
| 329 | |||
| 330 | let go [] = throwError err403 | 321 | let go [] = throwError err403 |
| 331 | go (SpmMapping{..} : ancestors) = do | 322 | go (SpmMapping{..} : ancestors) = do |
| 332 | candidate <- selectList | 323 | candidate <- selectList |
| @@ -344,6 +335,21 @@ spmServer dom mbox = whoami | |||
| 344 | _other -> throwError err500 | 335 | _other -> throwError err500 |
| 345 | in go $ spmMappingAncestors spmMapping | 336 | in go $ spmMappingAncestors spmMapping |
| 346 | 337 | ||
| 338 | putMapping spmMapping mappingState = spmSql $ do | ||
| 339 | Entity mailboxId _ <- maybe (throwError err404) return <=< getBy $ UniqueMailbox mbox | ||
| 340 | |||
| 341 | existing <- selectList | ||
| 342 | [ MailboxMappingLocal ==. (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) | ||
| 343 | , MailboxMappingExtension ==. (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) | ||
| 344 | , MailboxMappingDomain ==. dom | ||
| 345 | ] | ||
| 346 | [ LimitTo 1 | ||
| 347 | ] | ||
| 348 | unless (null existing) $ | ||
| 349 | throwError err409 | ||
| 350 | |||
| 351 | assertAuthorizedAncestor spmMapping | ||
| 352 | |||
| 347 | insert_ MailboxMapping | 353 | insert_ MailboxMapping |
| 348 | { mailboxMappingLocal = (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) | 354 | { mailboxMappingLocal = (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) |
| 349 | , mailboxMappingExtension = (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) | 355 | , mailboxMappingExtension = (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) |
| @@ -353,6 +359,13 @@ spmServer dom mbox = whoami | |||
| 353 | } | 359 | } |
| 354 | return NoContent | 360 | return NoContent |
| 355 | 361 | ||
| 362 | deleteMapping spmMapping = spmSql $ do | ||
| 363 | Entity mmId MailboxMapping{} <- getUniqueMapping spmMapping | ||
| 364 | assertAuthorizedAncestor spmMapping | ||
| 365 | |||
| 366 | delete mmId | ||
| 367 | return NoContent | ||
| 368 | |||
| 356 | main :: IO () | 369 | main :: IO () |
| 357 | main = runSystemdWarp systemdSettings warpSettings =<< mkSpmApp | 370 | main = runSystemdWarp systemdSettings warpSettings =<< mkSpmApp |
| 358 | where | 371 | where |
