Skip to content

Commit

Permalink
Fixing up problems from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Mar 25, 2021
1 parent b0a2fb0 commit f55c6bf
Show file tree
Hide file tree
Showing 27 changed files with 54 additions and 159 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/cases/server/client/cases/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ interface CreateCaseArgs {
userActionService: CaseUserActionServiceSetup;
theCase: CasePostRequest;
logger: Logger;
subCasesEnabled: boolean;
}

/**
Expand All @@ -59,7 +58,6 @@ export const create = async ({
user,
theCase,
logger,
subCasesEnabled,
}: CreateCaseArgs): Promise<CaseResponse> => {
// default to an individual case if the type is not defined.
const { type = CaseType.individual, ...nonTypeCaseFields } = theCase;
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/cases/server/client/cases/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface GetParams {
includeComments?: boolean;
includeSubCaseComments?: boolean;
logger: Logger;
subCasesEnabled: boolean;
}

/**
Expand All @@ -33,7 +32,6 @@ export const get = async ({
logger,
includeComments = false,
includeSubCaseComments = false,
subCasesEnabled,
}: GetParams): Promise<CaseResponse> => {
try {
let theCase: SavedObject<ESCaseAttributes>;
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/cases/server/client/cases/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ interface PushParams {
casesClient: CasesClientHandler;
actionsClient: ActionsClient;
logger: Logger;
subCasesEnabled: boolean;
}

export const push = async ({
Expand All @@ -83,7 +82,6 @@ export const push = async ({
caseId,
user,
logger,
subCasesEnabled,
}: PushParams): Promise<CaseResponse> => {
/* Start of push to external service */
let theCase: CaseResponse;
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/cases/server/client/cases/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ interface UpdateArgs {
casesClient: CasesClientHandler;
cases: CasesPatchRequest;
logger: Logger;
subCasesEnabled: boolean;
}

