diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-12-18 18:56:13 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-12-18 18:56:13 +0100 |
commit | 7d6e8a86997b41b351054cef0afc25646091a238 (patch) | |
tree | fdf9635f333416b987a16b7b19cfb0d700bf88aa /overlays/spm/server | |
parent | a436ce952a30b49ba2da98c12cbdfbd5feba6c3f (diff) | |
download | nixos-7d6e8a86997b41b351054cef0afc25646091a238.tar nixos-7d6e8a86997b41b351054cef0afc25646091a238.tar.gz nixos-7d6e8a86997b41b351054cef0afc25646091a238.tar.bz2 nixos-7d6e8a86997b41b351054cef0afc25646091a238.tar.xz nixos-7d6e8a86997b41b351054cef0afc25646091a238.zip |
...
Diffstat (limited to 'overlays/spm/server')
-rw-r--r-- | overlays/spm/server/Spm/Server.hs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/overlays/spm/server/Spm/Server.hs b/overlays/spm/server/Spm/Server.hs index 86d7d02b..d8efd826 100644 --- a/overlays/spm/server/Spm/Server.hs +++ b/overlays/spm/server/Spm/Server.hs | |||
@@ -222,6 +222,7 @@ spmServer dom mbox = whoami | |||
222 | :<|> listMappings | 222 | :<|> listMappings |
223 | :<|> getMapping | 223 | :<|> getMapping |
224 | :<|> patchMapping | 224 | :<|> patchMapping |
225 | :<|> putMapping | ||
225 | where | 226 | where |
226 | whoami = do | 227 | whoami = do |
227 | Entity _ Mailbox{mailboxIdent} <- maybe (throwError err404) return <=< spmSql . getBy $ UniqueMailbox mbox | 228 | Entity _ Mailbox{mailboxIdent} <- maybe (throwError err404) return <=< spmSql . getBy $ UniqueMailbox mbox |
@@ -313,6 +314,45 @@ spmServer dom mbox = whoami | |||
313 | update mmId [ MailboxMappingReject =. view _SpmMappingStateReject mappingState ] | 314 | update mmId [ MailboxMappingReject =. view _SpmMappingStateReject mappingState ] |
314 | return NoContent | 315 | return NoContent |
315 | 316 | ||
317 | putMapping spmMapping mappingState = spmSql $ do | ||
318 | Entity mailboxId _ <- maybe (throwError err404) return <=< getBy $ UniqueMailbox mbox | ||
319 | |||
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 | ||
331 | go (SpmMapping{..} : ancestors) = do | ||
332 | candidate <- selectList | ||
333 | [ MailboxMappingLocal ==. (spmMappingLocal <&> view (_Wrapped . _Unwrapped)) | ||
334 | , MailboxMappingExtension ==. (spmMappingExtension <&> view (_Wrapped . _Unwrapped)) | ||
335 | , MailboxMappingDomain ==. dom | ||
336 | ] | ||
337 | [ LimitTo 1 | ||
338 | ] | ||
339 | case candidate of | ||
340 | [Entity _ MailboxMapping{..}] -> | ||
341 | unless (mailboxMappingMailbox == mailboxId) $ | ||
342 | throwError err403 | ||
343 | [] -> go ancestors | ||
344 | _other -> throwError err500 | ||
345 | in go $ spmMappingAncestors spmMapping | ||
346 | |||
347 | insert_ MailboxMapping | ||
348 | { mailboxMappingLocal = (spmMappingLocal spmMapping <&> view (_Wrapped . _Unwrapped)) | ||
349 | , mailboxMappingExtension = (spmMappingExtension spmMapping <&> view (_Wrapped . _Unwrapped)) | ||
350 | , mailboxMappingDomain = dom | ||
351 | , mailboxMappingMailbox = mailboxId | ||
352 | , mailboxMappingReject = view _SpmMappingStateReject mappingState | ||
353 | } | ||
354 | return NoContent | ||
355 | |||
316 | main :: IO () | 356 | main :: IO () |
317 | main = runSystemdWarp systemdSettings warpSettings =<< mkSpmApp | 357 | main = runSystemdWarp systemdSettings warpSettings =<< mkSpmApp |
318 | where | 358 | where |