Skip to content

Commit

Permalink
[Fleet] Enable read bulk agent actions (elastic#206847)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Jan 16, 2025
1 parent ba92d08 commit 5e8d2b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,25 +342,21 @@ export const AgentListTable: React.FC<Props> = (props: Props) => {
totalItemCount: totalAgents,
pageSizeOptions,
}}
selection={
!authz.fleet.allAgents
? undefined
: {
selected,
onSelectionChange,
selectable: isAgentSelectable,
selectableMessage: (selectable, agent) => {
if (selectable) return '';
if (!agent.active) {
return 'This agent is not active';
}
if (agent.policy_id && agentPoliciesIndexedById[agent.policy_id].is_managed) {
return 'This action is not available for agents enrolled in an externally managed agent policy';
}
return '';
},
}
}
selection={{
selected,
onSelectionChange,
selectable: isAgentSelectable,
selectableMessage: (selectable, agent) => {
if (selectable) return '';
if (!agent.active) {
return 'This agent is not active';
}
if (agent.policy_id && agentPoliciesIndexedById[agent.policy_id].is_managed) {
return 'This action is not available for agents enrolled in an externally managed agent policy';
}
return '';
},
}}
onChange={onTableChange}
sorting={sorting}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { createFleetTestRendererMock } from '../../../../../../mock';
import type { LicenseService } from '../../../../services';
import { ExperimentalFeaturesService } from '../../../../services';
import { AgentReassignAgentPolicyModal } from '../../components/agent_reassign_policy_modal';

import { useAuthz } from '../../../../../../hooks/use_authz';
import { useLicense } from '../../../../../../hooks/use_license';

import { AgentBulkActions } from './bulk_actions';
Expand All @@ -24,6 +24,7 @@ jest.mock('../../../../../../services/experimental_features');
const mockedExperimentalFeaturesService = jest.mocked(ExperimentalFeaturesService);

jest.mock('../../../../../../hooks/use_license');
jest.mock('../../../../../../hooks/use_authz');
const mockedUseLicence = useLicense as jest.MockedFunction<typeof useLicense>;

jest.mock('../../components/agent_reassign_policy_modal');
Expand All @@ -49,6 +50,13 @@ const defaultProps = {
describe('AgentBulkActions', () => {
beforeAll(() => {
mockedExperimentalFeaturesService.get.mockReturnValue({} as any);
jest.mocked(useAuthz).mockReturnValue({
fleet: {
allAgents: true,
readAgents: true,
},
integrations: {},
} as any);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
AgentUnenrollAgentModal,
AgentUpgradeAgentModal,
} from '../../components';
import { useLicense } from '../../../../hooks';
import { useAuthz, useLicense } from '../../../../hooks';
import { LICENSE_FOR_SCHEDULE_UPGRADE, AGENTS_PREFIX } from '../../../../../../../common/constants';

import { getCommonTags } from '../utils';
Expand Down Expand Up @@ -65,6 +65,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
sortOrder,
}) => {
const licenseService = useLicense();
const authz = useAuthz();
const isLicenceAllowingScheduleUpgrade = licenseService.hasAtLeast(LICENSE_FOR_SCHEDULE_UPGRADE);

// Bulk actions menu states
Expand Down Expand Up @@ -117,6 +118,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
/>
),
icon: <EuiIcon type="tag" size="m" />,
disabled: !authz.fleet.allAgents,
onClick: (event: any) => {
setTagsPopoverButton((event.target as Element).closest('button')!);
setIsTagAddVisible(!isTagAddVisible);
Expand All @@ -131,6 +133,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
/>
),
icon: <EuiIcon type="pencil" size="m" />,
disabled: !authz.fleet.allAgents,
onClick: () => {
closeMenu();
setIsReassignFlyoutOpen(true);
Expand All @@ -148,6 +151,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
/>
),
icon: <EuiIcon type="refresh" size="m" />,
disabled: !authz.fleet.allAgents,
onClick: () => {
closeMenu();
setUpgradeModalState({ isOpen: true, isScheduled: false, isUpdating: false });
Expand All @@ -165,7 +169,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
/>
),
icon: <EuiIcon type="timeRefresh" size="m" />,
disabled: !isLicenceAllowingScheduleUpgrade,
disabled: !authz.fleet.allAgents || !isLicenceAllowingScheduleUpgrade,
onClick: () => {
closeMenu();
setUpgradeModalState({ isOpen: true, isScheduled: true, isUpdating: false });
Expand All @@ -183,6 +187,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
/>
),
icon: <EuiIcon type="refresh" size="m" />,
disabled: !authz.fleet.allAgents,
onClick: () => {
closeMenu();
setUpgradeModalState({ isOpen: true, isScheduled: false, isUpdating: true });
Expand All @@ -199,6 +204,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
}}
/>
),
disabled: !authz.fleet.readAgents,
icon: <EuiIcon type="download" size="m" />,
onClick: () => {
closeMenu();
Expand All @@ -216,6 +222,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
}}
/>
),
disabled: !authz.fleet.allAgents,
icon: <EuiIcon type="trash" size="m" />,
onClick: () => {
closeMenu();
Expand All @@ -233,6 +240,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
}}
/>
),
disabled: !authz.fleet.readAgents,
icon: <EuiIcon type="exportAction" size="m" />,
onClick: () => {
closeMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ export const SearchAndFilterBar: React.FunctionComponent<SearchAndFilterBarProps
</EuiFilterButton>
</EuiFilterGroup>
</EuiFlexItem>
{(authz.fleet.allAgents && selectionMode === 'manual' && selectedAgents.length) ||
(authz.fleet.allAgents && selectionMode === 'query' && nAgentsInTable > 0) ? (
{(selectionMode === 'manual' && selectedAgents.length) ||
(selectionMode === 'query' && nAgentsInTable > 0) ? (
<EuiFlexItem grow={false}>
<AgentBulkActions
nAgentsInTable={nAgentsInTable}
Expand Down

0 comments on commit 5e8d2b5

Please sign in to comment.