Skip to content

Commit

Permalink
[8.8] add 'user-managed' label to the rule details page for the api k…
Browse files Browse the repository at this point in the history
…eys created by users (#155699) (#157792)

# Backport

This will backport the following commits from `main` to `8.8`:
- [add 'user-managed' label to the rule details page for the api keys
created by users
(#155699)](#155699)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Ersin
Erdal","email":"92688503+ersin-erdal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-05-15T19:33:48Z","message":"add
'user-managed' label to the rule details page for the api keys created
by users (#155699)\n\nResolves: #154581\r\n\r\nThis PR adds
'user-managed' label next to the API key owner name when\r\nthe API key
is created by the user.\r\n\r\n<img width=\"813\" alt=\"Screenshot
2023-05-06 at 19 02
08\"\r\nsrc=\"https://user-images.githubusercontent.com/92688503/236637767-d0c0ee00-1314-4824-b97a-b7bdf1b7f43b.png\">","sha":"d297a9949fc603a797faebc997ea92bee1001fee","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","ui-copy","v8.8.0","v8.9.0"],"number":155699,"url":"https://github.com/elastic/kibana/pull/155699","mergeCommit":{"message":"add
'user-managed' label to the rule details page for the api keys created
by users (#155699)\n\nResolves: #154581\r\n\r\nThis PR adds
'user-managed' label next to the API key owner name when\r\nthe API key
is created by the user.\r\n\r\n<img width=\"813\" alt=\"Screenshot
2023-05-06 at 19 02
08\"\r\nsrc=\"https://user-images.githubusercontent.com/92688503/236637767-d0c0ee00-1314-4824-b97a-b7bdf1b7f43b.png\">","sha":"d297a9949fc603a797faebc997ea92bee1001fee"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/155699","number":155699,"mergeCommit":{"message":"add
'user-managed' label to the rule details page for the api keys created
by users (#155699)\n\nResolves: #154581\r\n\r\nThis PR adds
'user-managed' label next to the API key owner name when\r\nthe API key
is created by the user.\r\n\r\n<img width=\"813\" alt=\"Screenshot
2023-05-06 at 19 02
08\"\r\nsrc=\"https://user-images.githubusercontent.com/92688503/236637767-d0c0ee00-1314-4824-b97a-b7bdf1b7f43b.png\">","sha":"d297a9949fc603a797faebc997ea92bee1001fee"}}]}]
BACKPORT-->

Co-authored-by: Ersin Erdal <92688503+ersin-erdal@users.noreply.github.com>
  • Loading branch information
kibanamachine and ersin-erdal authored May 15, 2023
1 parent 4c2b4a0 commit 0a574d3
Show file tree
Hide file tree
Showing 3 changed files with 33 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 icon 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 Info'
);
});

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,
EuiIconTip,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
Expand Down Expand Up @@ -366,6 +367,20 @@ export const RuleDetails: React.FunctionComponent<RuleDetailsProps> = ({
<EuiFlexItem grow={false}>
<EuiText size="s" data-test-subj="apiKeyOwnerLabel">
<b>{rule.apiKeyOwner}</b>
{rule.apiKeyCreatedByUser ? (
<>
&nbsp;
<EuiIconTip
position="right"
content={i18n.translate(
'xpack.triggersActionsUI.sections.ruleDetails.userManagedApikey',
{
defaultMessage: 'This rule is associated with an API key.',
}
)}
/>
</>
) : null}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down

0 comments on commit 0a574d3

Please sign in to comment.