UI, Client: Move invite-component form to ProjectComponentsR and use getCapability

This commit is contained in:
Pere Lev 2024-04-29 01:14:56 +03:00
parent 6cdd332d1d
commit d04f161203
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
5 changed files with 26 additions and 45 deletions

View file

@ -38,7 +38,6 @@ module Vervis.Handler.Project
, getProjectComponentsR
, getProjectCollabLiveR
, getProjectInviteCompR
, postProjectInviteCompR
, getProjectChildrenR
@ -484,6 +483,12 @@ getProjectComponentsR projectHash = do
return (i E.^. InstanceHost, ro E.^. RemoteObjectIdent)
getHtml projectID = do
mp <- maybeAuthId
haveAdmin <- fmap isJust $ handlerToWidget $ runDB $ runMaybeT $ do
personID <- MaybeT $ pure mp
project <- lift $ get404 projectID
MaybeT $ getCapability personID (Left $ projectResource project) AP.RoleAdmin
((_, widgetIC), enctypeIC) <- handlerToWidget $ runFormPost projectInviteCompForm
(project, actor, comps, drafts) <- handlerToWidget $ runDB $ do
project <- get404 projectID
actor <- getJust $ projectActor project
@ -556,12 +561,6 @@ getProjectCollabLiveR projectHash enableHash = do
Collab _ resourceID' <- getJust collabID
unless (resourceID == resourceID') notFound
getProjectInviteCompR :: KeyHashid Project -> Handler Html
getProjectInviteCompR projectHash = do
projectID <- decodeKeyHashid404 projectHash
((_result, widget), enctype) <- runFormPost projectInviteCompForm
defaultLayout $(widgetFile "project/component-new")
postProjectInviteCompR :: KeyHashid Project -> Handler Html
postProjectInviteCompR projectHash = do
projectID <- decodeKeyHashid404 projectHash
@ -575,26 +574,21 @@ postProjectInviteCompR projectHash = do
result <- runExceptT $ do
(maybeSummary, audience, invite) <-
C.inviteComponent personID projectID uComp
grantID <- do
cap <- do
maybeItem <- lift $ runDB $ do
resourceID <- projectResource <$> get404 projectID
getGrant resourceID personID
fromMaybeE maybeItem "You need to be a collaborator in the Project to invite people"
grantHash <- encodeKeyHashid grantID
let uCap = encodeRouteHome $ ProjectOutboxItemR projectHash grantHash
getCapability personID (Left resourceID) AP.RoleAdmin
fromMaybeE maybeItem "You need to be have Admin access to the Project to invite components"
uCap <- lift $ renderActivityURI cap
(localRecips, remoteRecips, fwdHosts, action) <-
C.makeServerInput (Just uCap) maybeSummary audience $ AP.InviteActivity invite
let cap =
Left (LocalActorProject projectID, LocalActorProject projectHash, grantID)
let cap' = first (\ (la, i) -> (la, error "lah", i)) cap
handleViaActor
personID (Just cap) localRecips remoteRecips fwdHosts action
personID (Just cap') localRecips remoteRecips fwdHosts action
case result of
Left e -> do
setMessage $ toHtml e
redirect $ ProjectInviteCompR projectHash
Right inviteID -> do
setMessage "Invite sent"
Left e -> setMessage $ toHtml e
Right inviteID -> setMessage "Invite sent"
redirect $ ProjectComponentsR projectHash
getProjectChildrenR :: KeyHashid Project -> Handler TypedContent

View file

@ -1,18 +0,0 @@
$# This file is part of Vervis.
$#
$# Written in 2016, 2023 by fr33domlover <fr33domlover@riseup.net>.
$#
$# ♡ Copying is an act of love. Please copy, reuse and share.
$#
$# The author(s) have dedicated all copyright and related and neighboring
$# rights to this software to the public domain worldwide. This software is
$# distributed without any warranty.
$#
$# You should have received a copy of the CC0 Public Domain Dedication along
$# with this software. If not, see
$# <http://creativecommons.org/publicdomain/zero/1.0/>.
<form method=POST action=@{ProjectInviteCompR projectHash} enctype=#{enctype}>
^{widget}
<div class="submit">
<input type="submit">

View file

@ -1,6 +1,7 @@
$# 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.
$#
@ -28,6 +29,12 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<td>#{showDate since}
$# <td>^{buttonW POST "Remove" (ProjectRemoveR projectHash ctID)}
$if haveAdmin
<p>Invite a component:
<form method=POST action=@{ProjectInviteCompR projectHash} enctype=#{enctypeIC}>
^{widgetIC}
<input type="submit">
<h2>Component requests in progress
<table>
@ -38,5 +45,3 @@ $# <td>^{buttonW POST "Remove" (ProjectRemoveR projectHash ctID)}
<tr>
<td>#{show role}
<td>^{componentLinkFedW comp}
<a href=@{ProjectInviteCompR projectHash}>Invite…

View file

@ -359,7 +359,7 @@
/projects/#ProjectKeyHashid/components ProjectComponentsR GET
/projects/#ProjectKeyHashid/collabs/#CollabEnableKeyHashid/live ProjectCollabLiveR GET
/projects/#ProjectKeyHashid/invite-component ProjectInviteCompR GET POST
/projects/#ProjectKeyHashid/invite-component ProjectInviteCompR POST
/projects/#ProjectKeyHashid/children ProjectChildrenR GET
/projects/#ProjectKeyHashid/parents ProjectParentsR GET