Skip to content

Commit

Permalink
renaming to unsecuredSavedObjectsClient (#101215)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Jun 3, 2021
1 parent 373cd68 commit d59dbad
Show file tree
Hide file tree
Showing 25 changed files with 335 additions and 272 deletions.
41 changes: 22 additions & 19 deletions x-pack/plugins/cases/server/client/attachments/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SavedObject<SubCaseAttributes>> {
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: [],
Expand All @@ -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',
Expand Down Expand Up @@ -152,7 +155,7 @@ const addGeneratedAlerts = async (
});

const caseInfo = await caseService.getCase({
soClient: unsecuredSavedObjectsClient,
unsecuredSavedObjectsClient,
id: caseId,
});

Expand All @@ -171,7 +174,7 @@ const addGeneratedAlerts = async (

const subCase = await getSubCase({
caseService,
savedObjectsClient: unsecuredSavedObjectsClient,
unsecuredSavedObjectsClient,
caseId,
createdAt: createdDate,
userActionService,
Expand All @@ -182,7 +185,7 @@ const addGeneratedAlerts = async (
logger,
collection: caseInfo,
subCase,
soClient: unsecuredSavedObjectsClient,
unsecuredSavedObjectsClient,
caseService,
attachmentService,
});
Expand Down Expand Up @@ -212,7 +215,7 @@ const addGeneratedAlerts = async (
}

await userActionService.bulkCreate({
soClient: unsecuredSavedObjectsClient,
unsecuredSavedObjectsClient,
actions: [
buildCommentUserActionItem({
action: 'create',
Expand Down Expand Up @@ -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<CommentableCase> {
const [casePromise, subCasePromise] = await Promise.allSettled([
caseService.getCase({
soClient,
unsecuredSavedObjectsClient,
id,
}),
...(ENABLE_CASE_CONNECTOR
? [
caseService.getSubCase({
soClient,
unsecuredSavedObjectsClient,
id,
}),
]
Expand All @@ -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({
Expand All @@ -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');
Expand All @@ -293,7 +296,7 @@ async function getCombinedCase({
collection: casePromise.value,
caseService,
attachmentService,
soClient,
unsecuredSavedObjectsClient,
});
}
}
Expand Down Expand Up @@ -366,7 +369,7 @@ export const addComment = async (
const combinedCase = await getCombinedCase({
caseService,
attachmentService,
soClient: unsecuredSavedObjectsClient,
unsecuredSavedObjectsClient,
id: caseId,
logger,
});
Expand Down Expand Up @@ -398,7 +401,7 @@ export const addComment = async (
}

await userActionService.bulkCreate({
soClient: unsecuredSavedObjectsClient,
unsecuredSavedObjectsClient,
actions: [
buildCommentUserActionItem({
action: 'create',
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/cases/server/client/attachments/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function deleteAll(
): Promise<void> {
const {
user,
unsecuredSavedObjectsClient: soClient,
unsecuredSavedObjectsClient,
caseService,
attachmentService,
userActionService,
Expand All @@ -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,
});
Expand All @@ -93,7 +93,7 @@ export async function deleteAll(
await Promise.all(
comments.saved_objects.map((comment) =>
attachmentService.delete({
soClient,
unsecuredSavedObjectsClient,
attachmentId: comment.id,
})
)
Expand All @@ -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',
Expand Down Expand Up @@ -136,7 +136,7 @@ export async function deleteComment(
) {
const {
user,
unsecuredSavedObjectsClient: soClient,
unsecuredSavedObjectsClient,
attachmentService,
userActionService,
logger,
Expand All @@ -150,7 +150,7 @@ export async function deleteComment(
const deleteDate = new Date().toISOString();

const myComment = await attachmentService.get({
soClient,
unsecuredSavedObjectsClient,
attachmentId: attachmentID,
});

Expand All @@ -175,12 +175,12 @@ export async function deleteComment(
}

await attachmentService.delete({
soClient,
unsecuredSavedObjectsClient,
attachmentId: attachmentID,
});

await userActionService.bulkCreate({
soClient,
unsecuredSavedObjectsClient,
actions: [
buildCommentUserActionItem({
action: 'delete',
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/cases/server/client/attachments/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function find(
clientArgs: CasesClientArgs
): Promise<CommentsResponse> {
const {
unsecuredSavedObjectsClient: soClient,
unsecuredSavedObjectsClient,
caseService,
logger,
authorization,
Expand Down Expand Up @@ -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
Expand All @@ -141,7 +141,7 @@ export async function find(
}
: {
caseService,
soClient,
unsecuredSavedObjectsClient,
id,
options: {
page: defaultPage,
Expand Down Expand Up @@ -184,15 +184,15 @@ export async function get(
): Promise<CommentResponse> {
const {
attachmentService,
unsecuredSavedObjectsClient: soClient,
unsecuredSavedObjectsClient,
logger,
authorization,
auditLogger,
} = clientArgs;

try {
const comment = await attachmentService.get({
soClient,
unsecuredSavedObjectsClient,
attachmentId: attachmentID,
});

Expand Down Expand Up @@ -225,7 +225,7 @@ export async function getAll(
clientArgs: CasesClientArgs
): Promise<AllCommentsResponse> {
const {
unsecuredSavedObjectsClient: soClient,
unsecuredSavedObjectsClient,
caseService,
logger,
authorization,
Expand Down Expand Up @@ -256,7 +256,7 @@ export async function getAll(

if (subCaseID) {
comments = await caseService.getAllSubCaseComments({
soClient,
unsecuredSavedObjectsClient,
id: subCaseID,
options: {
filter,
Expand All @@ -265,7 +265,7 @@ export async function getAll(
});
} else {
comments = await caseService.getAllCaseComments({
soClient,
unsecuredSavedObjectsClient,
id: caseID,
includeSubCaseComments,
options: {
Expand Down
22 changes: 11 additions & 11 deletions x-pack/plugins/cases/server/client/attachments/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface UpdateArgs {
interface CombinedCaseParams {
attachmentService: AttachmentService;
caseService: CasesService;
soClient: SavedObjectsClientContract;
unsecuredSavedObjectsClient: SavedObjectsClientContract;
caseID: string;
logger: Logger;
subCaseId?: string;
Expand All @@ -49,19 +49,19 @@ interface CombinedCaseParams {
async function getCommentableCase({
attachmentService,
caseService,
soClient,
unsecuredSavedObjectsClient,
caseID,
subCaseId,
logger,
}: CombinedCaseParams) {
if (subCaseId) {
const [caseInfo, subCase] = await Promise.all([
caseService.getCase({
soClient,
unsecuredSavedObjectsClient,
id: caseID,
}),
caseService.getSubCase({
soClient,
unsecuredSavedObjectsClient,
id: subCaseId,
}),
]);
Expand All @@ -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,
});
}
Expand All @@ -100,7 +100,7 @@ export async function update(
const {
attachmentService,
caseService,
unsecuredSavedObjectsClient: soClient,
unsecuredSavedObjectsClient,
logger,
user,
userActionService,
Expand All @@ -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,
});

Expand Down Expand Up @@ -179,7 +179,7 @@ export async function update(
});

await userActionService.bulkCreate({
soClient,
unsecuredSavedObjectsClient,
actions: [
buildCommentUserActionItem({
action: 'update',
Expand Down
Loading

0 comments on commit d59dbad

Please sign in to comment.