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 <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Sep 13, 2023
1 parent f465403 commit bd355dd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 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: 3 additions & 8 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import {
FIND_DEFAULT_PER_PAGE,
SavedObjectsUtils,
} from './utils';
import { PUBLIC_WORKSPACE_ID, WorkspacePermissionMode } from '../../../../utils/constants';
import { WorkspacePermissionMode } from '../../../../utils/constants';
import { ACL, Principals } from '../../permission_control/acl';
import { WORKSPACE_TYPE } from '../../../../utils';

Expand Down 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 bd355dd

Please sign in to comment.