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

View file

@ -130,7 +130,7 @@ followW' (Right actorID) = do
[whamlet| [whamlet|
<button type="button" disabled> <button type="button" disabled>
Following Following
^{buttonW POST "Unfollow" (UnfollowRemoteR actorID)} ^{buttonW POST "Unfollow" (UnfollowRemoteR actorID)}
|] |]
else if alreadyRequest else if alreadyRequest
then then
@ -142,7 +142,7 @@ followW' (Right actorID) = do
[whamlet| [whamlet|
<button type="button" disabled> <button type="button" disabled>
Not following Not following
^{buttonW POST "Follow" (FollowRemoteR actorID)} ^{buttonW POST "Follow" (FollowRemoteR actorID)}
|] |]
personNavW :: Entity Person -> Widget personNavW :: Entity Person -> Widget

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

View file

@ -359,7 +359,7 @@
/projects/#ProjectKeyHashid/components ProjectComponentsR GET /projects/#ProjectKeyHashid/components ProjectComponentsR GET
/projects/#ProjectKeyHashid/collabs/#CollabEnableKeyHashid/live ProjectCollabLiveR 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/children ProjectChildrenR GET
/projects/#ProjectKeyHashid/parents ProjectParentsR GET /projects/#ProjectKeyHashid/parents ProjectParentsR GET