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 13, 2023
1 parent 05fab00 commit ad7eca2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 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
24 changes: 7 additions & 17 deletions src/core/server/saved_objects/routes/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IRouter } from '../../http';
import { exportSavedObjectsToStream } from '../export';
import { validateObjects } from './utils';
import { collectSavedObjects } from '../import/collect_saved_objects';
import { PUBLIC_WORKSPACE_ID, WORKSPACE_TYPE } from '../../../utils';
import { WORKSPACE_TYPE } from '../../../utils';

const SHARE_LIMIT = 10000;

Expand Down 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
11 changes: 2 additions & 9 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ import {
FIND_DEFAULT_PER_PAGE,
SavedObjectsUtils,
} from './utils';
import { PUBLIC_WORKSPACE_ID } from '../../../../utils/constants';

// BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository
// so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient.

Expand Down Expand Up @@ -1424,11 +1422,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 @@ -1469,7 +1463,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 @@ -1480,7 +1474,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 ad7eca2

Please sign in to comment.