Skip to content

Commit

Permalink
Remove pulic workspace logic for share API
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Sep 12, 2023
1 parent f465403 commit 5914ba8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/core/server/saved_objects/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export function registerRoutes({
registerImportRoute(router, config);
registerCopyRoute(router, config);
registerResolveImportErrorsRoute(router, config);
// TODO disable when workspace is not enabled
registerShareRoute(router);

const internalRouter = http.createRouter('/internal/saved_objects/');
Expand Down
22 changes: 6 additions & 16 deletions src/core/server/saved_objects/routes/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,11 @@ export const registerShareRoute = (router: IRouter) => {

const savedObjects = collectSavedObjectsResult.collectedObjects;

const nonPublicSharedObjects = savedObjects
// non-public
.filter(
(obj) =>
obj.workspaces &&
obj.workspaces.length > 0 &&
!obj.workspaces.includes(PUBLIC_WORKSPACE_ID)
)
const sharedObjects = savedObjects
.filter((obj) => obj.workspaces && obj.workspaces.length > 0)
.map((obj) => ({ id: obj.id, type: obj.type, workspaces: obj.workspaces }));

if (nonPublicSharedObjects.length === 0) {
if (sharedObjects.length === 0) {
return res.ok({
body: savedObjects.map((savedObject) => ({
type: savedObject.type,
Expand All @@ -86,13 +80,9 @@ export const registerShareRoute = (router: IRouter) => {
});
}

const response = await savedObjectsClient.addToWorkspaces(
nonPublicSharedObjects,
targetWorkspaceIds,
{
workspaces: sourceWorkspaceId ? [sourceWorkspaceId] : undefined,
}
);
const response = await savedObjectsClient.addToWorkspaces(sharedObjects, targetWorkspaceIds, {
workspaces: sourceWorkspaceId ? [sourceWorkspaceId] : undefined,
});
return res.ok({
body: response,
});
Expand Down
9 changes: 2 additions & 7 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,11 +1427,7 @@ export class SavedObjectsRepository {
// saved objects must exist in specified workspace
if (options.workspaces) {
const invalidObjects = savedObjects.filter((obj) => {
if (
obj.workspaces &&
obj.workspaces.length > 0 &&
!obj.workspaces.includes(PUBLIC_WORKSPACE_ID)
) {
if (obj.workspaces && obj.workspaces.length > 0) {
return intersection(obj.workspaces, options.workspaces).length === 0;
}
return false;
Expand Down Expand Up @@ -1472,7 +1468,7 @@ export class SavedObjectsRepository {
{
script: {
source: `
if (params.workspaces != null && ctx._source.workspaces != null && !ctx._source.workspaces?.contains(params.globalWorkspaceId)) {
if (params.workspaces != null && ctx._source.workspaces != null) {
ctx._source.workspaces.addAll(params.workspaces);
HashSet workspacesSet = new HashSet(ctx._source.workspaces);
ctx._source.workspaces = new ArrayList(workspacesSet);
Expand All @@ -1483,7 +1479,6 @@ export class SavedObjectsRepository {
params: {
time,
workspaces,
globalWorkspaceId: PUBLIC_WORKSPACE_ID,
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/saved_objects/service/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,16 @@ export class SavedObjectsClient {
/**
* Adds workspace to SavedObjects
*
* @param objects
* @param savedObjects
* @param workspaces
* @param options
*/
addToWorkspaces = async (
objects: SavedObjectsShareObjects[],
savedObjects: SavedObjectsShareObjects[],
workspaces: string[],
options: SavedObjectsAddToWorkspacesOptions = {}
): Promise<SavedObjectsAddToWorkspacesResponse[]> => {
return await this._repository.addToWorkspaces(objects, workspaces, options);
return await this._repository.addToWorkspaces(savedObjects, workspaces, options);
};

/**
Expand Down

0 comments on commit 5914ba8

Please sign in to comment.