Skip to content

Commit

Permalink
remove share logic check for delete
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Sep 25, 2023
1 parent ea9f3a4 commit 5e09396
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 36 deletions.
1 change: 0 additions & 1 deletion src/core/public/saved_objects/saved_objects_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ describe('SavedObjectsClient', () => {
"method": "DELETE",
"query": Object {
"force": false,
"workspace": undefined,
},
},
]
Expand Down
2 changes: 0 additions & 2 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export interface SavedObjectsBatchResponse<T = unknown> {
export interface SavedObjectsDeleteOptions {
/** Force deletion of an object that exists in multiple namespaces */
force?: boolean;
workspace?: string;
}

/**
Expand Down Expand Up @@ -337,7 +336,6 @@ export class SavedObjectsClient {

const query = {
force: !!options?.force,
workspace: this._getCurrentWorkspace(),
};

return this.savedObjectsFetch(this.getPath([type, id]), { method: 'DELETE', query });
Expand Down
4 changes: 1 addition & 3 deletions src/core/server/saved_objects/routes/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ export const registerDeleteRoute = (router: IRouter) => {
}),
query: schema.object({
force: schema.maybe(schema.boolean()),
workspace: schema.maybe(schema.string()),
}),
},
},
router.handleLegacyErrors(async (context, req, res) => {
const { type, id } = req.params;
const { force, workspace } = req.query;
const { force } = req.query;
const result = await context.core.savedObjects.client.delete(type, id, {
force,
workspaces: workspace ? [workspace] : undefined,
});
return res.ok({ body: result });
})
Expand Down
19 changes: 0 additions & 19 deletions src/core/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2554,25 +2554,6 @@ describe('SavedObjectsRepository', () => {
expect(client.get).toHaveBeenCalledTimes(1);
});

it(`throws when the document has multiple workspaces and the force option is not enabled`, async () => {
const workspaces = ['foo-workspace', 'bar-workspace'];
const response = getMockGetResponse({
type: NAMESPACE_AGNOSTIC_TYPE,
id,
namespace,
workspaces,
});
client.get.mockResolvedValueOnce(
opensearchClientMock.createSuccessTransportRequestPromise(response)
);
await expect(
savedObjectsRepository.delete(NAMESPACE_AGNOSTIC_TYPE, id, { namespace, workspaces })
).rejects.toThrowError(
'Unable to delete saved object that exists in multiple workspaces, use the `force` option to delete it anyway'
);
expect(client.get).toHaveBeenCalledTimes(1);
});

it(`throws when the type is multi-namespace and the document has all namespaces and the force option is not enabled`, async () => {
const response = getMockGetResponse({ type: MULTI_NAMESPACE_TYPE, id, namespace });
response._source.namespaces = ['*'];
Expand Down
11 changes: 0 additions & 11 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,17 +725,6 @@ export class SavedObjectsRepository {
}
}

const { workspaces } = options;
if (workspaces) {
const obj = await this.get(type, id, { namespace });
const existingWorkspace = obj.workspaces || [];
if (!force && existingWorkspace.length > 1) {
throw SavedObjectsErrorHelpers.createBadRequestError(
'Unable to delete saved object that exists in multiple workspaces, use the `force` option to delete it anyway'
);
}
}

const { body, statusCode } = await this.client.delete<DeleteDocumentResponse>(
{
id: rawId,
Expand Down

0 comments on commit 5e09396

Please sign in to comment.