From 1eddad6044c737f7ea182bc3bdfd8a407e8e39ca Mon Sep 17 00:00:00 2001 From: John Schulz Date: Tue, 6 Apr 2021 11:00:30 -0400 Subject: [PATCH] [Fleet] Hide many actions for hosted agent policies (#96160) ## Summary Fixes items 2a, 4a, 5c2, and 6 from https://github.com/elastic/kibana/issues/91906 ### 2a - On the agents table, remove all actions except for "View agent" [code commit](https://github.com/elastic/kibana/commit/a93dd8cc7b106fedc1c921cebe1ed7f5f999731e) Screen Shot 2021-04-02 at 2 00 34 PM Screen Shot 2021-04-02 at 2 00 41 PM ### 4a & 5c2 On the agent policy list page, remove the "add agent" & "copy policy" actions which appears in the [...] actions menu [code commit](https://github.com/elastic/kibana/commit/f0c267f717f8bd3326254f762dabe2434458a4fa) Screen Shot 2021-04-02 at 2 36 57 PM Screen Shot 2021-04-02 at 2 37 02 PM ### 6 - Do not show the the "revoke token" trash icon [code commit](https://github.com/elastic/kibana/commit/cd05cd0f9781956bc8ed1362650bb5bf898efc0d) Screen Shot 2021-04-02 at 2 15 54 PM Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../agent_policy/components/actions_menu.tsx | 79 ++++++------ .../sections/agents/agent_list_page/index.tsx | 120 ++++++++++-------- .../enrollment_token_list_page/index.tsx | 4 +- 3 files changed, 112 insertions(+), 91 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx index 9ee0b0a7b29ee..bdf49f44f4397 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx @@ -48,6 +48,48 @@ export const AgentPolicyActionMenu = memo<{ return ( {(copyAgentPolicyPrompt) => { + const viewPolicyItem = ( + setIsYamlFlyoutOpen(!isYamlFlyoutOpen)} + key="viewPolicy" + > + + + ); + + const menuItems = agentPolicy?.is_managed + ? [viewPolicyItem] + : [ + setIsEnrollmentFlyoutOpen(true)} + key="enrollAgents" + > + + , + viewPolicyItem, + { + copyAgentPolicyPrompt(agentPolicy, onCopySuccess); + }} + key="copyPolicy" + > + + , + ]; return ( <> {isYamlFlyoutOpen ? ( @@ -80,42 +122,7 @@ export const AgentPolicyActionMenu = memo<{ } : undefined } - items={[ - setIsEnrollmentFlyoutOpen(true)} - key="enrollAgents" - > - - , - setIsYamlFlyoutOpen(!isYamlFlyoutOpen)} - key="viewPolicy" - > - - , - { - copyAgentPolicyPrompt(agentPolicy, onCopySuccess); - }} - key="copyPolicy" - > - - , - ]} + items={menuItems} /> ); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx index faf5da5f17f6b..0a35021c7beb0 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx @@ -55,74 +55,81 @@ const REFRESH_INTERVAL_MS = 30000; const RowActions = React.memo<{ agent: Agent; + agentPolicy?: AgentPolicy; refresh: () => void; onReassignClick: () => void; onUnenrollClick: () => void; onUpgradeClick: () => void; -}>(({ agent, refresh, onReassignClick, onUnenrollClick, onUpgradeClick }) => { +}>(({ agent, agentPolicy, refresh, onReassignClick, onUnenrollClick, onUpgradeClick }) => { const { getHref } = useLink(); const hasWriteCapabilites = useCapabilities().write; const isUnenrolling = agent.status === 'unenrolling'; const kibanaVersion = useKibanaVersion(); const [isMenuOpen, setIsMenuOpen] = useState(false); - return ( - setIsMenuOpen(isOpen)} - items={[ - - - , - { - onReassignClick(); - }} - disabled={!agent.active} - key="reassignPolicy" - > + const menuItems = [ + + + , + ]; + + if (agentPolicy?.is_managed === false) { + menuItems.push( + { + onReassignClick(); + }} + disabled={!agent.active} + key="reassignPolicy" + > + + , + { + onUnenrollClick(); + }} + > + {isUnenrolling ? ( - , - { - onUnenrollClick(); - }} - > - {isUnenrolling ? ( - - ) : ( - - )} - , - { - onUpgradeClick(); - }} - > + ) : ( - , - ]} + )} + , + { + onUpgradeClick(); + }} + > + + + ); + } + return ( + setIsMenuOpen(isOpen)} + items={menuItems} /> ); }); @@ -445,9 +452,14 @@ export const AgentListPage: React.FunctionComponent<{}> = () => { actions: [ { render: (agent: Agent) => { + const agentPolicy = + typeof agent.policy_id === 'string' + ? agentPoliciesIndexedById[agent.policy_id] + : undefined; return ( fetchData()} onReassignClick={() => setAgentToReassign(agent)} onUnenrollClick={() => setAgentToUnenroll(agent)} diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx index a19cf714135fc..5d867a1c4c93c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx @@ -242,8 +242,10 @@ export const EnrollmentTokenListPage: React.FunctionComponent<{}> = () => { }), width: '70px', render: (_: any, apiKey: EnrollmentAPIKey) => { + const agentPolicy = agentPolicies.find((c) => c.id === apiKey.policy_id); + const canUnenroll = apiKey.active && !agentPolicy?.is_managed; return ( - apiKey.active && ( + canUnenroll && ( enrollmentAPIKeysRequest.resendRequest()}