Commit fb4c948f authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge remote-tracking branch 'origin/396-dev-list-persons-in-team' into dev-merge

parents ff2130a2 9b5b433a
module Gargantext.Components.Forest.Tree.Node.Action.ManageTeam where
import Gargantext.Prelude
import Data.Array (filter)
import Data.Either (Either(..))
import Effect.Aff (runAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
import Gargantext.Components.GraphQL.Endpoints (deleteTeamMembership, getTeam)
import Gargantext.Components.GraphQL.Team (TeamMember)
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session)
import Gargantext.Types (ID, NodeType)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.ManageTeam"
type ActionManageTeam = (
id :: ID
, nodeType :: NodeType
, session :: Session
)
actionManageTeam :: R2.Component ActionManageTeam
actionManageTeam = R.createElement actionManageTeamCpt
actionManageTeamCpt :: R.Component ActionManageTeam
actionManageTeamCpt = here.component "actionManageTeam" cpt where
cpt {id, session} _ = do
useLoader { errorHandler
, loader: loadTeam
, path: { nodeId: id, session }
, render: \team -> teamLayoutWrapper { team
, nodeId: id
, session
} []
}
where
errorHandler = logRESTError here "teamLayout"
type TeamProps =
( nodeId :: ID
, session :: Session
, team :: (Array TeamMember)
)
teamLayoutWrapper :: R2.Component TeamProps
teamLayoutWrapper = R.createElement teamLayoutWrapperCpt
teamLayoutWrapperCpt :: R.Component TeamProps
teamLayoutWrapperCpt = here.component "teamLayoutWrapper" cpt where
cpt {nodeId, session, team} _ = do
teamS <- T.useBox team
team' <- T.useLive T.unequal teamS
error <- T.useBox ""
error' <- T.useLive T.unequal error
pure $ teamLayoutRows {nodeId, session, team: teamS, team', error, error'}
type TeamRowProps =
( nodeId :: ID
, session :: Session
, team :: T.Box (Array TeamMember)
, error :: T.Box String
, team' :: Array TeamMember
, error' :: String
)
teamLayoutRows :: R2.Leaf TeamRowProps
teamLayoutRows = R2.leafComponent teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamRowProps
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
cpt { team, nodeId, session, error, team', error' } _ = do
pure $ Tools.panel (map makeTeam team') (H.div {} [H.text error'])
where
makeTeam :: TeamMember -> R.Element
makeTeam { username, shared_folder_id } = H.div {className: "from-group row"} [ H.div { className: "col-8" } [ H.text username ]
, H.a { className: "text-danger col-2 fa fa-times"
, title: "Remove user from team"
, type: "button"
, on: {click: submit shared_folder_id }
} []
]
submit sharedFolderId _ = do
runAff_ callback $ saveDeleteTeam { session, nodeId, sharedFolderId }
callback res =
case res of
Left _ -> do
_ <- liftEffect $ T.write "Only the Team owner can remove users" error
pure unit
Right val ->
case val of
Left _ -> do
pure unit
Right r -> do
T.write_ (filter (\tm -> tm.shared_folder_id /= r) team') team
-------------------------------------------------------------
type LoadProps =
(
session :: Session,
nodeId :: Int
)
loadTeam :: Record LoadProps -> AffRESTError (Array TeamMember)
loadTeam { session, nodeId } = getTeam session nodeId
type DeleteProps =
(
session :: Session,
nodeId :: Int,
sharedFolderId :: Int
)
saveDeleteTeam ∷ Record DeleteProps -> AffRESTError Int
saveDeleteTeam { session, nodeId, sharedFolderId } = deleteTeamMembership session sharedFolderId nodeId
...@@ -22,6 +22,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Types (Action) ...@@ -22,6 +22,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Types (Action)
import Gargantext.Components.Forest.Tree.Node.Action.Update (update) import Gargantext.Components.Forest.Tree.Node.Action.Update (update)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (actionUpload) import Gargantext.Components.Forest.Tree.Node.Action.Upload (actionUpload)
import Gargantext.Components.Forest.Tree.Node.Action.WriteNodesDocuments (actionWriteNodesDocuments) import Gargantext.Components.Forest.Tree.Node.Action.WriteNodesDocuments (actionWriteNodesDocuments)
import Gargantext.Components.Forest.Tree.Node.Action.ManageTeam (actionManageTeam)
import Gargantext.Components.Forest.Tree.Node.Box.Types (NodePopupProps, NodePopupS) import Gargantext.Components.Forest.Tree.Node.Box.Types (NodePopupProps, NodePopupS)
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), SettingsBox(..), glyphiconNodeAction, settingsBox) import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), SettingsBox(..), glyphiconNodeAction, settingsBox)
import Gargantext.Components.Forest.Tree.Node.Status (Status(..), hasStatus) import Gargantext.Components.Forest.Tree.Node.Status (Status(..), hasStatus)
...@@ -189,6 +190,7 @@ panelActionCpt = here.component "panelAction" cpt ...@@ -189,6 +190,7 @@ panelActionCpt = here.component "panelAction" cpt
cpt { action: Download, id, nodeType, session} _ = pure $ actionDownload { id, nodeType, session } [] cpt { action: Download, id, nodeType, session} _ = pure $ actionDownload { id, nodeType, session } []
cpt { action: Upload, dispatch, id, nodeType, session} _ = pure $ actionUpload { dispatch, id, nodeType, session } [] cpt { action: Upload, dispatch, id, nodeType, session} _ = pure $ actionUpload { dispatch, id, nodeType, session } []
cpt { action: Delete, nodeType, dispatch} _ = pure $ actionDelete { dispatch, nodeType } [] cpt { action: Delete, nodeType, dispatch} _ = pure $ actionDelete { dispatch, nodeType } []
cpt { action: ManageTeam, nodeType, id, session} _ = pure $ actionManageTeam { id, nodeType, session } []
cpt { action: Add xs, dispatch, id, name, nodeType} _ = cpt { action: Add xs, dispatch, id, name, nodeType} _ =
pure $ addNodeView {dispatch, id, name, nodeType, nodeTypes: xs} [] pure $ addNodeView {dispatch, id, name, nodeType, nodeTypes: xs} []
cpt { action: Refresh , dispatch, nodeType } _ = pure $ update { dispatch, nodeType } [] cpt { action: Refresh , dispatch, nodeType } _ = pure $ update { dispatch, nodeType } []
......
...@@ -16,6 +16,7 @@ data NodeAction = Documentation NodeType ...@@ -16,6 +16,7 @@ data NodeAction = Documentation NodeType
| Download | Upload | Refresh | Config | Download | Upload | Refresh | Config
| Delete | Delete
| Share | Share
| ManageTeam
| Publish { subTreeParams :: SubTreeParams } | Publish { subTreeParams :: SubTreeParams }
| Add (Array NodeType) | Add (Array NodeType)
| Merge { subTreeParams :: SubTreeParams } | Merge { subTreeParams :: SubTreeParams }
...@@ -37,6 +38,7 @@ instance Eq NodeAction where ...@@ -37,6 +38,7 @@ instance Eq NodeAction where
eq Clone Clone = true eq Clone Clone = true
eq Delete Delete = true eq Delete Delete = true
eq Share Share = true eq Share Share = true
eq ManageTeam ManageTeam = true
eq (Link x) (Link y) = x == y eq (Link x) (Link y) = x == y
eq (Add x) (Add y) = x == y eq (Add x) (Add y) = x == y
eq (Merge x) (Merge y) = x == y eq (Merge x) (Merge y) = x == y
...@@ -57,6 +59,7 @@ instance Show NodeAction where ...@@ -57,6 +59,7 @@ instance Show NodeAction where
show Clone = "Clone" show Clone = "Clone"
show Delete = "Delete" show Delete = "Delete"
show Share = "Share" show Share = "Share"
show ManageTeam = "Team"
show Config = "Config" show Config = "Config"
show (Link _) = "Link to " -- <> show x show (Link _) = "Link to " -- <> show x
show (Add _) = "Add Child" -- foldl (\a b -> a <> show b) "Add " xs show (Add _) = "Add Child" -- foldl (\a b -> a <> show b) "Add " xs
...@@ -78,6 +81,7 @@ glyphiconNodeAction (Merge _) = "random" ...@@ -78,6 +81,7 @@ glyphiconNodeAction (Merge _) = "random"
glyphiconNodeAction Refresh = "refresh" glyphiconNodeAction Refresh = "refresh"
glyphiconNodeAction Config = "wrench" glyphiconNodeAction Config = "wrench"
glyphiconNodeAction Share = "user-plus" glyphiconNodeAction Share = "user-plus"
glyphiconNodeAction ManageTeam = "users"
glyphiconNodeAction AddingContact = "user-plus" glyphiconNodeAction AddingContact = "user-plus"
glyphiconNodeAction (Move _) = "share-square-o" glyphiconNodeAction (Move _) = "share-square-o"
glyphiconNodeAction (Publish _) = fldr FolderPublic true glyphiconNodeAction (Publish _) = fldr FolderPublic true
...@@ -137,6 +141,7 @@ settingsBox Team = ...@@ -137,6 +141,7 @@ settingsBox Team =
, NodeFrameVisio , NodeFrameVisio
] ]
, Share , Share
, ManageTeam
, Delete , Delete
] ]
} }
......
...@@ -14,6 +14,7 @@ import Gargantext.Components.GraphQL.IMT as GQLIMT ...@@ -14,6 +14,7 @@ import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node) import Gargantext.Components.GraphQL.Node (Node)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel) import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM) import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.Team (TeamMember, TeamDeleteM)
import Gargantext.Ends (Backend(..)) import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..)) import Gargantext.Sessions (Session(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -77,7 +78,9 @@ type Schema ...@@ -77,7 +78,9 @@ type Schema
, users :: { user_id :: Int } ==> Array User , users :: { user_id :: Int } ==> Array User
, tree :: { root_id :: Int } ==> TreeFirstLevel , tree :: { root_id :: Int } ==> TreeFirstLevel
, annuaire_contacts :: { contact_id :: Int } ==> Array AnnuaireContact , annuaire_contacts :: { contact_id :: Int } ==> Array AnnuaireContact
, team :: { team_node_id :: Int } ==> Array TeamMember
} }
type Mutation type Mutation
= { update_user_info :: UserInfoM ==> Int } = { update_user_info :: UserInfoM ==> Int
, delete_team_membership :: TeamDeleteM ==> Array Int }
...@@ -2,22 +2,24 @@ module Gargantext.Components.GraphQL.Endpoints where ...@@ -2,22 +2,24 @@ module Gargantext.Components.GraphQL.Endpoints where
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.GraphQL.Node (Node, nodeParentQuery, nodesQuery)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
import Data.Array as A import Data.Array as A
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL (queryGql) import Gargantext.Components.GraphQL (getClient, queryGql)
import Gargantext.Components.GraphQL.IMT as GQLIMT import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node, nodeParentQuery, nodesQuery)
import Gargantext.Components.GraphQL.Team (TeamMember, teamQuery)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
import Gargantext.Config.REST (RESTError(..), AffRESTError) import Gargantext.Config.REST (RESTError(..), AffRESTError)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session(..))
import Gargantext.Types (NodeType) import Gargantext.Types (NodeType)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargnatext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery) import Gargnatext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Query (mutation)
import GraphQL.Client.Variables (withVars) import GraphQL.Client.Variables (withVars)
here :: R2.Here here :: R2.Here
...@@ -70,3 +72,28 @@ getTreeFirstLevel session id = do ...@@ -70,3 +72,28 @@ getTreeFirstLevel session id = do
{ tree } <- queryGql session "get tree first level" $ treeFirstLevelQuery `withVars` { id } { tree } <- queryGql session "get tree first level" $ treeFirstLevelQuery `withVars` { id }
liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree
pure $ Right tree -- TODO: error handling pure $ Right tree -- TODO: error handling
getTeam :: Session -> Int -> AffRESTError (Array TeamMember)
getTeam session id = do
{ team } <- queryGql session "get team" $ teamQuery `withVars` { id }
liftEffect $ here.log2 "[getTree] data" team
pure $ Right team
type SharedFolderId = Int
type TeamNodeId = Int
deleteTeamMembership :: Session -> SharedFolderId -> TeamNodeId -> AffRESTError Int
deleteTeamMembership session sharedFolderId teamNodeId = do
let token = getToken session
client <- liftEffect $ getClient session
{ delete_team_membership } <- mutation
client
"delete_team_membership"
{ delete_team_membership: onlyArgs { token: token
, shared_folder_id: sharedFolderId
, team_node_id: teamNodeId } }
pure $ case A.head delete_team_membership of
Nothing -> Left (CustomError $ "Failed to delete team membership. team node id=" <> show teamNodeId <> " shared folder id=" <> show sharedFolderId)
Just _ -> Right sharedFolderId
where
getToken (Session { token }) = token
module Gargantext.Components.GraphQL.Team where
import Gargantext.Prelude
import GraphQL.Client.Args (NotNull, (=>>))
import GraphQL.Client.Variable (Var(..))
type TeamMember
= { username :: String
, shared_folder_id :: Int
}
type TeamDeleteM
= { token :: NotNull String
, shared_folder_id :: Int
, team_node_id :: Int
}
teamQuery = { team: { team_node_id: Var :: _ "id" Int } =>>
{ username: unit
, shared_folder_id: unit }
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment