UI: Deck: Form for adding to a project

This commit is contained in:
Pere Lev 2024-04-29 02:08:44 +03:00
parent d04f161203
commit ffe1c39fd3
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
6 changed files with 76 additions and 8 deletions

View file

@ -957,6 +957,7 @@ instance YesodBreadcrumbs App where
DeckProjectsR d -> ("Projects", Just $ DeckR d) DeckProjectsR d -> ("Projects", Just $ DeckR d)
DeckApproveCompR d c -> ("", Nothing) DeckApproveCompR d c -> ("", Nothing)
DeckAddProjectR d -> ("", Nothing)
TicketR d t -> ("#" <> keyHashidText t, Just $ DeckTicketsR d) TicketR d t -> ("#" <> keyHashidText t, Just $ DeckTicketsR d)
TicketDiscussionR d t -> ("Discussion", Just $ TicketR d t) TicketDiscussionR d t -> ("Discussion", Just $ TicketR d t)

View file

@ -43,6 +43,7 @@ module Vervis.Handler.Deck
, postDeckInviteR , postDeckInviteR
, postDeckRemoveR , postDeckRemoveR
, getDeckProjectsR , getDeckProjectsR
, postDeckAddProjectR
, postDeckApproveCompR , postDeckApproveCompR
@ -69,6 +70,7 @@ import Control.Monad
import Control.Monad.Trans.Except import Control.Monad.Trans.Except
import Control.Monad.Trans.Maybe import Control.Monad.Trans.Maybe
import Data.Aeson import Data.Aeson
import Data.Bifunctor
import Data.Bitraversable import Data.Bitraversable
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import Data.Default.Class import Data.Default.Class
@ -83,11 +85,13 @@ import Text.Blaze.Html (Html)
import Yesod.Auth import Yesod.Auth
import Yesod.Core import Yesod.Core
import Yesod.Core.Handler (redirect, setMessage, lookupPostParam, notFound) import Yesod.Core.Handler (redirect, setMessage, lookupPostParam, notFound)
import Yesod.Form
import Yesod.Form.Functions (runFormPost, runFormGet) import Yesod.Form.Functions (runFormPost, runFormGet)
import Yesod.Form.Types (FormResult (..)) import Yesod.Form.Types (FormResult (..))
import Yesod.Persist.Core (runDB, get404, getBy404) import Yesod.Persist.Core (runDB, get404, getBy404)
import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Database.Esqueleto as E import qualified Database.Esqueleto as E
import Database.Persist.JSON import Database.Persist.JSON
@ -110,6 +114,7 @@ import Yesod.Persist.Local
import Vervis.Access import Vervis.Access
import Vervis.API import Vervis.API
import Vervis.Data.Actor
import Vervis.Federation.Auth import Vervis.Federation.Auth
import Vervis.Federation.Discussion import Vervis.Federation.Discussion
import Vervis.Federation.Offer import Vervis.Federation.Offer
@ -176,12 +181,9 @@ getDeckR deckHash = do
, AP.ticketTrackerTeam = Nothing , AP.ticketTrackerTeam = Nothing
, AP.ticketTrackerCollaborators = , AP.ticketTrackerCollaborators =
encodeRouteLocal $ DeckCollabsR deckHash encodeRouteLocal $ DeckCollabsR deckHash
, AP.ticketTrackerProjects =
encodeRouteLocal $ DeckProjectsR deckHash
} }
followButton =
followW
(DeckFollowR deckHash)
(DeckUnfollowR deckHash)
(actorFollowers actor)
provideHtmlAndAP deckAP $ redirect $ DeckTicketsR deckHash provideHtmlAndAP deckAP $ redirect $ DeckTicketsR deckHash
@ -581,6 +583,12 @@ postDeckRemoveR deckHash collabID = do
getDeckProjectsR :: KeyHashid Deck -> Handler Html getDeckProjectsR :: KeyHashid Deck -> Handler Html
getDeckProjectsR deckHash = do getDeckProjectsR deckHash = do
deckID <- decodeKeyHashid404 deckHash deckID <- decodeKeyHashid404 deckHash
mp <- maybeAuthId
haveAdmin <- fmap isJust $ runDB $ runMaybeT $ do
personID <- MaybeT $ pure mp
deck <- lift $ get404 deckID
MaybeT $ getCapability personID (Left $ deckResource deck) AP.RoleAdmin
((_, widgetAP), enctypeAP) <- runFormPost addProjectForm
(deck, actor, stems) <- runDB $ do (deck, actor, stems) <- runDB $ do
deck <- get404 deckID deck <- get404 deckID
actor <- getJust $ deckActor deck actor <- getJust $ deckActor deck
@ -614,6 +622,53 @@ getDeckProjectsR deckHash = do
return (deck, actor, stems') return (deck, actor, stems')
defaultLayout $(widgetFile "deck/projects") defaultLayout $(widgetFile "deck/projects")
addProjectForm = renderDivs $
areq fedUriField "(URI) Project" Nothing
postDeckAddProjectR :: KeyHashid Deck -> Handler ()
postDeckAddProjectR deckHash = do
deckID <- decodeKeyHashid404 deckHash
uProject <-
runFormPostRedirect (DeckProjectsR deckHash) addProjectForm
personEntity@(Entity personID person) <- requireAuth
personHash <- encodeKeyHashid personID
encodeRouteHome <- getEncodeRouteHome
let uDeck = encodeRouteHome $ DeckR deckHash
result <- runExceptT $ do
uCollection <- do
project <- do
u <- parseFedURIOld uProject
bitraverse parseLocalActorE pure u
case project of
Left la ->
encodeRouteHome . renderLocalActor <$> hashLocalActor la
Right (ObjURI h lu) -> do
manager <- asksSite appHttpManager
AP.ResourceWithCollections _ _ mluComponents _ <- ExceptT $ liftIO $ first (T.pack . show) <$> AP.fetchRWC manager h lu
luComponents <- fromMaybeE mluComponents "No components collection"
return $ ObjURI h luComponents
(maybeSummary, audience, add) <- C.add personID uDeck uCollection AP.RoleAdmin
cap <- do
maybeItem <- lift $ runDB $ do
resourceID <- deckResource <$> get404 deckID
getCapability personID (Left resourceID) AP.RoleAdmin
fromMaybeE maybeItem "You need to be have Admin access to the Deck to add projects"
uCap <- lift $ renderActivityURI cap
(localRecips, remoteRecips, fwdHosts, action) <-
C.makeServerInput (Just uCap) maybeSummary audience $ AP.AddActivity add
let cap' = first (\ (la, i) -> (la, error "lah", i)) cap
handleViaActor
personID (Just cap') localRecips remoteRecips fwdHosts action
case result of
Left e -> setMessage $ toHtml e
Right inviteID -> setMessage "Add sent"
redirect $ DeckProjectsR deckHash
postDeckApproveCompR :: KeyHashid Deck -> KeyHashid Stem -> Handler Html postDeckApproveCompR :: KeyHashid Deck -> KeyHashid Stem -> Handler Html
postDeckApproveCompR deckHash stemHash = do postDeckApproveCompR deckHash stemHash = do
deckID <- decodeKeyHashid404 deckHash deckID <- decodeKeyHashid404 deckHash

View file

@ -565,7 +565,7 @@ postProjectInviteCompR :: KeyHashid Project -> Handler Html
postProjectInviteCompR projectHash = do postProjectInviteCompR projectHash = do
projectID <- decodeKeyHashid404 projectHash projectID <- decodeKeyHashid404 projectHash
uComp <- uComp <-
runFormPostRedirect (ProjectInviteCompR projectHash) projectInviteCompForm runFormPostRedirect (ProjectComponentsR projectHash) projectInviteCompForm
personEntity@(Entity personID person) <- requireAuth personEntity@(Entity personID person) <- requireAuth
personHash <- encodeKeyHashid personID personHash <- encodeKeyHashid personID

View file

@ -678,6 +678,7 @@ data TicketTracker u = TicketTracker
{ ticketTrackerActor :: Actor u { ticketTrackerActor :: Actor u
, ticketTrackerTeam :: Maybe LocalURI , ticketTrackerTeam :: Maybe LocalURI
, ticketTrackerCollaborators :: LocalURI , ticketTrackerCollaborators :: LocalURI
, ticketTrackerProjects :: LocalURI
} }
instance ActivityPub TicketTracker where instance ActivityPub TicketTracker where
@ -690,10 +691,12 @@ instance ActivityPub TicketTracker where
TicketTracker a TicketTracker a
<$> withAuthorityMaybeO h (o .:|? "team") <$> withAuthorityMaybeO h (o .:|? "team")
<*> withAuthorityO h (o .: "collaborators") <*> withAuthorityO h (o .: "collaborators")
toSeries h (TicketTracker actor team collabs) <*> withAuthorityO h (o .: "context")
toSeries h (TicketTracker actor team collabs projects)
= toSeries h actor = toSeries h actor
<> "team" .= (ObjURI h <$> team) <> "team" .= (ObjURI h <$> team)
<> "collaborators" .= ObjURI h collabs <> "collaborators" .= ObjURI h collabs
<> "context" .= ObjURI h projects
data PatchTracker u = PatchTracker data PatchTracker u = PatchTracker
{ patchTrackerActor :: Actor u { patchTrackerActor :: Actor u

View file

@ -1,6 +1,7 @@
$# This file is part of Vervis. $# This file is part of Vervis.
$# $#
$# Written in 2016, 2019, 2022, 2023 by fr33domlover <fr33domlover@riseup.net>. $# Written in 2016, 2019, 2022, 2023, 2024
$# by fr33domlover <fr33domlover@riseup.net>.
$# $#
$# ♡ Copying is an act of love. Please copy, reuse and share. $# ♡ Copying is an act of love. Please copy, reuse and share.
$# $#
@ -34,3 +35,9 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
$if not gestured $if not gestured
<td>^{buttonW POST "Approve" (DeckApproveCompR deckHash stemHash)} <td>^{buttonW POST "Approve" (DeckApproveCompR deckHash stemHash)}
$# <td>^{buttonW POST "Remove" (DeckRemoveR deckHash ctID)} $# <td>^{buttonW POST "Remove" (DeckRemoveR deckHash ctID)}
$if haveAdmin
<p>Add deck to a project:
<form method=POST action=@{DeckAddProjectR deckHash} enctype=#{enctypeAP}>
^{widgetAP}
<input type="submit">

View file

@ -249,6 +249,8 @@
/decks/#DeckKeyHashid/remove/#CollabId DeckRemoveR POST /decks/#DeckKeyHashid/remove/#CollabId DeckRemoveR POST
/decks/#DeckKeyHashid/projects DeckProjectsR GET /decks/#DeckKeyHashid/projects DeckProjectsR GET
/decks/#DeckKeyHashid/add-project DeckAddProjectR POST
/decks/#DeckKeyHashid/projects/approve/#StemKeyHashid DeckApproveCompR POST /decks/#DeckKeyHashid/projects/approve/#StemKeyHashid DeckApproveCompR POST
---- Ticket ------------------------------------------------------------------ ---- Ticket ------------------------------------------------------------------