Skip to content

Commit

Permalink
Addressing pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed May 3, 2021
1 parent fbf5784 commit 9fae3d9
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 61 deletions.
9 changes: 4 additions & 5 deletions x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { CommentResponseRt } from './comment';
import { CasesStatusResponseRt, CaseStatusRt } from './status';
import { CaseConnectorRt, ESCaseConnector } from '../connectors';
import { SubCaseResponseRt } from './sub_case';
import { OWNER_FIELD } from './constants';

export enum CaseType {
collection = 'collection',
Expand All @@ -39,7 +38,7 @@ const CaseBasicRt = rt.type({
[caseTypeField]: CaseTypeRt,
connector: CaseConnectorRt,
settings: SettingsRt,
[OWNER_FIELD]: rt.string,
owner: rt.string,
});

const CaseExternalServiceBasicRt = rt.type({
Expand Down Expand Up @@ -80,7 +79,7 @@ const CasePostRequestNoTypeRt = rt.type({
title: rt.string,
connector: CaseConnectorRt,
settings: SettingsRt,
[OWNER_FIELD]: rt.string,
owner: rt.string,
});

/**
Expand Down Expand Up @@ -115,7 +114,7 @@ export const CasesFindRequestRt = rt.partial({
searchFields: rt.union([rt.array(rt.string), rt.string]),
sortField: rt.string,
sortOrder: rt.union([rt.literal('desc'), rt.literal('asc')]),
[OWNER_FIELD]: rt.union([rt.array(rt.string), rt.string]),
owner: rt.union([rt.array(rt.string), rt.string]),
});

export const CaseResponseRt = rt.intersection([
Expand Down Expand Up @@ -177,7 +176,7 @@ export const ExternalServiceResponseRt = rt.intersection([
]);

export const AllTagsFindRequestRt = rt.partial({
[OWNER_FIELD]: rt.union([rt.array(rt.string), rt.string]),
owner: rt.union([rt.array(rt.string), rt.string]),
});

export const AllReportersFindRequestRt = AllTagsFindRequestRt;
Expand Down
7 changes: 3 additions & 4 deletions x-pack/plugins/cases/common/api/cases/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import * as rt from 'io-ts';
import { OWNER_FIELD } from './constants';
import { SavedObjectFindOptionsRt } from '../saved_object';

import { UserRT } from '../user';
Expand All @@ -29,7 +28,7 @@ export const CommentAttributesBasicRt = rt.type({
]),
created_at: rt.string,
created_by: UserRT,
[OWNER_FIELD]: rt.string,
owner: rt.string,
pushed_at: rt.union([rt.string, rt.null]),
pushed_by: rt.union([UserRT, rt.null]),
updated_at: rt.union([rt.string, rt.null]),
Expand All @@ -45,7 +44,7 @@ export enum CommentType {
export const ContextTypeUserRt = rt.type({
comment: rt.string,
type: rt.literal(CommentType.user),
[OWNER_FIELD]: rt.string,
owner: rt.string,
});

/**
Expand All @@ -61,7 +60,7 @@ export const AlertCommentRequestRt = rt.type({
id: rt.union([rt.string, rt.null]),
name: rt.union([rt.string, rt.null]),
}),
[OWNER_FIELD]: rt.string,
owner: rt.string,
});

const AttributesTypeUserRt = rt.intersection([ContextTypeUserRt, CommentAttributesBasicRt]);
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/cases/common/api/cases/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ClosureTypeRT = rt.union([rt.literal('close-by-user'), rt.literal('close-b
const CasesConfigureBasicRt = rt.type({
connector: CaseConnectorRt,
closure_type: ClosureTypeRT,
[OWNER_FIELD]: rt.string,
owner: rt.string,
});

const CasesConfigureBasicWithoutOwnerRt = rt.type(
Expand Down Expand Up @@ -48,12 +48,12 @@ export const CaseConfigureResponseRt = rt.intersection([
id: rt.string,
version: rt.string,
error: rt.union([rt.string, rt.null]),
[OWNER_FIELD]: rt.string,
owner: rt.string,
}),
]);

export const GetConfigureFindRequestRt = rt.partial({
[OWNER_FIELD]: rt.union([rt.array(rt.string), rt.string]),
owner: rt.union([rt.array(rt.string), rt.string]),
});

export const CaseConfigureRequestParamsRt = rt.type({
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/cases/common/api/cases/sub_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as rt from 'io-ts';
import { NumberFromString } from '../saved_object';
import { UserRT } from '../user';
import { CommentResponseRt } from './comment';
import { OWNER_FIELD } from './constants';
import { CasesStatusResponseRt } from './status';
import { CaseStatusRt } from './status';

Expand All @@ -27,7 +26,7 @@ export const SubCaseAttributesRt = rt.intersection([
created_by: rt.union([UserRT, rt.null]),
updated_at: rt.union([rt.string, rt.null]),
updated_by: rt.union([UserRT, rt.null]),
[OWNER_FIELD]: rt.string,
owner: rt.string,
}),
]);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/api/cases/user_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CaseUserActionBasicRT = rt.type({
action_by: UserRT,
new_value: rt.union([rt.string, rt.null]),
old_value: rt.union([rt.string, rt.null]),
[OWNER_FIELD]: rt.string,
owner: rt.string,
});

const CaseUserActionResponseRT = rt.intersection([
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/cases/common/api/connectors/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import * as rt from 'io-ts';
import { OWNER_FIELD } from '../cases/constants';

const ActionTypeRT = rt.union([
rt.literal('append'),
Expand All @@ -32,7 +31,7 @@ export const ConnectorMappingsAttributesRT = rt.type({

export const ConnectorMappingsRt = rt.type({
mappings: rt.array(ConnectorMappingsAttributesRT),
[OWNER_FIELD]: rt.string,
owner: rt.string,
});

export type ConnectorMappingsAttributes = rt.TypeOf<typeof ConnectorMappingsAttributesRT>;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/authorization/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getOwnersFilter = (savedObjectType: string, owners: string[]): Kuer
return nodeBuilder.or(
owners.reduce<KueryNode[]>((query, owner) => {
ensureFieldIsSafeForQuery(OWNER_FIELD, owner);
query.push(nodeBuilder.is(`${savedObjectType}.attributes.owner`, owner));
query.push(nodeBuilder.is(`${savedObjectType}.attributes.${OWNER_FIELD}`, owner));
return query;
}, [])
);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/cases/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const push = async (
// We need to change the logic when we support subcases
if (theCase?.status === CaseStatuses.closed) {
throw Boom.conflict(
`This case ${theCase.title} is closed. You can not pushed if the case is closed.`
`The ${theCase.title} case is closed. Pushing a closed case is not allowed.`
);
}

Expand Down
7 changes: 1 addition & 6 deletions x-pack/plugins/cases/server/client/cases/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,11 @@ function partitionPatchRequest(
conflictedCases: CasePatchRequest[];
casesToAuthorize: Array<SavedObject<ESCaseAttributes>>;
} {
const reqCasesMap = patchReqCases.reduce((acc, req) => {
acc.set(req.id, req);
return acc;
}, new Map<string, CasePatchRequest>());

const nonExistingCases: CasePatchRequest[] = [];
const conflictedCases: CasePatchRequest[] = [];
const casesToAuthorize: Array<SavedObject<ESCaseAttributes>> = [];

for (const reqCase of reqCasesMap.values()) {
for (const reqCase of patchReqCases) {
const foundCase = casesMap.get(reqCase.id);

if (!foundCase || foundCase.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { FtrProviderContext as CommonFtrProviderContext } from '../../../common/ftr_provider_context';
import { Role, User, UserInfo } from './types';
import { users } from './users';
import { superUser, users } from './users';
import { roles } from './roles';
import { spaces } from './spaces';

Expand Down Expand Up @@ -90,3 +90,5 @@ export const deleteSpacesAndUsers = async (getService: CommonFtrProviderContext[
await deleteSpaces(getService);
await deleteUsersAndRoles(getService);
};

export const superUserSpace1Auth = { user: superUser, space: 'space1' };
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
superUser,
} from '../../../../common/lib/authentication/users';

import { superUserSpace1Auth } from '../../../../common/lib/authentication';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertestWithoutAuth = getService('supertestWithoutAuth');
Expand Down Expand Up @@ -238,14 +240,14 @@ export default ({ getService }: FtrProviderContext): void => {
supertest: supertestWithoutAuth,
caseId: caseSec.id,
expectedHttpCode: 200,
auth: { user: superUser, space: 'space1' },
auth: superUserSpace1Auth,
});

await getCase({
supertest: supertestWithoutAuth,
caseId: caseObs.id,
expectedHttpCode: 200,
auth: { user: superUser, space: 'space1' },
auth: superUserSpace1Auth,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
secOnlyRead,
superUser,
} from '../../../../common/lib/authentication/users';
import { superUserSpace1Auth } from '../../../../common/lib/authentication';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
Expand Down Expand Up @@ -1169,7 +1170,7 @@ export default ({ getService }: FtrProviderContext): void => {
expectedHttpCode: 403,
});

const resp = await findCases({ supertest, auth: { user: superUser, space: 'space1' } });
const resp = await findCases({ supertest, auth: superUserSpace1Auth });
expect(resp.cases.length).to.eql(3);
// the update should have failed and none of the title should have been changed
expect(resp.cases[0].title).to.eql(postCaseReq.title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
secOnlyRead,
superUser,
} from '../../../../../common/lib/authentication/users';
import { superUserSpace1Auth } from '../../../../../common/lib/authentication';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
Expand Down Expand Up @@ -93,13 +94,13 @@ export default ({ getService }: FtrProviderContext): void => {
supertestWithoutAuth,
getPostCaseRequest({ owner: 'observabilityFixture' }),
200,
{ user: superUser, space: 'space1' }
superUserSpace1Auth
),
createCase(
supertestWithoutAuth,
getPostCaseRequest({ owner: 'observabilityFixture' }),
200,
{ user: superUser, space: 'space1' }
superUserSpace1Auth
),
]);

Expand All @@ -124,7 +125,7 @@ export default ({ getService }: FtrProviderContext): void => {
},
],
},
auth: { user: superUser, space: 'space1' },
auth: superUserSpace1Auth,
});

for (const scenario of [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
secOnlyRead,
superUser,
} from '../../../../common/lib/authentication/users';
import { superUserSpace1Auth } from '../../../../common/lib/authentication';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
Expand Down Expand Up @@ -277,14 +278,14 @@ export default ({ getService }: FtrProviderContext): void => {
supertestWithoutAuth,
getPostCaseRequest({ owner: 'securitySolutionFixture' }),
200,
{ user: superUser, space: 'space1' }
superUserSpace1Auth
);

const commentResp = await createComment({
supertest: supertestWithoutAuth,
caseId: postedCase.id,
params: postCommentUserReq,
auth: { user: superUser, space: 'space1' },
auth: superUserSpace1Auth,
});

await deleteComment({
Expand All @@ -309,14 +310,14 @@ export default ({ getService }: FtrProviderContext): void => {
supertestWithoutAuth,
getPostCaseRequest({ owner: 'securitySolutionFixture' }),
200,
{ user: superUser, space: 'space1' }
superUserSpace1Auth
);

const commentResp = await createComment({
supertest: supertestWithoutAuth,
caseId: postedCase.id,
params: postCommentUserReq,
auth: { user: superUser, space: 'space1' },
auth: superUserSpace1Auth,
});

await deleteComment({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
globalRead,
obsSecRead,
} from '../../../../common/lib/authentication/users';
import { superUserSpace1Auth } from '../../../../common/lib/authentication';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
Expand Down Expand Up @@ -312,12 +313,12 @@ export default ({ getService }: FtrProviderContext): void => {
supertestWithoutAuth,
getPostCaseRequest({ owner: 'observabilityFixture' }),
200,
{ user: superUser, space: 'space1' }
superUserSpace1Auth
);

await createComment({
supertest: supertestWithoutAuth,
auth: { user: superUser, space: 'space1' },
auth: superUserSpace1Auth,
params: { ...postCommentUserReq, owner: 'observabilityFixture' },
caseId: obsCase.id,
});
Expand All @@ -340,12 +341,12 @@ export default ({ getService }: FtrProviderContext): void => {
supertestWithoutAuth,
getPostCaseRequest({ owner: 'observabilityFixture' }),
200,
{ user: superUser, space: 'space1' }
superUserSpace1Auth
);

await createComment({
supertest: supertestWithoutAuth,
auth: { user: superUser, space: 'space1' },
auth: superUserSpace1Auth,
params: { ...postCommentUserReq, owner: 'observabilityFixture' },
caseId: obsCase.id,
});
Expand Down
Loading

0 comments on commit 9fae3d9

Please sign in to comment.