export const update = async ({
Expand All @@ -348,7 +347,6 @@ export const update = async ({
casesClient,
cases,
logger,
subCasesEnabled,
}: UpdateArgs): Promise<CasesResponse> => {
const query = pipe(
excess(CasesPatchRequestRt).decode(cases),
Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/cases/server/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class CasesClientHandler implements CasesClient {
private readonly _userActionService: CaseUserActionServiceSetup;
private readonly _alertsService: AlertServiceContract;
private readonly logger: Logger;
private readonly subCasesEnabled: boolean;

constructor(clientArgs: CasesClientFactoryArguments) {
this._scopedClusterClient = clientArgs.scopedClusterClient;
Expand All @@ -63,7 +62,6 @@ export class CasesClientHandler implements CasesClient {
this._userActionService = clientArgs.userActionService;
this._alertsService = clientArgs.alertsService;
this.logger = clientArgs.logger;
this.subCasesEnabled = clientArgs.subCasesEnabled;
}

public async create(caseInfo: CasePostRequest) {
Expand All @@ -76,7 +74,6 @@ export class CasesClientHandler implements CasesClient {
user: this.user,
theCase: caseInfo,
logger: this.logger,
subCasesEnabled: this.subCasesEnabled,
});
} catch (error) {
throw createCaseError({
Expand All @@ -97,7 +94,6 @@ export class CasesClientHandler implements CasesClient {
cases,
casesClient: this,
logger: this.logger,
subCasesEnabled: this.subCasesEnabled,
});
} catch (error) {
const caseIDVersions = cases.cases.map((caseInfo) => ({
Expand All @@ -123,7 +119,6 @@ export class CasesClientHandler implements CasesClient {
comment,
user: this.user,
logger: this.logger,
subCasesEnabled: this.subCasesEnabled,
});
} catch (error) {
throw createCaseError({
Expand Down Expand Up @@ -190,7 +185,6 @@ export class CasesClientHandler implements CasesClient {
caseService: this._caseService,
savedObjectsClient: this._savedObjectsClient,
logger: this.logger,
subCasesEnabled: this.subCasesEnabled,
});
} catch (error) {
this.logger.error(`Failed to get case using client id: ${args.id}: ${error}`);
Expand Down Expand Up @@ -244,7 +238,6 @@ export class CasesClientHandler implements CasesClient {
casesClient: this,
caseConfigureService: this._caseConfigureService,
logger: this.logger,
subCasesEnabled: this.subCasesEnabled,
});
} catch (error) {
throw createCaseError({
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/cases/server/client/comments/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,11 @@ async function getCombinedCase({
client,
id,
logger,
subCasesEnabled,
}: {
service: CaseServiceSetup;
client: SavedObjectsClientContract;
id: string;
logger: Logger;
subCasesEnabled: boolean;
}): Promise<CommentableCase> {
const [casePromise, subCasePromise] = await Promise.allSettled([
service.getCase({
Expand Down Expand Up @@ -278,7 +276,6 @@ interface AddCommentArgs {
userActionService: CaseUserActionServiceSetup;
user: User;
logger: Logger;
subCasesEnabled: boolean;
}

export const addComment = async ({
Expand All @@ -290,7 +287,6 @@ export const addComment = async ({
comment,
user,
logger,
subCasesEnabled,
}: AddCommentArgs): Promise<CaseResponse> => {
const query = pipe(
CommentRequestRt.decode(comment),
Expand Down Expand Up @@ -324,7 +320,6 @@ export const addComment = async ({
client: savedObjectsClient,
id: caseId,
logger,
subCasesEnabled,
});

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/cases/server/client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('createExternalCasesClient()', () => {
savedObjectsClient,
userActionService,
logger,
subCasesEnabled: true,
});
expect(CasesClientHandler).toHaveBeenCalledTimes(1);
});
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/cases/server/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export const createCasesClientWithMockSavedObjectsClient = async ({
alertsService,
scopedClusterClient: esClient,
logger: log,
subCasesEnabled: true,
});
return {
client: casesClient,
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/cases/server/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export interface CasesClientFactoryArguments {
userActionService: CaseUserActionServiceSetup;
alertsService: AlertServiceContract;
logger: Logger;
subCasesEnabled: boolean;
}

export interface ConfigureFields {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/cases/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { schema, TypeOf } from '@kbn/config-schema';

export const ConfigSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
subCasesEnabled: schema.boolean({ defaultValue: false }),
});

export type ConfigType = TypeOf<typeof ConfigSchema>;
3 changes: 0 additions & 3 deletions x-pack/plugins/cases/server/connectors/case/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ async function executor(
userActionService,
alertsService,
logger,
// sub-cases-enabled: force this to true because we should never be able to call execute if the feature is disabled in the first
// place. The plugin won't register case as a connector if subCasesEnabled is false.
subCasesEnabled: true,
});

if (!supportedSubActions.includes(subAction)) {
Expand Down
8 changes: 2 additions & 6 deletions x-pack/plugins/cases/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ export class CasePlugin {
private connectorMappingsService?: ConnectorMappingsServiceSetup;
private userActionService?: CaseUserActionServiceSetup;
private alertsService?: AlertService;
private config?: ConfigType;

constructor(private readonly initializerContext: PluginInitializerContext) {
this.log = this.initializerContext.logger.get();
}

public async setup(core: CoreSetup, plugins: PluginsSetup) {
this.config = createConfig(this.initializerContext);
const config = createConfig(this.initializerContext);

if (!this.config.enabled) {
if (!config.enabled) {
return;
}

Expand Down Expand Up @@ -109,7 +108,6 @@ export class CasePlugin {
connectorMappingsService: this.connectorMappingsService,
userActionService: this.userActionService,
router,
subCasesEnabled: this.config.subCasesEnabled,
});

if (ENABLE_CASE_CONNECTOR) {
Expand Down Expand Up @@ -144,7 +142,6 @@ export class CasePlugin {
userActionService: this.userActionService!,
alertsService: this.alertsService!,
logger: this.log,
subCasesEnabled: this.config?.subCasesEnabled ?? false,
});
};

Expand Down Expand Up @@ -189,7 +186,6 @@ export class CasePlugin {
alertsService,
user,
logger,
subCasesEnabled: this.config?.subCasesEnabled ?? false,
});
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const createRoute = async (
getUserActions: jest.fn(),
},
logger: log,
subCasesEnabled: true,
});

return router[method].mock.calls[0][1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const createRouteContext = async (client: any, badAuth = false) => {
alertsService,
scopedClusterClient: esClient,
logger: log,
subCasesEnabled: true,
});

return { context, services: { userActionService } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,19 @@ export function initDeleteAllCommentsApi({
router,
userActionService,
logger,
subCasesEnabled,
}: RouteDeps) {
const querySchema = subCasesEnabled
? {
query: schema.maybe(
schema.object({
subCaseId: schema.maybe(schema.string()),
})
),
}
: {};
router.delete(
{
path: CASE_COMMENTS_URL,
validate: {
params: schema.object({
case_id: schema.string(),
}),
...querySchema,
query: schema.maybe(
schema.object({
subCaseId: schema.maybe(schema.string()),
})
),
},
},
async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,7 @@ export function initDeleteCommentApi({
router,
userActionService,
logger,
subCasesEnabled,
}: RouteDeps) {
const querySchema = subCasesEnabled
? {
query: schema.maybe(
schema.object({
subCaseId: schema.maybe(schema.string()),
})
),
}
: {};
router.delete(
{
path: CASE_COMMENT_DETAILS_URL,
Expand All @@ -38,7 +28,11 @@ export function initDeleteCommentApi({
case_id: schema.string(),
comment_id: schema.string(),
}),
...querySchema,
query: schema.maybe(
schema.object({
subCaseId: schema.maybe(schema.string()),
})
),
},
},
async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ const FindQueryParamsRt = rt.partial({
subCaseId: rt.string,
});

export function initFindCaseCommentsApi({
caseService,
router,
logger,
subCasesEnabled,
}: RouteDeps) {
export function initFindCaseCommentsApi({ caseService, router, logger }: RouteDeps) {
router.get(
{
path: `${CASE_COMMENTS_URL}/_find`,
Expand All @@ -49,17 +44,10 @@ export function initFindCaseCommentsApi({
async (context, request, response) => {
try {
const client = context.core.savedObjects.client;
const query = {
...pipe(
// sub-cases-enabled: Don't allow subCaseId to be a valid query parameter
subCasesEnabled
? FindQueryParamsRt.decode(request.query)
: SavedObjectFindOptionsRt.decode(request.query),
fold(throwErrors(Boom.badRequest), identity)
),
// sub-cases-enabled: Avoid type errors because SavedObjectFindOptionsRt does not have 'subCaseId' field defined
...(subCasesEnabled ? {} : { subCaseId: undefined }),
};
const query = pipe(
FindQueryParamsRt.decode(request.query),
fold(throwErrors(Boom.badRequest), identity)
);

if (!ENABLE_CASE_CONNECTOR && query.subCaseId !== undefined) {
throw Boom.badRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ import { flattenCommentSavedObjects, wrapError } from '../../utils';
import { CASE_COMMENTS_URL, ENABLE_CASE_CONNECTOR } from '../../../../../common/constants';
import { defaultSortField } from '../../../../common';

export function initGetAllCommentsApi({ caseService, router, logger, subCasesEnabled }: RouteDeps) {
const querySchema = subCasesEnabled
? {
query: schema.maybe(
schema.object({
includeSubCaseComments: schema.maybe(schema.boolean()),
subCaseId: schema.maybe(schema.string()),
})
),
}
: {};
export function initGetAllCommentsApi({ caseService, router, logger }: RouteDeps) {
router.get(
{
path: CASE_COMMENTS_URL,
validate: {
params: schema.object({
case_id: schema.string(),
}),
...querySchema,
query: schema.maybe(
schema.object({
includeSubCaseComments: schema.maybe(schema.boolean()),
subCaseId: schema.maybe(schema.string()),
})
),
},
},
async (context, request, response) => {
Expand Down
Loading

0 comments on commit f55c6bf

Please sign in to comment.