diff --git a/x-pack/plugins/cases/server/client/attachments/add.ts b/x-pack/plugins/cases/server/client/attachments/add.ts index a334e4bb6e5e70..b453e1feb5d632 100644 --- a/x-pack/plugins/cases/server/client/attachments/add.ts +++ b/x-pack/plugins/cases/server/client/attachments/add.ts @@ -54,23 +54,26 @@ import { Operations } from '../../authorization'; async function getSubCase({ caseService, - savedObjectsClient, + unsecuredSavedObjectsClient, caseId, createdAt, userActionService, user, }: { caseService: CasesService; - savedObjectsClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; caseId: string; createdAt: string; userActionService: CaseUserActionService; user: User; }): Promise> { - const mostRecentSubCase = await caseService.getMostRecentSubCase(savedObjectsClient, caseId); + const mostRecentSubCase = await caseService.getMostRecentSubCase( + unsecuredSavedObjectsClient, + caseId + ); if (mostRecentSubCase && mostRecentSubCase.attributes.status !== CaseStatuses.closed) { const subCaseAlertsAttachement = await caseService.getAllSubCaseComments({ - soClient: savedObjectsClient, + unsecuredSavedObjectsClient, id: mostRecentSubCase.id, options: { fields: [], @@ -89,13 +92,13 @@ async function getSubCase({ } const newSubCase = await caseService.createSubCase({ - soClient: savedObjectsClient, + unsecuredSavedObjectsClient, createdAt, caseId, createdBy: user, }); await userActionService.bulkCreate({ - soClient: savedObjectsClient, + unsecuredSavedObjectsClient, actions: [ buildCaseUserActionItem({ action: 'create', @@ -152,7 +155,7 @@ const addGeneratedAlerts = async ( }); const caseInfo = await caseService.getCase({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, id: caseId, }); @@ -171,7 +174,7 @@ const addGeneratedAlerts = async ( const subCase = await getSubCase({ caseService, - savedObjectsClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseId, createdAt: createdDate, userActionService, @@ -182,7 +185,7 @@ const addGeneratedAlerts = async ( logger, collection: caseInfo, subCase, - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseService, attachmentService, }); @@ -212,7 +215,7 @@ const addGeneratedAlerts = async ( } await userActionService.bulkCreate({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, actions: [ buildCommentUserActionItem({ action: 'create', @@ -241,25 +244,25 @@ const addGeneratedAlerts = async ( async function getCombinedCase({ caseService, attachmentService, - soClient, + unsecuredSavedObjectsClient, id, logger, }: { caseService: CasesService; attachmentService: AttachmentService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; id: string; logger: Logger; }): Promise { const [casePromise, subCasePromise] = await Promise.allSettled([ caseService.getCase({ - soClient, + unsecuredSavedObjectsClient, id, }), ...(ENABLE_CASE_CONNECTOR ? [ caseService.getSubCase({ - soClient, + unsecuredSavedObjectsClient, id, }), ] @@ -269,7 +272,7 @@ async function getCombinedCase({ if (subCasePromise.status === 'fulfilled') { if (subCasePromise.value.references.length > 0) { const caseValue = await caseService.getCase({ - soClient, + unsecuredSavedObjectsClient, id: subCasePromise.value.references[0].id, }); return new CommentableCase({ @@ -278,7 +281,7 @@ async function getCombinedCase({ subCase: subCasePromise.value, caseService, attachmentService, - soClient, + unsecuredSavedObjectsClient, }); } else { throw Boom.badRequest('Sub case found without reference to collection'); @@ -293,7 +296,7 @@ async function getCombinedCase({ collection: casePromise.value, caseService, attachmentService, - soClient, + unsecuredSavedObjectsClient, }); } } @@ -366,7 +369,7 @@ export const addComment = async ( const combinedCase = await getCombinedCase({ caseService, attachmentService, - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, id: caseId, logger, }); @@ -398,7 +401,7 @@ export const addComment = async ( } await userActionService.bulkCreate({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, actions: [ buildCommentUserActionItem({ action: 'create', diff --git a/x-pack/plugins/cases/server/client/attachments/delete.ts b/x-pack/plugins/cases/server/client/attachments/delete.ts index 359c7a0672275f..d9a2b00ec50ae7 100644 --- a/x-pack/plugins/cases/server/client/attachments/delete.ts +++ b/x-pack/plugins/cases/server/client/attachments/delete.ts @@ -59,7 +59,7 @@ export async function deleteAll( ): Promise { const { user, - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseService, attachmentService, userActionService, @@ -73,7 +73,7 @@ export async function deleteAll( const id = subCaseID ?? caseID; const comments = await caseService.getCommentsByAssociation({ - soClient, + unsecuredSavedObjectsClient, id, associationType: subCaseID ? AssociationType.subCase : AssociationType.case, }); @@ -93,7 +93,7 @@ export async function deleteAll( await Promise.all( comments.saved_objects.map((comment) => attachmentService.delete({ - soClient, + unsecuredSavedObjectsClient, attachmentId: comment.id, }) ) @@ -102,7 +102,7 @@ export async function deleteAll( const deleteDate = new Date().toISOString(); await userActionService.bulkCreate({ - soClient, + unsecuredSavedObjectsClient, actions: comments.saved_objects.map((comment) => buildCommentUserActionItem({ action: 'delete', @@ -136,7 +136,7 @@ export async function deleteComment( ) { const { user, - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, attachmentService, userActionService, logger, @@ -150,7 +150,7 @@ export async function deleteComment( const deleteDate = new Date().toISOString(); const myComment = await attachmentService.get({ - soClient, + unsecuredSavedObjectsClient, attachmentId: attachmentID, }); @@ -175,12 +175,12 @@ export async function deleteComment( } await attachmentService.delete({ - soClient, + unsecuredSavedObjectsClient, attachmentId: attachmentID, }); await userActionService.bulkCreate({ - soClient, + unsecuredSavedObjectsClient, actions: [ buildCommentUserActionItem({ action: 'delete', diff --git a/x-pack/plugins/cases/server/client/attachments/get.ts b/x-pack/plugins/cases/server/client/attachments/get.ts index 6bd0383c508da0..9d85a90324a6c4 100644 --- a/x-pack/plugins/cases/server/client/attachments/get.ts +++ b/x-pack/plugins/cases/server/client/attachments/get.ts @@ -91,7 +91,7 @@ export async function find( clientArgs: CasesClientArgs ): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseService, logger, authorization, @@ -124,7 +124,7 @@ export async function find( const args = queryParams ? { caseService, - soClient, + unsecuredSavedObjectsClient, id, options: { // We need this because the default behavior of getAllCaseComments is to return all the comments @@ -141,7 +141,7 @@ export async function find( } : { caseService, - soClient, + unsecuredSavedObjectsClient, id, options: { page: defaultPage, @@ -184,7 +184,7 @@ export async function get( ): Promise { const { attachmentService, - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, logger, authorization, auditLogger, @@ -192,7 +192,7 @@ export async function get( try { const comment = await attachmentService.get({ - soClient, + unsecuredSavedObjectsClient, attachmentId: attachmentID, }); @@ -225,7 +225,7 @@ export async function getAll( clientArgs: CasesClientArgs ): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseService, logger, authorization, @@ -256,7 +256,7 @@ export async function getAll( if (subCaseID) { comments = await caseService.getAllSubCaseComments({ - soClient, + unsecuredSavedObjectsClient, id: subCaseID, options: { filter, @@ -265,7 +265,7 @@ export async function getAll( }); } else { comments = await caseService.getAllCaseComments({ - soClient, + unsecuredSavedObjectsClient, id: caseID, includeSubCaseComments, options: { diff --git a/x-pack/plugins/cases/server/client/attachments/update.ts b/x-pack/plugins/cases/server/client/attachments/update.ts index 5f07aa25fb3849..3310f9e8f6aa6d 100644 --- a/x-pack/plugins/cases/server/client/attachments/update.ts +++ b/x-pack/plugins/cases/server/client/attachments/update.ts @@ -40,7 +40,7 @@ export interface UpdateArgs { interface CombinedCaseParams { attachmentService: AttachmentService; caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; caseID: string; logger: Logger; subCaseId?: string; @@ -49,7 +49,7 @@ interface CombinedCaseParams { async function getCommentableCase({ attachmentService, caseService, - soClient, + unsecuredSavedObjectsClient, caseID, subCaseId, logger, @@ -57,11 +57,11 @@ async function getCommentableCase({ if (subCaseId) { const [caseInfo, subCase] = await Promise.all([ caseService.getCase({ - soClient, + unsecuredSavedObjectsClient, id: caseID, }), caseService.getSubCase({ - soClient, + unsecuredSavedObjectsClient, id: subCaseId, }), ]); @@ -70,19 +70,19 @@ async function getCommentableCase({ caseService, collection: caseInfo, subCase, - soClient, + unsecuredSavedObjectsClient, logger, }); } else { const caseInfo = await caseService.getCase({ - soClient, + unsecuredSavedObjectsClient, id: caseID, }); return new CommentableCase({ attachmentService, caseService, collection: caseInfo, - soClient, + unsecuredSavedObjectsClient, logger, }); } @@ -100,7 +100,7 @@ export async function update( const { attachmentService, caseService, - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, logger, user, userActionService, @@ -122,14 +122,14 @@ export async function update( const commentableCase = await getCommentableCase({ attachmentService, caseService, - soClient, + unsecuredSavedObjectsClient, caseID, subCaseId: subCaseID, logger, }); const myComment = await attachmentService.get({ - soClient, + unsecuredSavedObjectsClient, attachmentId: queryCommentId, }); @@ -179,7 +179,7 @@ export async function update( }); await userActionService.bulkCreate({ - soClient, + unsecuredSavedObjectsClient, actions: [ buildCommentUserActionItem({ action: 'update', diff --git a/x-pack/plugins/cases/server/client/cases/create.ts b/x-pack/plugins/cases/server/client/cases/create.ts index b0b1a38c0cd636..e1edcfdda0423e 100644 --- a/x-pack/plugins/cases/server/client/cases/create.ts +++ b/x-pack/plugins/cases/server/client/cases/create.ts @@ -88,12 +88,12 @@ export const create = async ( const { username, full_name, email } = user; const createdDate = new Date().toISOString(); const myCaseConfigure = await caseConfigureService.find({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, }); const caseConfigureConnector = getConnectorFromConfiguration(myCaseConfigure); const newCase = await caseService.postNewCase({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, attributes: transformNewCase({ createdDate, newCase: query, @@ -106,7 +106,7 @@ export const create = async ( }); await userActionService.bulkCreate({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, actions: [ buildCaseUserActionItem({ action: 'create', diff --git a/x-pack/plugins/cases/server/client/cases/delete.ts b/x-pack/plugins/cases/server/client/cases/delete.ts index 597b8ad0fca00a..8ad48bde7f9711 100644 --- a/x-pack/plugins/cases/server/client/cases/delete.ts +++ b/x-pack/plugins/cases/server/client/cases/delete.ts @@ -19,19 +19,22 @@ import { OWNER_FIELD } from '../../../common/api'; async function deleteSubCases({ attachmentService, caseService, - soClient, + unsecuredSavedObjectsClient, caseIds, }: { attachmentService: AttachmentService; caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; caseIds: string[]; }) { - const subCasesForCaseIds = await caseService.findSubCasesByCaseId({ soClient, ids: caseIds }); + const subCasesForCaseIds = await caseService.findSubCasesByCaseId({ + unsecuredSavedObjectsClient, + ids: caseIds, + }); const subCaseIDs = subCasesForCaseIds.saved_objects.map((subCase) => subCase.id); const commentsForSubCases = await caseService.getAllSubCaseComments({ - soClient, + unsecuredSavedObjectsClient, id: subCaseIDs, }); @@ -39,13 +42,13 @@ async function deleteSubCases({ // per case ID await Promise.all( commentsForSubCases.saved_objects.map((commentSO) => - attachmentService.delete({ soClient, attachmentId: commentSO.id }) + attachmentService.delete({ unsecuredSavedObjectsClient, attachmentId: commentSO.id }) ) ); await Promise.all( subCasesForCaseIds.saved_objects.map((subCaseSO) => - caseService.deleteSubCase(soClient, subCaseSO.id) + caseService.deleteSubCase(unsecuredSavedObjectsClient, subCaseSO.id) ) ); } @@ -57,7 +60,7 @@ async function deleteSubCases({ */ export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseService, attachmentService, user, @@ -67,7 +70,7 @@ export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): P auditLogger, } = clientArgs; try { - const cases = await caseService.getCases({ soClient, caseIds: ids }); + const cases = await caseService.getCases({ unsecuredSavedObjectsClient, caseIds: ids }); const soIds = new Set(); const owners = new Set(); @@ -96,7 +99,7 @@ export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): P await Promise.all( ids.map((id) => caseService.deleteCase({ - soClient, + unsecuredSavedObjectsClient, id, }) ) @@ -105,7 +108,7 @@ export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): P const comments = await Promise.all( ids.map((id) => caseService.getAllCaseComments({ - soClient, + unsecuredSavedObjectsClient, id, }) ) @@ -117,7 +120,7 @@ export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): P Promise.all( c.saved_objects.map(({ id }) => attachmentService.delete({ - soClient, + unsecuredSavedObjectsClient, attachmentId: id, }) ) @@ -130,7 +133,7 @@ export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): P await deleteSubCases({ attachmentService, caseService, - soClient, + unsecuredSavedObjectsClient, caseIds: ids, }); } @@ -138,7 +141,7 @@ export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): P const deleteDate = new Date().toISOString(); await userActionService.bulkCreate({ - soClient, + unsecuredSavedObjectsClient, actions: cases.saved_objects.map((caseInfo) => buildCaseUserActionItem({ action: 'delete', diff --git a/x-pack/plugins/cases/server/client/cases/find.ts b/x-pack/plugins/cases/server/client/cases/find.ts index 8c007d1a1a9111..633261100ddeaa 100644 --- a/x-pack/plugins/cases/server/client/cases/find.ts +++ b/x-pack/plugins/cases/server/client/cases/find.ts @@ -71,7 +71,7 @@ export const find = async ( const caseQueries = constructQueryOptions({ ...queryArgs, authorizationFilter }); const cases = await caseService.findCasesGroupedByID({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseOptions: { ...queryParams, ...caseQueries.case, @@ -92,7 +92,7 @@ export const find = async ( ...caseStatuses.map((status) => { const statusQuery = constructQueryOptions({ ...queryArgs, status, authorizationFilter }); return caseService.findCaseStatusStats({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseOptions: statusQuery.case, subCaseOptions: statusQuery.subCase, ensureSavedObjectsAreAuthorized, diff --git a/x-pack/plugins/cases/server/client/cases/get.ts b/x-pack/plugins/cases/server/client/cases/get.ts index 0dadc128b3ceb4..cf6d12ceae0a0c 100644 --- a/x-pack/plugins/cases/server/client/cases/get.ts +++ b/x-pack/plugins/cases/server/client/cases/get.ts @@ -62,7 +62,7 @@ export const getCaseIDsByAlertID = async ( clientArgs: CasesClientArgs ): Promise => { const { - unsecuredSavedObjectsClient: savedObjectsClient, + unsecuredSavedObjectsClient, caseService, logger, authorization, @@ -92,7 +92,7 @@ export const getCaseIDsByAlertID = async ( ); const commentsWithAlert = await caseService.getCaseIdsByAlertId({ - soClient: savedObjectsClient, + unsecuredSavedObjectsClient, alertId: alertID, filter, }); @@ -166,17 +166,20 @@ export const get = async ( if (ENABLE_CASE_CONNECTOR) { const [caseInfo, subCasesForCaseId] = await Promise.all([ caseService.getCase({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, id, }), - caseService.findSubCasesByCaseId({ soClient: unsecuredSavedObjectsClient, ids: [id] }), + caseService.findSubCasesByCaseId({ + unsecuredSavedObjectsClient, + ids: [id], + }), ]); theCase = caseInfo; subCaseIds = subCasesForCaseId.saved_objects.map((so) => so.id); } else { theCase = await caseService.getCase({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, id, }); } @@ -199,7 +202,7 @@ export const get = async ( } const theComments = await caseService.getAllCaseComments({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, id, options: { sortField: 'created_at', @@ -231,7 +234,7 @@ export async function getTags( clientArgs: CasesClientArgs ): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseService, logger, authorization: auth, @@ -257,7 +260,7 @@ export async function getTags( const filter = combineAuthorizedAndOwnerFilter(queryParams.owner, authorizationFilter); const cases = await caseService.getTags({ - soClient, + unsecuredSavedObjectsClient, filter, }); @@ -293,7 +296,7 @@ export async function getReporters( clientArgs: CasesClientArgs ): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseService, logger, authorization: auth, @@ -319,7 +322,7 @@ export async function getReporters( const filter = combineAuthorizedAndOwnerFilter(queryParams.owner, authorizationFilter); const cases = await caseService.getReporters({ - soClient, + unsecuredSavedObjectsClient, filter, }); diff --git a/x-pack/plugins/cases/server/client/cases/push.ts b/x-pack/plugins/cases/server/client/cases/push.ts index af395e9d8768a9..74d3fb1373fd75 100644 --- a/x-pack/plugins/cases/server/client/cases/push.ts +++ b/x-pack/plugins/cases/server/client/cases/push.ts @@ -151,12 +151,12 @@ export const push = async ( /* Start of update case with push information */ const [myCase, myCaseConfigure, comments] = await Promise.all([ caseService.getCase({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, id: caseId, }), - caseConfigureService.find({ soClient: unsecuredSavedObjectsClient }), + caseConfigureService.find({ unsecuredSavedObjectsClient }), caseService.getAllCaseComments({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, id: caseId, options: { fields: [], @@ -186,7 +186,7 @@ export const push = async ( const [updatedCase, updatedComments] = await Promise.all([ caseService.patchCase({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseId, updatedAttributes: { ...(shouldMarkAsClosed @@ -204,7 +204,7 @@ export const push = async ( }), attachmentService.bulkUpdate({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, comments: comments.saved_objects .filter((comment) => comment.attributes.pushed_at == null) .map((comment) => ({ @@ -218,7 +218,7 @@ export const push = async ( }), userActionService.bulkCreate({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, actions: [ ...(shouldMarkAsClosed ? [ diff --git a/x-pack/plugins/cases/server/client/cases/update.ts b/x-pack/plugins/cases/server/client/cases/update.ts index 1cda4863ffe410..1dabca40146f8d 100644 --- a/x-pack/plugins/cases/server/client/cases/update.ts +++ b/x-pack/plugins/cases/server/client/cases/update.ts @@ -134,15 +134,15 @@ function throwIfUpdateOwner(requests: ESCasePatchRequest[]) { async function throwIfInvalidUpdateOfTypeWithAlerts({ requests, caseService, - soClient, + unsecuredSavedObjectsClient, }: { requests: ESCasePatchRequest[]; caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; }) { const getAlertsForID = async (caseToUpdate: ESCasePatchRequest) => { const alerts = await caseService.getAllCaseComments({ - soClient, + unsecuredSavedObjectsClient, id: caseToUpdate.id, options: { fields: [], @@ -196,17 +196,17 @@ function getID( async function getAlertComments({ casesToSync, caseService, - soClient, + unsecuredSavedObjectsClient, }: { casesToSync: ESCasePatchRequest[]; caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; }): Promise> { const idsOfCasesToSync = casesToSync.map((casePatchReq) => casePatchReq.id); // getAllCaseComments will by default get all the comments, unless page or perPage fields are set return caseService.getAllCaseComments({ - soClient, + unsecuredSavedObjectsClient, id: idsOfCasesToSync, includeSubCaseComments: true, options: { @@ -225,11 +225,11 @@ async function getAlertComments({ async function getSubCasesToStatus({ totalAlerts, caseService, - soClient, + unsecuredSavedObjectsClient, }: { totalAlerts: SavedObjectsFindResponse; caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; }): Promise> { const subCasesToRetrieve = totalAlerts.saved_objects.reduce((acc, alertComment) => { if ( @@ -246,7 +246,7 @@ async function getSubCasesToStatus({ const subCases = await caseService.getSubCases({ ids: Array.from(subCasesToRetrieve.values()), - soClient, + unsecuredSavedObjectsClient, }); return subCases.saved_objects.reduce((acc, subCase) => { @@ -292,14 +292,14 @@ async function updateAlerts({ casesWithStatusChangedAndSynced, casesMap, caseService, - soClient, + unsecuredSavedObjectsClient, casesClientInternal, }: { casesWithSyncSettingChangedToOn: ESCasePatchRequest[]; casesWithStatusChangedAndSynced: ESCasePatchRequest[]; casesMap: Map>; caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; casesClientInternal: CasesClientInternal; }) { /** @@ -324,11 +324,15 @@ async function updateAlerts({ const totalAlerts = await getAlertComments({ casesToSync, caseService, - soClient, + unsecuredSavedObjectsClient, }); // get a map of sub case id to the sub case status - const subCasesToStatus = await getSubCasesToStatus({ totalAlerts, soClient, caseService }); + const subCasesToStatus = await getSubCasesToStatus({ + totalAlerts, + unsecuredSavedObjectsClient, + caseService, + }); // create an array of requests that indicate the id, index, and status to update an alert const alertsToUpdate = totalAlerts.saved_objects.reduce( @@ -411,7 +415,7 @@ export const update = async ( try { const myCases = await caseService.getCases({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseIds: query.cases.map((q) => q.id), }); @@ -481,14 +485,14 @@ export const update = async ( await throwIfInvalidUpdateOfTypeWithAlerts({ requests: updateFilterCases, caseService, - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, }); // eslint-disable-next-line @typescript-eslint/naming-convention const { username, full_name, email } = user; const updatedDt = new Date().toISOString(); const updatedCases = await caseService.patchCases({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, cases: updateFilterCases.map((thisCase) => { // intentionally removing owner from the case so that we don't accidentally allow it to be updated const { id: caseId, version, owner, ...updateCaseAttributes } = thisCase; @@ -550,7 +554,7 @@ export const update = async ( casesWithStatusChangedAndSynced, casesWithSyncSettingChangedToOn, caseService, - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, casesClientInternal, casesMap, }); @@ -573,7 +577,7 @@ export const update = async ( }); await userActionService.bulkCreate({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, actions: buildCaseUserActions({ originalCases: myCases.saved_objects, updatedCases: updatedCases.saved_objects, diff --git a/x-pack/plugins/cases/server/client/configure/client.ts b/x-pack/plugins/cases/server/client/configure/client.ts index 65e89f9d819b21..e0bf8c7d82308c 100644 --- a/x-pack/plugins/cases/server/client/configure/client.ts +++ b/x-pack/plugins/cases/server/client/configure/client.ts @@ -149,7 +149,7 @@ async function get( casesClientInternal: CasesClientInternal ): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseConfigureService, logger, authorization, @@ -179,7 +179,7 @@ async function get( let error: string | null = null; const myCaseConfigure = await caseConfigureService.find({ - soClient, + unsecuredSavedObjectsClient, options: { filter }, }); @@ -264,7 +264,7 @@ async function update( const { caseConfigureService, logger, - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, user, authorization, auditLogger, @@ -291,7 +291,7 @@ async function update( ); const configuration = await caseConfigureService.get({ - soClient, + unsecuredSavedObjectsClient, configurationId, }); @@ -345,7 +345,7 @@ async function update( } const patch = await caseConfigureService.patch({ - soClient, + unsecuredSavedObjectsClient, configurationId: configuration.id, updatedAttributes: { ...queryWithoutVersionAndConnector, @@ -381,7 +381,7 @@ async function create( casesClientInternal: CasesClientInternal ): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseConfigureService, logger, user, @@ -413,7 +413,7 @@ async function create( ); const myCaseConfigure = await caseConfigureService.find({ - soClient, + unsecuredSavedObjectsClient, options: { filter }, }); @@ -429,7 +429,7 @@ async function create( if (myCaseConfigure.saved_objects.length > 0) { await Promise.all( myCaseConfigure.saved_objects.map((cc) => - caseConfigureService.delete({ soClient, configurationId: cc.id }) + caseConfigureService.delete({ unsecuredSavedObjectsClient, configurationId: cc.id }) ) ); } @@ -460,7 +460,7 @@ async function create( } const post = await caseConfigureService.post({ - soClient, + unsecuredSavedObjectsClient, attributes: { ...configuration, connector: transformCaseConnectorToEsConnector(configuration.connector), diff --git a/x-pack/plugins/cases/server/client/configure/create_mappings.ts b/x-pack/plugins/cases/server/client/configure/create_mappings.ts index bdd4b31377ee06..b01f10d7a9e43b 100644 --- a/x-pack/plugins/cases/server/client/configure/create_mappings.ts +++ b/x-pack/plugins/cases/server/client/configure/create_mappings.ts @@ -29,7 +29,7 @@ export const createMappings = async ( }); const theMapping = await connectorMappingsService.post({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, attributes: { mappings: res.defaultMappings, owner, diff --git a/x-pack/plugins/cases/server/client/configure/get_mappings.ts b/x-pack/plugins/cases/server/client/configure/get_mappings.ts index f00a62c8cd039a..3489c06b1da5ad 100644 --- a/x-pack/plugins/cases/server/client/configure/get_mappings.ts +++ b/x-pack/plugins/cases/server/client/configure/get_mappings.ts @@ -24,7 +24,7 @@ export const getMappings = async ( } const myConnectorMappings = await connectorMappingsService.find({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, options: { hasReference: { type: ACTION_SAVED_OBJECT_TYPE, diff --git a/x-pack/plugins/cases/server/client/configure/update_mappings.ts b/x-pack/plugins/cases/server/client/configure/update_mappings.ts index ddac074c432719..7eccf4cbbe5829 100644 --- a/x-pack/plugins/cases/server/client/configure/update_mappings.ts +++ b/x-pack/plugins/cases/server/client/configure/update_mappings.ts @@ -29,7 +29,7 @@ export const updateMappings = async ( }); const theMapping = await connectorMappingsService.update({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, mappingId, attributes: { mappings: res.defaultMappings, diff --git a/x-pack/plugins/cases/server/client/stats/client.ts b/x-pack/plugins/cases/server/client/stats/client.ts index 4cd8823883c4bf..9816bfe1fd7cff 100644 --- a/x-pack/plugins/cases/server/client/stats/client.ts +++ b/x-pack/plugins/cases/server/client/stats/client.ts @@ -51,7 +51,7 @@ async function getStatusTotalsByType( clientArgs: CasesClientArgs ): Promise { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, caseService, logger, authorization, @@ -82,7 +82,7 @@ async function getStatusTotalsByType( authorizationFilter, }); return caseService.findCaseStatusStats({ - soClient, + unsecuredSavedObjectsClient, caseOptions: statusQuery.case, subCaseOptions: statusQuery.subCase, ensureSavedObjectsAreAuthorized, diff --git a/x-pack/plugins/cases/server/client/sub_cases/client.ts b/x-pack/plugins/cases/server/client/sub_cases/client.ts index 4552d4042012e4..b35d58ce060108 100644 --- a/x-pack/plugins/cases/server/client/sub_cases/client.ts +++ b/x-pack/plugins/cases/server/client/sub_cases/client.ts @@ -93,7 +93,7 @@ export function createSubCasesClient( async function deleteSubCase(ids: string[], clientArgs: CasesClientArgs): Promise { try { const { - unsecuredSavedObjectsClient: soClient, + unsecuredSavedObjectsClient, user, userActionService, caseService, @@ -101,8 +101,8 @@ async function deleteSubCase(ids: string[], clientArgs: CasesClientArgs): Promis } = clientArgs; const [comments, subCases] = await Promise.all([ - caseService.getAllSubCaseComments({ soClient, id: ids }), - caseService.getSubCases({ soClient, ids }), + caseService.getAllSubCaseComments({ unsecuredSavedObjectsClient, id: ids }), + caseService.getSubCases({ unsecuredSavedObjectsClient, ids }), ]); const subCaseErrors = subCases.saved_objects.filter((subCase) => subCase.error !== undefined); @@ -123,16 +123,16 @@ async function deleteSubCase(ids: string[], clientArgs: CasesClientArgs): Promis await Promise.all( comments.saved_objects.map((comment) => - attachmentService.delete({ soClient, attachmentId: comment.id }) + attachmentService.delete({ unsecuredSavedObjectsClient, attachmentId: comment.id }) ) ); - await Promise.all(ids.map((id) => caseService.deleteSubCase(soClient, id))); + await Promise.all(ids.map((id) => caseService.deleteSubCase(unsecuredSavedObjectsClient, id))); const deleteDate = new Date().toISOString(); await userActionService.bulkCreate({ - soClient, + unsecuredSavedObjectsClient, actions: subCases.saved_objects.map((subCase) => buildCaseUserActionItem({ action: 'delete', @@ -161,7 +161,7 @@ async function find( clientArgs: CasesClientArgs ): Promise { try { - const { unsecuredSavedObjectsClient: soClient, caseService } = clientArgs; + const { unsecuredSavedObjectsClient, caseService } = clientArgs; const ids = [caseID]; const { subCase: subCaseQueryOptions } = constructQueryOptions({ @@ -170,7 +170,7 @@ async function find( }); const subCases = await caseService.findSubCasesGroupByCase({ - soClient, + unsecuredSavedObjectsClient, ids, options: { sortField: 'created_at', @@ -188,7 +188,7 @@ async function find( sortByField: queryParams.sortField, }); return caseService.findSubCaseStatusStats({ - soClient, + unsecuredSavedObjectsClient, options: statusQueryOptions ?? {}, ids, }); @@ -220,10 +220,10 @@ async function get( clientArgs: CasesClientArgs ): Promise { try { - const { unsecuredSavedObjectsClient: soClient, caseService } = clientArgs; + const { unsecuredSavedObjectsClient, caseService } = clientArgs; const subCase = await caseService.getSubCase({ - soClient, + unsecuredSavedObjectsClient, id, }); @@ -236,7 +236,7 @@ async function get( } const theComments = await caseService.getAllSubCaseComments({ - soClient, + unsecuredSavedObjectsClient, id, options: { sortField: 'created_at', diff --git a/x-pack/plugins/cases/server/client/sub_cases/update.ts b/x-pack/plugins/cases/server/client/sub_cases/update.ts index 9e64a7b8731b16..b49d36d7a27d4b 100644 --- a/x-pack/plugins/cases/server/client/sub_cases/update.ts +++ b/x-pack/plugins/cases/server/client/sub_cases/update.ts @@ -115,19 +115,19 @@ function getParentIDs({ async function getParentCases({ caseService, - soClient, + unsecuredSavedObjectsClient, subCaseIDs, subCasesMap, }: { caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; subCaseIDs: string[]; subCasesMap: Map>; }): Promise>> { const parentIDInfo = getParentIDs({ subCaseIDs, subCasesMap }); const parentCases = await caseService.getCases({ - soClient, + unsecuredSavedObjectsClient, caseIds: parentIDInfo.ids, }); @@ -182,15 +182,15 @@ function getID(comment: SavedObject): string | undefined { async function getAlertComments({ subCasesToSync, caseService, - soClient, + unsecuredSavedObjectsClient, }: { subCasesToSync: SubCasePatchRequest[]; caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; }): Promise> { const ids = subCasesToSync.map((subCase) => subCase.id); return caseService.getAllSubCaseComments({ - soClient, + unsecuredSavedObjectsClient, id: ids, options: { filter: nodeBuilder.or([ @@ -206,13 +206,13 @@ async function getAlertComments({ */ async function updateAlerts({ caseService, - soClient, + unsecuredSavedObjectsClient, casesClientInternal, logger, subCasesToSync, }: { caseService: CasesService; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; casesClientInternal: CasesClientInternal; logger: Logger; subCasesToSync: SubCasePatchRequest[]; @@ -223,7 +223,11 @@ async function updateAlerts({ return acc; }, new Map()); // get all the alerts for all sub cases that need to be synced - const totalAlerts = await getAlertComments({ caseService, soClient, subCasesToSync }); + const totalAlerts = await getAlertComments({ + caseService, + unsecuredSavedObjectsClient, + subCasesToSync, + }); // create a map of the status (open, closed, etc) to alert info that needs to be updated const alertsToUpdate = totalAlerts.saved_objects.reduce( (acc: UpdateAlertRequest[], alertComment) => { @@ -274,7 +278,7 @@ export async function update({ const { unsecuredSavedObjectsClient, user, caseService, userActionService } = clientArgs; const bulkSubCases = await caseService.getSubCases({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, ids: query.subCases.map((q) => q.id), }); @@ -292,7 +296,7 @@ export async function update({ } const subIDToParentCase = await getParentCases({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseService, subCaseIDs: nonEmptySubCaseRequests.map((subCase) => subCase.id), subCasesMap, @@ -300,7 +304,7 @@ export async function update({ const updatedAt = new Date().toISOString(); const updatedCases = await caseService.patchSubCases({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, subCases: nonEmptySubCaseRequests.map((thisCase) => { const { id: subCaseId, version, ...updateSubCaseAttributes } = thisCase; let closedInfo: { closed_at: string | null; closed_by: User | null } = { @@ -352,7 +356,7 @@ export async function update({ await updateAlerts({ caseService, - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, casesClientInternal, subCasesToSync: subCasesToSyncAlertsFor, logger: clientArgs.logger, @@ -380,7 +384,7 @@ export async function update({ ); await userActionService.bulkCreate({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, actions: buildSubCaseUserActions({ originalSubCases: bulkSubCases.saved_objects, updatedSubCases: updatedCases.saved_objects, diff --git a/x-pack/plugins/cases/server/client/user_actions/get.ts b/x-pack/plugins/cases/server/client/user_actions/get.ts index 4fbc4d333133f7..7cc1dc7d27dfe9 100644 --- a/x-pack/plugins/cases/server/client/user_actions/get.ts +++ b/x-pack/plugins/cases/server/client/user_actions/get.ts @@ -34,7 +34,7 @@ export const get = async ( checkEnabledCaseConnectorOrThrow(subCaseId); const userActions = await userActionService.getAll({ - soClient: unsecuredSavedObjectsClient, + unsecuredSavedObjectsClient, caseId, subCaseId, }); diff --git a/x-pack/plugins/cases/server/common/models/commentable_case.ts b/x-pack/plugins/cases/server/common/models/commentable_case.ts index 894e1f9a7f518f..2d1e1e18b50987 100644 --- a/x-pack/plugins/cases/server/common/models/commentable_case.ts +++ b/x-pack/plugins/cases/server/common/models/commentable_case.ts @@ -52,7 +52,7 @@ interface NewCommentResp { interface CommentableCaseParams { collection: SavedObject; subCase?: SavedObject; - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; caseService: CasesService; attachmentService: AttachmentService; logger: Logger; @@ -65,7 +65,7 @@ interface CommentableCaseParams { export class CommentableCase { private readonly collection: SavedObject; private readonly subCase?: SavedObject; - private readonly soClient: SavedObjectsClientContract; + private readonly unsecuredSavedObjectsClient: SavedObjectsClientContract; private readonly caseService: CasesService; private readonly attachmentService: AttachmentService; private readonly logger: Logger; @@ -73,14 +73,14 @@ export class CommentableCase { constructor({ collection, subCase, - soClient, + unsecuredSavedObjectsClient, caseService, attachmentService, logger, }: CommentableCaseParams) { this.collection = collection; this.subCase = subCase; - this.soClient = soClient; + this.unsecuredSavedObjectsClient = unsecuredSavedObjectsClient; this.caseService = caseService; this.attachmentService = attachmentService; this.logger = logger; @@ -144,7 +144,7 @@ export class CommentableCase { if (this.subCase) { const updatedSubCase = await this.caseService.patchSubCase({ - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, subCaseId: this.subCase.id, updatedAttributes: { updated_at: date, @@ -166,7 +166,7 @@ export class CommentableCase { } const updatedCase = await this.caseService.patchCase({ - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, caseId: this.collection.id, updatedAttributes: { updated_at: date, @@ -186,7 +186,7 @@ export class CommentableCase { version: updatedCase.version ?? this.collection.version, }, subCase: updatedSubCaseAttributes, - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, caseService: this.caseService, attachmentService: this.attachmentService, logger: this.logger, @@ -217,7 +217,7 @@ export class CommentableCase { const [comment, commentableCase] = await Promise.all([ this.attachmentService.update({ - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, attachmentId: id, updatedAttributes: { ...queryRestAttributes, @@ -272,7 +272,7 @@ export class CommentableCase { const [comment, commentableCase] = await Promise.all([ this.attachmentService.create({ - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, attributes: transformNewComment({ associationType: this.subCase ? AssociationType.subCase : AssociationType.case, createdDate, @@ -310,7 +310,7 @@ export class CommentableCase { public async encode(): Promise { try { const collectionCommentStats = await this.caseService.getAllCaseComments({ - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, id: this.collection.id, options: { fields: [], @@ -320,7 +320,7 @@ export class CommentableCase { }); const collectionComments = await this.caseService.getAllCaseComments({ - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, id: this.collection.id, options: { fields: [], @@ -340,7 +340,7 @@ export class CommentableCase { if (this.subCase) { const subCaseComments = await this.caseService.getAllSubCaseComments({ - soClient: this.soClient, + unsecuredSavedObjectsClient: this.unsecuredSavedObjectsClient, id: this.subCase.id, }); const totalAlerts = diff --git a/x-pack/plugins/cases/server/services/attachments/index.ts b/x-pack/plugins/cases/server/services/attachments/index.ts index 2308e90320c62c..c9b9d11a896899 100644 --- a/x-pack/plugins/cases/server/services/attachments/index.ts +++ b/x-pack/plugins/cases/server/services/attachments/index.ts @@ -40,35 +40,47 @@ export class AttachmentService { constructor(private readonly log: Logger) {} public async get({ - soClient, + unsecuredSavedObjectsClient, attachmentId, }: GetAttachmentArgs): Promise> { try { this.log.debug(`Attempting to GET attachment ${attachmentId}`); - return await soClient.get(CASE_COMMENT_SAVED_OBJECT, attachmentId); + return await unsecuredSavedObjectsClient.get( + CASE_COMMENT_SAVED_OBJECT, + attachmentId + ); } catch (error) { this.log.error(`Error on GET attachment ${attachmentId}: ${error}`); throw error; } } - public async delete({ soClient, attachmentId }: GetAttachmentArgs) { + public async delete({ unsecuredSavedObjectsClient, attachmentId }: GetAttachmentArgs) { try { this.log.debug(`Attempting to GET attachment ${attachmentId}`); - return await soClient.delete(CASE_COMMENT_SAVED_OBJECT, attachmentId); + return await unsecuredSavedObjectsClient.delete(CASE_COMMENT_SAVED_OBJECT, attachmentId); } catch (error) { this.log.error(`Error on GET attachment ${attachmentId}: ${error}`); throw error; } } - public async create({ soClient, attributes, references, id }: CreateAttachmentArgs) { + public async create({ + unsecuredSavedObjectsClient, + attributes, + references, + id, + }: CreateAttachmentArgs) { try { this.log.debug(`Attempting to POST a new comment`); - return await soClient.create(CASE_COMMENT_SAVED_OBJECT, attributes, { - references, - id, - }); + return await unsecuredSavedObjectsClient.create( + CASE_COMMENT_SAVED_OBJECT, + attributes, + { + references, + id, + } + ); } catch (error) { this.log.error(`Error on POST a new comment: ${error}`); throw error; @@ -76,14 +88,14 @@ export class AttachmentService { } public async update({ - soClient, + unsecuredSavedObjectsClient, attachmentId, updatedAttributes, version, }: UpdateAttachmentArgs) { try { this.log.debug(`Attempting to UPDATE comment ${attachmentId}`); - return await soClient.update( + return await unsecuredSavedObjectsClient.update( CASE_COMMENT_SAVED_OBJECT, attachmentId, updatedAttributes, @@ -95,12 +107,12 @@ export class AttachmentService { } } - public async bulkUpdate({ soClient, comments }: BulkUpdateAttachmentArgs) { + public async bulkUpdate({ unsecuredSavedObjectsClient, comments }: BulkUpdateAttachmentArgs) { try { this.log.debug( `Attempting to UPDATE comments ${comments.map((c) => c.attachmentId).join(', ')}` ); - return await soClient.bulkUpdate( + return await unsecuredSavedObjectsClient.bulkUpdate( comments.map((c) => ({ type: CASE_COMMENT_SAVED_OBJECT, id: c.attachmentId, diff --git a/x-pack/plugins/cases/server/services/cases/index.ts b/x-pack/plugins/cases/server/services/cases/index.ts index 38e9881cbdccce..1cd5ded87d76ba 100644 --- a/x-pack/plugins/cases/server/services/cases/index.ts +++ b/x-pack/plugins/cases/server/services/cases/index.ts @@ -77,20 +77,20 @@ interface GetSubCasesArgs extends ClientArgs { } interface FindCommentsArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; id: string | string[]; options?: SavedObjectFindOptionsKueryNode; } interface FindCaseCommentsArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; id: string | string[]; options?: SavedObjectFindOptionsKueryNode; includeSubCaseComments?: boolean; } interface FindSubCaseCommentsArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; id: string | string[]; options?: SavedObjectFindOptionsKueryNode; } @@ -104,7 +104,7 @@ interface FindSubCasesByIDArgs extends FindCasesArgs { } interface FindSubCasesStatusStats { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; options: SavedObjectFindOptionsKueryNode; ids: string[]; } @@ -132,15 +132,15 @@ interface PatchCasesArgs extends ClientArgs { } interface PatchSubCase { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; subCaseId: string; updatedAttributes: Partial; version?: string; } interface PatchSubCases { - soClient: SavedObjectsClientContract; - subCases: Array>; + unsecuredSavedObjectsClient: SavedObjectsClientContract; + subCases: Array>; } interface GetUserArgs { @@ -160,7 +160,7 @@ interface CaseCommentStats { } interface FindCommentsByAssociationArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; id: string | string[]; associationType: AssociationType; options?: SavedObjectFindOptionsKueryNode; @@ -181,12 +181,12 @@ interface CasesMapWithPageInfo { type FindCaseOptions = CasesFindRequest & SavedObjectFindOptionsKueryNode; interface GetTagsArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; filter?: KueryNode; } interface GetReportersArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; filter?: KueryNode; } @@ -234,7 +234,7 @@ export class CasesService { }); public async getCaseIdsByAlertId({ - soClient, + unsecuredSavedObjectsClient, alertId, filter, }: GetCaseIdsByAlertIdArgs): Promise< @@ -247,7 +247,10 @@ export class CasesService { filter, ]); - let response = await soClient.find({ + let response = await unsecuredSavedObjectsClient.find< + CommentAttributes, + GetCaseIdsByAlertIdAggs + >({ type: CASE_COMMENT_SAVED_OBJECT, fields: includeFieldsRequiredForAuthentication(), page: 1, @@ -257,7 +260,10 @@ export class CasesService { filter: combinedFilter, }); if (response.total > 100) { - response = await soClient.find({ + response = await unsecuredSavedObjectsClient.find< + CommentAttributes, + GetCaseIdsByAlertIdAggs + >({ type: CASE_COMMENT_SAVED_OBJECT, fields: includeFieldsRequiredForAuthentication(), page: 1, @@ -287,22 +293,22 @@ export class CasesService { * Returns a map of all cases combined with their sub cases if they are collections. */ public async findCasesGroupedByID({ - soClient, + unsecuredSavedObjectsClient, caseOptions, subCaseOptions, }: { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; caseOptions: FindCaseOptions; subCaseOptions?: SavedObjectFindOptionsKueryNode; }): Promise { const cases = await this.findCases({ - soClient, + unsecuredSavedObjectsClient, options: caseOptions, }); const subCasesResp = ENABLE_CASE_CONNECTOR ? await this.findSubCasesGroupByCase({ - soClient, + unsecuredSavedObjectsClient, options: subCaseOptions, ids: cases.saved_objects .filter((caseInfo) => caseInfo.attributes.type === CaseType.collection) @@ -343,7 +349,7 @@ export class CasesService { * in another request (the one below this comment). */ const totalCommentsForCases = await this.getCaseCommentStats({ - soClient, + unsecuredSavedObjectsClient, ids: Array.from(casesMap.keys()), associationType: AssociationType.case, }); @@ -374,18 +380,18 @@ export class CasesService { * This also counts sub cases. Parent cases are excluded from the statistics. */ public async findCaseStatusStats({ - soClient, + unsecuredSavedObjectsClient, caseOptions, subCaseOptions, ensureSavedObjectsAreAuthorized, }: { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; caseOptions: SavedObjectFindOptionsKueryNode; ensureSavedObjectsAreAuthorized: EnsureSOAuthCallback; subCaseOptions?: SavedObjectFindOptionsKueryNode; }): Promise { const casesStats = await this.findCases({ - soClient, + unsecuredSavedObjectsClient, options: { ...caseOptions, fields: [], @@ -415,7 +421,7 @@ export class CasesService { * don't have the same title and tags, we'd need to account for that as well. */ const cases = await this.findCases({ - soClient, + unsecuredSavedObjectsClient, options: { ...caseOptions, fields: includeFieldsRequiredForAuthentication([caseTypeField]), @@ -437,7 +443,7 @@ export class CasesService { if (ENABLE_CASE_CONNECTOR && subCaseOptions) { subCasesTotal = await this.findSubCaseStatusStats({ - soClient, + unsecuredSavedObjectsClient, options: cloneDeep(subCaseOptions), ids: caseIds, }); @@ -454,20 +460,20 @@ export class CasesService { * Retrieves the comments attached to a case or sub case. */ public async getCommentsByAssociation({ - soClient, + unsecuredSavedObjectsClient, id, associationType, options, }: FindCommentsByAssociationArgs): Promise> { if (associationType === AssociationType.subCase) { return this.getAllSubCaseComments({ - soClient, + unsecuredSavedObjectsClient, id, options, }); } else { return this.getAllCaseComments({ - soClient, + unsecuredSavedObjectsClient, id, options, }); @@ -478,11 +484,11 @@ export class CasesService { * Returns the number of total comments and alerts for a case (or sub case) */ public async getCaseCommentStats({ - soClient, + unsecuredSavedObjectsClient, ids, associationType, }: { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; ids: string[]; associationType: AssociationType; }): Promise { @@ -499,7 +505,7 @@ export class CasesService { const allComments = await Promise.all( ids.map((id) => this.getCommentsByAssociation({ - soClient, + unsecuredSavedObjectsClient, associationType, id, options: { page: 1, perPage: 1 }, @@ -508,7 +514,7 @@ export class CasesService { ); const alerts = await this.getCommentsByAssociation({ - soClient, + unsecuredSavedObjectsClient, associationType, id: ids, options: { @@ -544,11 +550,11 @@ export class CasesService { * Returns all the sub cases for a set of case IDs. Comment statistics are also returned. */ public async findSubCasesGroupByCase({ - soClient, + unsecuredSavedObjectsClient, options, ids, }: { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; options?: SavedObjectFindOptionsKueryNode; ids: string[]; }): Promise { @@ -572,7 +578,7 @@ export class CasesService { } const subCases = await this.findSubCases({ - soClient, + unsecuredSavedObjectsClient, options: { ...options, hasReference: ids.map((id) => { @@ -585,7 +591,7 @@ export class CasesService { }); const subCaseComments = await this.getCaseCommentStats({ - soClient, + unsecuredSavedObjectsClient, ids: subCases.saved_objects.map((subCase) => subCase.id), associationType: AssociationType.subCase, }); @@ -624,7 +630,7 @@ export class CasesService { * Calculates the number of sub cases for a given set of options for a set of case IDs. */ public async findSubCaseStatusStats({ - soClient, + unsecuredSavedObjectsClient, options, ids, }: FindSubCasesStatusStats): Promise { @@ -633,7 +639,7 @@ export class CasesService { } const subCases = await this.findSubCases({ - soClient, + unsecuredSavedObjectsClient, options: { ...options, page: 1, @@ -652,14 +658,14 @@ export class CasesService { } public async createSubCase({ - soClient, + unsecuredSavedObjectsClient, createdAt, caseId, createdBy, }: CreateSubCaseArgs): Promise> { try { this.log.debug(`Attempting to POST a new sub case`); - return soClient.create( + return unsecuredSavedObjectsClient.create( SUB_CASE_SAVED_OBJECT, // ENABLE_CASE_CONNECTOR: populate the owner field correctly transformNewSubCase({ createdAt, createdBy, owner: '' }), @@ -679,10 +685,13 @@ export class CasesService { } } - public async getMostRecentSubCase(soClient: SavedObjectsClientContract, caseId: string) { + public async getMostRecentSubCase( + unsecuredSavedObjectsClient: SavedObjectsClientContract, + caseId: string + ) { try { this.log.debug(`Attempting to find most recent sub case for caseID: ${caseId}`); - const subCases = await soClient.find({ + const subCases = await unsecuredSavedObjectsClient.find({ perPage: 1, sortField: 'created_at', sortOrder: 'desc', @@ -700,20 +709,20 @@ export class CasesService { } } - public async deleteSubCase(soClient: SavedObjectsClientContract, id: string) { + public async deleteSubCase(unsecuredSavedObjectsClient: SavedObjectsClientContract, id: string) { try { this.log.debug(`Attempting to DELETE sub case ${id}`); - return await soClient.delete(SUB_CASE_SAVED_OBJECT, id); + return await unsecuredSavedObjectsClient.delete(SUB_CASE_SAVED_OBJECT, id); } catch (error) { this.log.error(`Error on DELETE sub case ${id}: ${error}`); throw error; } } - public async deleteCase({ soClient, id: caseId }: GetCaseArgs) { + public async deleteCase({ unsecuredSavedObjectsClient, id: caseId }: GetCaseArgs) { try { this.log.debug(`Attempting to DELETE case ${caseId}`); - return await soClient.delete(CASE_SAVED_OBJECT, caseId); + return await unsecuredSavedObjectsClient.delete(CASE_SAVED_OBJECT, caseId); } catch (error) { this.log.error(`Error on DELETE case ${caseId}: ${error}`); throw error; @@ -721,21 +730,24 @@ export class CasesService { } public async getCase({ - soClient, + unsecuredSavedObjectsClient, id: caseId, }: GetCaseArgs): Promise> { try { this.log.debug(`Attempting to GET case ${caseId}`); - return await soClient.get(CASE_SAVED_OBJECT, caseId); + return await unsecuredSavedObjectsClient.get(CASE_SAVED_OBJECT, caseId); } catch (error) { this.log.error(`Error on GET case ${caseId}: ${error}`); throw error; } } - public async getSubCase({ soClient, id }: GetCaseArgs): Promise> { + public async getSubCase({ + unsecuredSavedObjectsClient, + id, + }: GetCaseArgs): Promise> { try { this.log.debug(`Attempting to GET sub case ${id}`); - return await soClient.get(SUB_CASE_SAVED_OBJECT, id); + return await unsecuredSavedObjectsClient.get(SUB_CASE_SAVED_OBJECT, id); } catch (error) { this.log.error(`Error on GET sub case ${id}: ${error}`); throw error; @@ -743,12 +755,12 @@ export class CasesService { } public async getSubCases({ - soClient, + unsecuredSavedObjectsClient, ids, }: GetSubCasesArgs): Promise> { try { this.log.debug(`Attempting to GET sub cases ${ids.join(', ')}`); - return await soClient.bulkGet( + return await unsecuredSavedObjectsClient.bulkGet( ids.map((id) => ({ type: SUB_CASE_SAVED_OBJECT, id })) ); } catch (error) { @@ -758,12 +770,12 @@ export class CasesService { } public async getCases({ - soClient, + unsecuredSavedObjectsClient, caseIds, }: GetCasesArgs): Promise> { try { this.log.debug(`Attempting to GET cases ${caseIds.join(', ')}`); - return await soClient.bulkGet( + return await unsecuredSavedObjectsClient.bulkGet( caseIds.map((caseId) => ({ type: CASE_SAVED_OBJECT, id: caseId })) ); } catch (error) { @@ -773,12 +785,12 @@ export class CasesService { } public async findCases({ - soClient, + unsecuredSavedObjectsClient, options, }: FindCasesArgs): Promise> { try { this.log.debug(`Attempting to find cases`); - return await soClient.find({ + return await unsecuredSavedObjectsClient.find({ sortField: defaultSortField, ...cloneDeep(options), type: CASE_SAVED_OBJECT, @@ -790,7 +802,7 @@ export class CasesService { } public async findSubCases({ - soClient, + unsecuredSavedObjectsClient, options, }: FindCasesArgs): Promise> { try { @@ -798,14 +810,14 @@ export class CasesService { // if the page or perPage options are set then respect those instead of trying to // grab all sub cases if (options?.page !== undefined || options?.perPage !== undefined) { - return soClient.find({ + return unsecuredSavedObjectsClient.find({ sortField: defaultSortField, ...cloneDeep(options), type: SUB_CASE_SAVED_OBJECT, }); } - const stats = await soClient.find({ + const stats = await unsecuredSavedObjectsClient.find({ fields: [], page: 1, perPage: 1, @@ -813,7 +825,7 @@ export class CasesService { ...cloneDeep(options), type: SUB_CASE_SAVED_OBJECT, }); - return soClient.find({ + return unsecuredSavedObjectsClient.find({ page: 1, perPage: stats.total, sortField: defaultSortField, @@ -833,7 +845,7 @@ export class CasesService { * @param id the saved object ID of the parent collection to find sub cases for. */ public async findSubCasesByCaseId({ - soClient, + unsecuredSavedObjectsClient, ids, options, }: FindSubCasesByIDArgs): Promise> { @@ -849,7 +861,7 @@ export class CasesService { try { this.log.debug(`Attempting to GET sub cases for case collection id ${ids.join(', ')}`); return this.findSubCases({ - soClient, + unsecuredSavedObjectsClient, options: { ...options, hasReference: ids.map((id) => ({ @@ -877,21 +889,21 @@ export class CasesService { } private async getAllComments({ - soClient, + unsecuredSavedObjectsClient, id, options, }: FindCommentsArgs): Promise> { try { this.log.debug(`Attempting to GET all comments internal for id ${JSON.stringify(id)}`); if (options?.page !== undefined || options?.perPage !== undefined) { - return soClient.find({ + return unsecuredSavedObjectsClient.find({ type: CASE_COMMENT_SAVED_OBJECT, sortField: defaultSortField, ...cloneDeep(options), }); } // get the total number of comments that are in ES then we'll grab them all in one go - const stats = await soClient.find({ + const stats = await unsecuredSavedObjectsClient.find({ type: CASE_COMMENT_SAVED_OBJECT, fields: [], page: 1, @@ -901,7 +913,7 @@ export class CasesService { ...cloneDeep(options), }); - return soClient.find({ + return unsecuredSavedObjectsClient.find({ type: CASE_COMMENT_SAVED_OBJECT, page: 1, perPage: stats.total, @@ -922,7 +934,7 @@ export class CasesService { * sub case comments are excluded. If the `filter` field is included in the options, it will override this behavior */ public async getAllCaseComments({ - soClient, + unsecuredSavedObjectsClient, id, options, includeSubCaseComments = false, @@ -954,7 +966,7 @@ export class CasesService { this.log.debug(`Attempting to GET all comments for case caseID ${JSON.stringify(id)}`); return await this.getAllComments({ - soClient, + unsecuredSavedObjectsClient, id, options: { hasReferenceOperator: 'OR', @@ -970,7 +982,7 @@ export class CasesService { } public async getAllSubCaseComments({ - soClient, + unsecuredSavedObjectsClient, id, options, }: FindSubCaseCommentsArgs): Promise> { @@ -987,7 +999,7 @@ export class CasesService { this.log.debug(`Attempting to GET all comments for sub case caseID ${JSON.stringify(id)}`); return await this.getAllComments({ - soClient, + unsecuredSavedObjectsClient, id, options: { hasReferenceOperator: 'OR', @@ -1002,12 +1014,12 @@ export class CasesService { } public async getReporters({ - soClient, + unsecuredSavedObjectsClient, filter, }: GetReportersArgs): Promise> { try { this.log.debug(`Attempting to GET all reporters`); - const firstReporters = await soClient.find({ + const firstReporters = await unsecuredSavedObjectsClient.find({ type: CASE_SAVED_OBJECT, fields: ['created_by', OWNER_FIELD], page: 1, @@ -1015,7 +1027,7 @@ export class CasesService { filter: cloneDeep(filter), }); - return await soClient.find({ + return await unsecuredSavedObjectsClient.find({ type: CASE_SAVED_OBJECT, fields: ['created_by', OWNER_FIELD], page: 1, @@ -1029,12 +1041,12 @@ export class CasesService { } public async getTags({ - soClient, + unsecuredSavedObjectsClient, filter, }: GetTagsArgs): Promise> { try { this.log.debug(`Attempting to GET all cases`); - const firstTags = await soClient.find({ + const firstTags = await unsecuredSavedObjectsClient.find({ type: CASE_SAVED_OBJECT, fields: ['tags', OWNER_FIELD], page: 1, @@ -1042,7 +1054,7 @@ export class CasesService { filter: cloneDeep(filter), }); - return await soClient.find({ + return await unsecuredSavedObjectsClient.find({ type: CASE_SAVED_OBJECT, fields: ['tags', OWNER_FIELD], page: 1, @@ -1080,20 +1092,29 @@ export class CasesService { } } - public async postNewCase({ soClient, attributes, id }: PostCaseArgs) { + public async postNewCase({ unsecuredSavedObjectsClient, attributes, id }: PostCaseArgs) { try { this.log.debug(`Attempting to POST a new case`); - return await soClient.create(CASE_SAVED_OBJECT, attributes, { id }); + return await unsecuredSavedObjectsClient.create( + CASE_SAVED_OBJECT, + attributes, + { id } + ); } catch (error) { this.log.error(`Error on POST a new case: ${error}`); throw error; } } - public async patchCase({ soClient, caseId, updatedAttributes, version }: PatchCaseArgs) { + public async patchCase({ + unsecuredSavedObjectsClient, + caseId, + updatedAttributes, + version, + }: PatchCaseArgs) { try { this.log.debug(`Attempting to UPDATE case ${caseId}`); - return await soClient.update( + return await unsecuredSavedObjectsClient.update( CASE_SAVED_OBJECT, caseId, { ...updatedAttributes }, @@ -1105,10 +1126,10 @@ export class CasesService { } } - public async patchCases({ soClient, cases }: PatchCasesArgs) { + public async patchCases({ unsecuredSavedObjectsClient, cases }: PatchCasesArgs) { try { this.log.debug(`Attempting to UPDATE case ${cases.map((c) => c.caseId).join(', ')}`); - return await soClient.bulkUpdate( + return await unsecuredSavedObjectsClient.bulkUpdate( cases.map((c) => ({ type: CASE_SAVED_OBJECT, id: c.caseId, @@ -1122,10 +1143,15 @@ export class CasesService { } } - public async patchSubCase({ soClient, subCaseId, updatedAttributes, version }: PatchSubCase) { + public async patchSubCase({ + unsecuredSavedObjectsClient, + subCaseId, + updatedAttributes, + version, + }: PatchSubCase) { try { this.log.debug(`Attempting to UPDATE sub case ${subCaseId}`); - return await soClient.update( + return await unsecuredSavedObjectsClient.update( SUB_CASE_SAVED_OBJECT, subCaseId, { ...updatedAttributes }, @@ -1137,12 +1163,12 @@ export class CasesService { } } - public async patchSubCases({ soClient, subCases }: PatchSubCases) { + public async patchSubCases({ unsecuredSavedObjectsClient, subCases }: PatchSubCases) { try { this.log.debug( `Attempting to UPDATE sub case ${subCases.map((c) => c.subCaseId).join(', ')}` ); - return await soClient.bulkUpdate( + return await unsecuredSavedObjectsClient.bulkUpdate( subCases.map((c) => ({ type: SUB_CASE_SAVED_OBJECT, id: c.subCaseId, diff --git a/x-pack/plugins/cases/server/services/configure/index.ts b/x-pack/plugins/cases/server/services/configure/index.ts index 28e9af01f9d735..8ea1c903622b72 100644 --- a/x-pack/plugins/cases/server/services/configure/index.ts +++ b/x-pack/plugins/cases/server/services/configure/index.ts @@ -13,7 +13,7 @@ import { ESCasesConfigureAttributes } from '../../../common/api'; import { CASE_CONFIGURE_SAVED_OBJECT } from '../../../common/constants'; interface ClientArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; } interface GetCaseConfigureArgs extends ClientArgs { @@ -36,20 +36,20 @@ interface PatchCaseConfigureArgs extends ClientArgs { export class CaseConfigureService { constructor(private readonly log: Logger) {} - public async delete({ soClient, configurationId }: GetCaseConfigureArgs) { + public async delete({ unsecuredSavedObjectsClient, configurationId }: GetCaseConfigureArgs) { try { this.log.debug(`Attempting to DELETE case configure ${configurationId}`); - return await soClient.delete(CASE_CONFIGURE_SAVED_OBJECT, configurationId); + return await unsecuredSavedObjectsClient.delete(CASE_CONFIGURE_SAVED_OBJECT, configurationId); } catch (error) { this.log.debug(`Error on DELETE case configure ${configurationId}: ${error}`); throw error; } } - public async get({ soClient, configurationId }: GetCaseConfigureArgs) { + public async get({ unsecuredSavedObjectsClient, configurationId }: GetCaseConfigureArgs) { try { this.log.debug(`Attempting to GET case configuration ${configurationId}`); - return await soClient.get( + return await unsecuredSavedObjectsClient.get( CASE_CONFIGURE_SAVED_OBJECT, configurationId ); @@ -59,10 +59,10 @@ export class CaseConfigureService { } } - public async find({ soClient, options }: FindCaseConfigureArgs) { + public async find({ unsecuredSavedObjectsClient, options }: FindCaseConfigureArgs) { try { this.log.debug(`Attempting to find all case configuration`); - return await soClient.find({ + return await unsecuredSavedObjectsClient.find({ ...cloneDeep(options), // Get the latest configuration sortField: 'created_at', @@ -75,10 +75,10 @@ export class CaseConfigureService { } } - public async post({ soClient, attributes, id }: PostCaseConfigureArgs) { + public async post({ unsecuredSavedObjectsClient, attributes, id }: PostCaseConfigureArgs) { try { this.log.debug(`Attempting to POST a new case configuration`); - return await soClient.create( + return await unsecuredSavedObjectsClient.create( CASE_CONFIGURE_SAVED_OBJECT, { ...attributes, @@ -91,10 +91,14 @@ export class CaseConfigureService { } } - public async patch({ soClient, configurationId, updatedAttributes }: PatchCaseConfigureArgs) { + public async patch({ + unsecuredSavedObjectsClient, + configurationId, + updatedAttributes, + }: PatchCaseConfigureArgs) { try { this.log.debug(`Attempting to UPDATE case configuration ${configurationId}`); - return await soClient.update( + return await unsecuredSavedObjectsClient.update( CASE_CONFIGURE_SAVED_OBJECT, configurationId, { diff --git a/x-pack/plugins/cases/server/services/connector_mappings/index.ts b/x-pack/plugins/cases/server/services/connector_mappings/index.ts index 44892336458213..e3ac5b4c55cf3b 100644 --- a/x-pack/plugins/cases/server/services/connector_mappings/index.ts +++ b/x-pack/plugins/cases/server/services/connector_mappings/index.ts @@ -12,7 +12,7 @@ import { CASE_CONNECTOR_MAPPINGS_SAVED_OBJECT } from '../../../common/constants' import { SavedObjectFindOptionsKueryNode } from '../../common'; interface ClientArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; } interface FindConnectorMappingsArgs extends ClientArgs { options?: SavedObjectFindOptionsKueryNode; @@ -32,10 +32,10 @@ interface UpdateConnectorMappingsArgs extends ClientArgs { export class ConnectorMappingsService { constructor(private readonly log: Logger) {} - public async find({ soClient, options }: FindConnectorMappingsArgs) { + public async find({ unsecuredSavedObjectsClient, options }: FindConnectorMappingsArgs) { try { this.log.debug(`Attempting to find all connector mappings`); - return await soClient.find({ + return await unsecuredSavedObjectsClient.find({ ...options, type: CASE_CONNECTOR_MAPPINGS_SAVED_OBJECT, }); @@ -45,10 +45,14 @@ export class ConnectorMappingsService { } } - public async post({ soClient, attributes, references }: PostConnectorMappingsArgs) { + public async post({ + unsecuredSavedObjectsClient, + attributes, + references, + }: PostConnectorMappingsArgs) { try { this.log.debug(`Attempting to POST a new connector mappings`); - return await soClient.create( + return await unsecuredSavedObjectsClient.create( CASE_CONNECTOR_MAPPINGS_SAVED_OBJECT, attributes, { @@ -62,14 +66,14 @@ export class ConnectorMappingsService { } public async update({ - soClient, + unsecuredSavedObjectsClient, mappingId, attributes, references, }: UpdateConnectorMappingsArgs) { try { this.log.debug(`Attempting to UPDATE connector mappings ${mappingId}`); - return await soClient.update( + return await unsecuredSavedObjectsClient.update( CASE_CONNECTOR_MAPPINGS_SAVED_OBJECT, mappingId, attributes, diff --git a/x-pack/plugins/cases/server/services/index.ts b/x-pack/plugins/cases/server/services/index.ts index 6a56001f29cac9..09895d9392441e 100644 --- a/x-pack/plugins/cases/server/services/index.ts +++ b/x-pack/plugins/cases/server/services/index.ts @@ -15,5 +15,5 @@ export { AlertService, AlertServiceContract } from './alerts'; export { AttachmentService } from './attachments'; export interface ClientArgs { - soClient: SavedObjectsClientContract; + unsecuredSavedObjectsClient: SavedObjectsClientContract; } diff --git a/x-pack/plugins/cases/server/services/user_actions/index.ts b/x-pack/plugins/cases/server/services/user_actions/index.ts index 0da640de2a6ca2..e691b9305fb37f 100644 --- a/x-pack/plugins/cases/server/services/user_actions/index.ts +++ b/x-pack/plugins/cases/server/services/user_actions/index.ts @@ -32,11 +32,11 @@ interface PostCaseUserActionArgs extends ClientArgs { export class CaseUserActionService { constructor(private readonly log: Logger) {} - public async getAll({ soClient, caseId, subCaseId }: GetCaseUserActionArgs) { + public async getAll({ unsecuredSavedObjectsClient, caseId, subCaseId }: GetCaseUserActionArgs) { try { const id = subCaseId ?? caseId; const type = subCaseId ? SUB_CASE_SAVED_OBJECT : CASE_SAVED_OBJECT; - const caseUserActionInfo = await soClient.find({ + const caseUserActionInfo = await unsecuredSavedObjectsClient.find({ type: CASE_USER_ACTION_SAVED_OBJECT, fields: [], hasReference: { type, id }, @@ -44,7 +44,7 @@ export class CaseUserActionService { perPage: 1, }); - return await soClient.find({ + return await unsecuredSavedObjectsClient.find({ type: CASE_USER_ACTION_SAVED_OBJECT, hasReference: { type, id }, page: 1, @@ -58,10 +58,10 @@ export class CaseUserActionService { } } - public async bulkCreate({ soClient, actions }: PostCaseUserActionArgs) { + public async bulkCreate({ unsecuredSavedObjectsClient, actions }: PostCaseUserActionArgs) { try { this.log.debug(`Attempting to POST a new case user action`); - return await soClient.bulkCreate( + return await unsecuredSavedObjectsClient.bulkCreate( actions.map((action) => ({ type: CASE_USER_ACTION_SAVED_OBJECT, ...action })) ); } catch (error) {