Skip to content

Commit

Permalink
add 'user-managed' label to the rule details page for the api keys cr…
Browse files Browse the repository at this point in the history
…eated by users
  • Loading branch information
ersin-erdal committed Apr 25, 2023
1 parent b0c7c2d commit eec9043
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const transformRule: RewriteRequestCase<Rule> = ({
created_at: createdAt,
updated_at: updatedAt,
api_key_owner: apiKeyOwner,
api_key_created_by_user: apiKeyCreatedByUser,
notify_when: notifyWhen,
mute_all: muteAll,
muted_alert_ids: mutedInstanceIds,
Expand Down Expand Up @@ -95,6 +96,7 @@ export const transformRule: RewriteRequestCase<Rule> = ({
activeSnoozes,
...(lastRun ? { lastRun: transformLastRun(lastRun) } : {}),
...(nextRun ? { nextRun } : {}),
...(apiKeyCreatedByUser !== undefined ? { apiKeyCreatedByUser } : {}),
...rest,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import {
import { useKibana } from '../../../../common/lib/kibana';
import { ruleTypeRegistryMock } from '../../../rule_type_registry.mock';

export const DATE_9999 = '9999-12-31T12:34:56.789Z';

jest.mock('../../../../common/lib/kibana');

jest.mock('../../../../common/lib/config_api', () => ({
Expand Down Expand Up @@ -110,12 +108,21 @@ describe('rule_details', () => {
});

it('renders the API key owner badge when user can manage API keys', () => {
const rule = mockRule();
expect(
shallow(
<RuleDetails rule={rule} ruleType={ruleType} actionTypes={[]} {...mockRuleApis} />
).find(<EuiBadge>{rule.apiKeyOwner}</EuiBadge>)
).toBeTruthy();
const rule = mockRule({ apiKeyOwner: 'elastic' });
const wrapper = mountWithIntl(
<RuleDetails rule={rule} ruleType={ruleType} actionTypes={[]} {...mockRuleApis} />
);
expect(wrapper.find('[data-test-subj="apiKeyOwnerLabel"]').first().text()).toBe('elastic');
});

it('renders the user-managed label when apiKeyCreatedByUser is true', async () => {
const rule = mockRule({ apiKeyOwner: 'elastic', apiKeyCreatedByUser: true });
const wrapper = mountWithIntl(
<RuleDetails rule={rule} ruleType={ruleType} actionTypes={[]} {...mockRuleApis} />
);
expect(wrapper.find('[data-test-subj="apiKeyOwnerLabel"]').first().text()).toBe(
'elastic (user-managed)'
);
});

it(`doesn't render the API key owner badge when user can't manage API keys`, () => {
Expand Down Expand Up @@ -819,6 +826,7 @@ describe('rule_details', () => {
lastExecutionDate: new Date('2020-08-20T19:23:38Z'),
},
revision: 0,
apiKeyCreatedByUser: false,
...overloads,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
EuiButton,
EuiIcon,
EuiLink,
EuiTextColor,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
Expand Down Expand Up @@ -366,6 +367,15 @@ export const RuleDetails: React.FunctionComponent<RuleDetailsProps> = ({
<EuiFlexItem grow={false}>
<EuiText size="s" data-test-subj="apiKeyOwnerLabel">
<b>{rule.apiKeyOwner}</b>
{rule.apiKeyCreatedByUser ? (
<EuiTextColor color="subdued">
&nbsp;
<FormattedMessage
id="xpack.triggersActionsUI.sections.ruleDetails.userManagedApikey"
defaultMessage="(user-managed)"
/>
</EuiTextColor>
) : null}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down

0 comments on commit eec9043

Please sign in to comment.