1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 16:54:53 +09:00

Update S2S Accept handler to handle Accept on a Create/Ticket

This commit is contained in:
fr33domlover 2020-04-08 17:02:04 +00:00
parent 318f182245
commit 4a362632be
5 changed files with 54 additions and 4 deletions

View file

@ -379,6 +379,15 @@ TicketProjectRemote
UniqueTicketProjectRemote ticket UniqueTicketProjectRemote ticket
TicketProjectRemoteAccept
ticket TicketProjectRemoteId
activity RemoteActivityId
accept Bool
result LocalURI Maybe
UniqueTicketProjectRemoteAccept ticket
UniqueTicketProjectRemoteAcceptActivity activity
TicketAuthorLocal TicketAuthorLocal
ticket LocalTicketId ticket LocalTicketId
author PersonId author PersonId

View file

@ -0,0 +1,8 @@
TicketProjectRemoteAccept
ticket TicketProjectRemoteId
activity RemoteActivityId
accept Bool
result LocalURI Maybe
UniqueTicketProjectRemoteAccept ticket
UniqueTicketProjectRemoteAcceptActivity activity

View file

@ -28,6 +28,7 @@ module Vervis.Federation.Offer
) )
where where
import Control.Applicative
import Control.Exception hiding (Handler) import Control.Exception hiding (Handler)
import Control.Monad import Control.Monad
import Control.Monad.Logger.CallStack import Control.Monad.Logger.CallStack
@ -87,7 +88,7 @@ sharerAcceptF
-> ActivityBody -> ActivityBody
-> Accept URIMode -> Accept URIMode
-> ExceptT Text Handler Text -> ExceptT Text Handler Text
sharerAcceptF shr now author body (Accept (ObjURI hOffer luOffer) _) = do sharerAcceptF shr now author body (Accept (ObjURI hOffer luOffer) mresult) = do
luAccept <- luAccept <-
fromMaybeE (activityId $ actbActivity body) "Accept without 'id'" fromMaybeE (activityId $ actbActivity body) "Accept without 'id'"
lift $ runDB $ do lift $ runDB $ do
@ -100,12 +101,17 @@ sharerAcceptF shr now author body (Accept (ObjURI hOffer luOffer) _) = do
case mractid of case mractid of
Nothing -> return $ "Activity already exists in inbox of " <> me Nothing -> return $ "Activity already exists in inbox of " <> me
Just ractid -> do Just ractid -> do
mv <- insertFollow pidRecip (personOutbox recip) ractid mv <-
runMaybeT
$ Left <$> insertFollow pidRecip (personOutbox recip) ractid
<|> Right <$> updateTicket pidRecip (personOutbox recip) ractid
case mv of case mv of
Nothing -> Nothing ->
return $ "Activity inserted to inbox of " <> me return $ "Activity inserted to inbox of " <> me
Just () -> Just (Left ()) ->
return $ "Accept received for follow request by " <> me return $ "Accept received for follow request by " <> me
Just (Right ()) ->
return $ "Accept received for ticket by " <> me
where where
insertToInbox luAccept ibidRecip = do insertToInbox luAccept ibidRecip = do
let iidAuthor = remoteAuthorInstance author let iidAuthor = remoteAuthorInstance author
@ -122,7 +128,7 @@ sharerAcceptF shr now author body (Accept (ObjURI hOffer luOffer) _) = do
delete ibiid delete ibiid
return Nothing return Nothing
Just _ -> return $ Just ractid Just _ -> return $ Just ractid
insertFollow pidRecip obidRecip ractidAccept = runMaybeT $ do insertFollow pidRecip obidRecip ractidAccept = do
guard =<< hostIsLocal hOffer guard =<< hostIsLocal hOffer
route <- MaybeT . pure $ decodeRouteLocal luOffer route <- MaybeT . pure $ decodeRouteLocal luOffer
obiid <- obiid <-
@ -148,6 +154,27 @@ sharerAcceptF shr now author body (Accept (ObjURI hOffer luOffer) _) = do
, followRemoteFollow = followRemoteRequestActivity frr , followRemoteFollow = followRemoteRequestActivity frr
, followRemoteAccept = ractidAccept , followRemoteAccept = ractidAccept
} }
updateTicket pidRecip obidRecip ractidAccept = do
guard =<< hostIsLocal hOffer
route <- MaybeT . pure $ decodeRouteLocal luOffer
obiid <-
case route of
SharerOutboxItemR shr' obikhid
| shr == shr' -> decodeKeyHashidM obikhid
_ -> MaybeT $ pure Nothing
obi <- MaybeT $ get obiid
guard $ outboxItemOutbox obi == obidRecip
Entity talid tal <- MaybeT $ getBy $ UniqueTicketAuthorLocalOpen obiid
guard $ ticketAuthorLocalAuthor tal == pidRecip
Entity tprid tpr <- MaybeT $ getBy $ UniqueTicketProjectRemote talid
guard $ remoteAuthorId author == ticketProjectRemoteTracker tpr
_tpraid <- MaybeT $ insertUnique TicketProjectRemoteAccept
{ ticketProjectRemoteAcceptTicket = tprid
, ticketProjectRemoteAcceptActivity = ractidAccept
, ticketProjectRemoteAcceptAccept = True
, ticketProjectRemoteAcceptResult = mresult
}
return ()
sharerRejectF sharerRejectF
:: ShrIdent :: ShrIdent

View file

@ -1509,6 +1509,8 @@ changes hLocal ctx =
, renameField "RemoteMessage" "identNew" "ident" , renameField "RemoteMessage" "identNew" "ident"
-- 234 -- 234
, addEntities model_2020_02_22 , addEntities model_2020_02_22
-- 235
, addEntities model_2020_04_07
] ]
migrateDB migrateDB

View file

@ -181,6 +181,7 @@ module Vervis.Migration.Model
, RemoteMessage227 , RemoteMessage227
, RemoteMessage227Generic (..) , RemoteMessage227Generic (..)
, model_2020_02_22 , model_2020_02_22
, model_2020_04_07
) )
where where
@ -355,3 +356,6 @@ makeEntitiesMigration "227"
model_2020_02_22 :: [Entity SqlBackend] model_2020_02_22 :: [Entity SqlBackend]
model_2020_02_22 = $(schema "2020_02_22_tpr") model_2020_02_22 = $(schema "2020_02_22_tpr")
model_2020_04_07 :: [Entity SqlBackend]
model_2020_04_07 = $(schema "2020_04_07_tpra")