Skip to content

Commit

Permalink
[ResponseOps] Run soon API improvements (#180533)
Browse files Browse the repository at this point in the history
## Summary

This PR moves some code around to make the API reflect how the UI works.

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
doakalexi authored Apr 12, 2024
1 parent bb5f6a6 commit 5982f12
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export enum ReadOperations {
GetActionErrorLog = 'getActionErrorLog',
Find = 'find',
GetAuthorizedAlertsIndices = 'getAuthorizedAlertsIndices',
RunSoon = 'runSoon',
GetRuleExecutionKPI = 'getRuleExecutionKPI',
}

Expand All @@ -55,6 +54,7 @@ export enum WriteOperations {
BulkEnable = 'bulkEnable',
BulkDisable = 'bulkDisable',
Unsnooze = 'unsnooze',
RunSoon = 'runSoon',
}

export interface EnsureAuthorizedOpts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { i18n } from '@kbn/i18n';
import { ConcreteTaskInstance, TaskStatus } from '@kbn/task-manager-plugin/server';
import { Rule } from '../../types';
import { ReadOperations, AlertingAuthorizationEntity } from '../../authorization';
import { WriteOperations, AlertingAuthorizationEntity } from '../../authorization';
import { ruleAuditEvent, RuleAuditAction } from '../common/audit_events';
import { RulesClientContext } from '../types';
import { RULE_SAVED_OBJECT_TYPE } from '../../saved_objects';
Expand All @@ -22,7 +22,7 @@ export async function runSoon(context: RulesClientContext, { id }: { id: string
await context.authorization.ensureAuthorized({
ruleTypeId: attributes.alertTypeId,
consumer: attributes.consumer,
operation: ReadOperations.RunSoon,
operation: WriteOperations.RunSoon,
entity: AlertingAuthorizationEntity.Rule,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/getActionErrorLog",
"alerting:alert-type/my-feature/rule/find",
"alerting:alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:alert-type/my-feature/rule/runSoon",
]
`);
});
Expand Down Expand Up @@ -178,7 +177,6 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/getActionErrorLog",
"alerting:alert-type/my-feature/rule/find",
"alerting:alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:alert-type/my-feature/alert/get",
"alerting:alert-type/my-feature/alert/find",
"alerting:alert-type/my-feature/alert/getAuthorizedAlertsIndices",
Expand Down Expand Up @@ -226,7 +224,6 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/getActionErrorLog",
"alerting:alert-type/my-feature/rule/find",
"alerting:alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:alert-type/my-feature/rule/create",
"alerting:alert-type/my-feature/rule/delete",
"alerting:alert-type/my-feature/rule/update",
Expand All @@ -243,6 +240,7 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/bulkEnable",
"alerting:alert-type/my-feature/rule/bulkDisable",
"alerting:alert-type/my-feature/rule/unsnooze",
"alerting:alert-type/my-feature/rule/runSoon",
]
`);
});
Expand Down Expand Up @@ -331,7 +329,6 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/getActionErrorLog",
"alerting:alert-type/my-feature/rule/find",
"alerting:alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:alert-type/my-feature/rule/create",
"alerting:alert-type/my-feature/rule/delete",
"alerting:alert-type/my-feature/rule/update",
Expand All @@ -348,6 +345,7 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/bulkEnable",
"alerting:alert-type/my-feature/rule/bulkDisable",
"alerting:alert-type/my-feature/rule/unsnooze",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:alert-type/my-feature/alert/get",
"alerting:alert-type/my-feature/alert/find",
"alerting:alert-type/my-feature/alert/getAuthorizedAlertsIndices",
Expand Down Expand Up @@ -396,7 +394,6 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/getActionErrorLog",
"alerting:alert-type/my-feature/rule/find",
"alerting:alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:alert-type/my-feature/rule/create",
"alerting:alert-type/my-feature/rule/delete",
"alerting:alert-type/my-feature/rule/update",
Expand All @@ -413,14 +410,14 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/bulkEnable",
"alerting:alert-type/my-feature/rule/bulkDisable",
"alerting:alert-type/my-feature/rule/unsnooze",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:readonly-alert-type/my-feature/rule/get",
"alerting:readonly-alert-type/my-feature/rule/getRuleState",
"alerting:readonly-alert-type/my-feature/rule/getAlertSummary",
"alerting:readonly-alert-type/my-feature/rule/getExecutionLog",
"alerting:readonly-alert-type/my-feature/rule/getActionErrorLog",
"alerting:readonly-alert-type/my-feature/rule/find",
"alerting:readonly-alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:readonly-alert-type/my-feature/rule/runSoon",
]
`);
});
Expand Down Expand Up @@ -513,7 +510,6 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/getActionErrorLog",
"alerting:alert-type/my-feature/rule/find",
"alerting:alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:alert-type/my-feature/rule/create",
"alerting:alert-type/my-feature/rule/delete",
"alerting:alert-type/my-feature/rule/update",
Expand All @@ -530,14 +526,14 @@ describe(`feature_privilege_builder`, () => {
"alerting:alert-type/my-feature/rule/bulkEnable",
"alerting:alert-type/my-feature/rule/bulkDisable",
"alerting:alert-type/my-feature/rule/unsnooze",
"alerting:alert-type/my-feature/rule/runSoon",
"alerting:readonly-alert-type/my-feature/rule/get",
"alerting:readonly-alert-type/my-feature/rule/getRuleState",
"alerting:readonly-alert-type/my-feature/rule/getAlertSummary",
"alerting:readonly-alert-type/my-feature/rule/getExecutionLog",
"alerting:readonly-alert-type/my-feature/rule/getActionErrorLog",
"alerting:readonly-alert-type/my-feature/rule/find",
"alerting:readonly-alert-type/my-feature/rule/getRuleExecutionKPI",
"alerting:readonly-alert-type/my-feature/rule/runSoon",
"alerting:another-alert-type/my-feature/alert/get",
"alerting:another-alert-type/my-feature/alert/find",
"alerting:another-alert-type/my-feature/alert/getAuthorizedAlertsIndices",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const readOperations: Record<AlertingEntity, string[]> = {
'getActionErrorLog',
'find',
'getRuleExecutionKPI',
'runSoon',
],
alert: ['get', 'find', 'getAuthorizedAlertsIndices', 'getAlertSummary'],
};
Expand All @@ -48,6 +47,7 @@ const writeOperations: Record<AlertingEntity, string[]> = {
'bulkEnable',
'bulkDisable',
'unsnooze',
'runSoon',
],
alert: ['update'],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
case 'global_read at space1':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getUnauthorizedErrorMessage('runSoon', 'test.noop', 'alertsFixture'),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all_alerts_none_actions at space1':
case 'superuser at space1':
case 'space_1_all at space1':
Expand Down

0 comments on commit 5982f12

Please sign in to comment.