Skip to content

Commit

Permalink
[Fleet] Hide many actions for hosted agent policies (#96160)
Browse files Browse the repository at this point in the history
## Summary

Fixes items 2a, 4a, 5c2, and 6 from #91906

### 2a - On the agents table, remove all actions except for "View agent"

[code commit](a93dd8c) 

<img width="1090" alt="Screen Shot 2021-04-02 at 2 00 34 PM" src="https://user-images.githubusercontent.com/57655/113446102-1b40bd00-93c5-11eb-804b-2afec37a176b.png">
<img width="1100" alt="Screen Shot 2021-04-02 at 2 00 41 PM" src="https://user-images.githubusercontent.com/57655/113446103-1b40bd00-93c5-11eb-8aba-daa1aa539955.png">

### 4a & 5c2 On the agent policy list page, remove the "add agent" & "copy policy" actions which appears in the [...] actions menu
[code commit](f0c267f)
<img width="1067" alt="Screen Shot 2021-04-02 at 2 36 57 PM" src="https://user-images.githubusercontent.com/57655/113446281-7b376380-93c5-11eb-9f82-03e957e6656c.png">
<img width="1104" alt="Screen Shot 2021-04-02 at 2 37 02 PM" src="https://user-images.githubusercontent.com/57655/113446282-7bcffa00-93c5-11eb-942c-1a98ebbab385.png">


### 6 - Do not show the the "revoke token" trash icon

[code commit](cd05cd0)
<img width="1088" alt="Screen Shot 2021-04-02 at 2 15 54 PM" src="https://user-images.githubusercontent.com/57655/113446176-4a572e80-93c5-11eb-9740-9723c1cb9f50.png">

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
John Schulz and kibanamachine authored Apr 6, 2021
1 parent 2745a6e commit 2adc060
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,48 @@ export const AgentPolicyActionMenu = memo<{
return (
<AgentPolicyCopyProvider>
{(copyAgentPolicyPrompt) => {
const viewPolicyItem = (
<EuiContextMenuItem
icon="inspect"
onClick={() => setIsYamlFlyoutOpen(!isYamlFlyoutOpen)}
key="viewPolicy"
>
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.viewPolicyText"
defaultMessage="View policy"
/>
</EuiContextMenuItem>
);

const menuItems = agentPolicy?.is_managed
? [viewPolicyItem]
: [
<EuiContextMenuItem
disabled={!hasWriteCapabilities}
icon="plusInCircle"
onClick={() => setIsEnrollmentFlyoutOpen(true)}
key="enrollAgents"
>
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.enrollAgentActionText"
defaultMessage="Add agent"
/>
</EuiContextMenuItem>,
viewPolicyItem,
<EuiContextMenuItem
disabled={!hasWriteCapabilities}
icon="copy"
onClick={() => {
copyAgentPolicyPrompt(agentPolicy, onCopySuccess);
}}
key="copyPolicy"
>
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.copyPolicyActionText"
defaultMessage="Copy policy"
/>
</EuiContextMenuItem>,
];
return (
<>
{isYamlFlyoutOpen ? (
Expand Down Expand Up @@ -80,42 +122,7 @@ export const AgentPolicyActionMenu = memo<{
}
: undefined
}
items={[
<EuiContextMenuItem
disabled={!hasWriteCapabilities}
icon="plusInCircle"
onClick={() => setIsEnrollmentFlyoutOpen(true)}
key="enrollAgents"
>
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.enrollAgentActionText"
defaultMessage="Add agent"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="inspect"
onClick={() => setIsYamlFlyoutOpen(!isYamlFlyoutOpen)}
key="viewPolicy"
>
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.viewPolicyText"
defaultMessage="View policy"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
disabled={!hasWriteCapabilities}
icon="copy"
onClick={() => {
copyAgentPolicyPrompt(agentPolicy, onCopySuccess);
}}
key="copyPolicy"
>
<FormattedMessage
id="xpack.fleet.agentPolicyActionMenu.copyPolicyActionText"
defaultMessage="Copy policy"
/>
</EuiContextMenuItem>,
]}
items={menuItems}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<ContextMenuActions
isOpen={isMenuOpen}
onChange={(isOpen) => setIsMenuOpen(isOpen)}
items={[
<EuiContextMenuItem
icon="inspect"
href={getHref('fleet_agent_details', { agentId: agent.id })}
key="viewAgent"
>
<FormattedMessage id="xpack.fleet.agentList.viewActionText" defaultMessage="View agent" />
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="pencil"
onClick={() => {
onReassignClick();
}}
disabled={!agent.active}
key="reassignPolicy"
>
const menuItems = [
<EuiContextMenuItem
icon="inspect"
href={getHref('fleet_agent_details', { agentId: agent.id })}
key="viewAgent"
>
<FormattedMessage id="xpack.fleet.agentList.viewActionText" defaultMessage="View agent" />
</EuiContextMenuItem>,
];

if (agentPolicy?.is_managed === false) {
menuItems.push(
<EuiContextMenuItem
icon="pencil"
onClick={() => {
onReassignClick();
}}
disabled={!agent.active}
key="reassignPolicy"
>
<FormattedMessage
id="xpack.fleet.agentList.reassignActionText"
defaultMessage="Assign to new policy"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
disabled={!hasWriteCapabilites || !agent.active}
icon="trash"
onClick={() => {
onUnenrollClick();
}}
>
{isUnenrolling ? (
<FormattedMessage
id="xpack.fleet.agentList.reassignActionText"
defaultMessage="Assign to new policy"
id="xpack.fleet.agentList.forceUnenrollOneButton"
defaultMessage="Force unenroll"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
disabled={!hasWriteCapabilites || !agent.active}
icon="trash"
onClick={() => {
onUnenrollClick();
}}
>
{isUnenrolling ? (
<FormattedMessage
id="xpack.fleet.agentList.forceUnenrollOneButton"
defaultMessage="Force unenroll"
/>
) : (
<FormattedMessage
id="xpack.fleet.agentList.unenrollOneButton"
defaultMessage="Unenroll agent"
/>
)}
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="refresh"
disabled={!isAgentUpgradeable(agent, kibanaVersion)}
onClick={() => {
onUpgradeClick();
}}
>
) : (
<FormattedMessage
id="xpack.fleet.agentList.upgradeOneButton"
defaultMessage="Upgrade agent"
id="xpack.fleet.agentList.unenrollOneButton"
defaultMessage="Unenroll agent"
/>
</EuiContextMenuItem>,
]}
)}
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="refresh"
disabled={!isAgentUpgradeable(agent, kibanaVersion)}
onClick={() => {
onUpgradeClick();
}}
>
<FormattedMessage
id="xpack.fleet.agentList.upgradeOneButton"
defaultMessage="Upgrade agent"
/>
</EuiContextMenuItem>
);
}
return (
<ContextMenuActions
isOpen={isMenuOpen}
onChange={(isOpen) => setIsMenuOpen(isOpen)}
items={menuItems}
/>
);
});
Expand Down Expand Up @@ -453,9 +460,14 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
actions: [
{
render: (agent: Agent) => {
const agentPolicy =
typeof agent.policy_id === 'string'
? agentPoliciesIndexedById[agent.policy_id]
: undefined;
return (
<RowActions
agent={agent}
agentPolicy={agentPolicy}
refresh={() => fetchData()}
onReassignClick={() => setAgentToReassign(agent)}
onUnenrollClick={() => setAgentToUnenroll(agent)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
<DeleteButton
apiKey={apiKey}
refresh={() => enrollmentAPIKeysRequest.resendRequest()}
Expand Down

0 comments on commit 2adc060

Please sign in to comment.