Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace] Fix find saved object within a workspace without queryparams return all the saved objects #9420

Merged
merged 3 commits into from
Mar 26, 2025

Conversation

FriedhelmWS
Copy link
Contributor

@FriedhelmWS FriedhelmWS commented Feb 19, 2025

Description

Given we have two workspaces (namely first and second), and each has a saved object.

We retrieve the saved objects using the following URL (using workspace prefix but no query parameters):
/w/first/api/opensearch-dashboards/management/saved_objects/_find?type=index-pattern

Previously, this request would return both saved objects because when no workspace query parameter was provided, our endpoint would pass workspace: undefined to the actual query, bypassing the workspace check. As a result, the backend would return all saved objects even when the original request was made under the first workspace context.

This PR removes the logic of passing workspace: undefined when there is no workspace query parameter. Now, the wrapper for the _find endpoint automatically retrieves the current workspace context, ensuring the backend only returns saved objects associated with the current workspace.

Issues Resolved

NA

Screenshot

NA

Testing the changes

Changelog

  • fix: fixing when find saved objects within a workspace returns saved objects in all the workspaces

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link
Contributor

❌ Entry Too Long

Entry is 111 characters long, which is 11 characters longer than the maximum allowed length of 100 characters. Please revise your entry to be within the maximum length.

opensearch-changeset-bot bot added a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Feb 19, 2025
)
);
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just refactoring repeated code

FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Feb 22, 2025
FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Feb 25, 2025
FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Feb 25, 2025
@FriedhelmWS FriedhelmWS changed the title Fix find saved object within a workspace without queryparams return all the saved objects [Workspace] Fix find saved object within a workspace without queryparams return all the saved objects Mar 4, 2025
FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Mar 6, 2025
FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Mar 11, 2025
FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Mar 12, 2025
FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Mar 13, 2025
Comment on lines +135 to +138
it('should handle workspace filtering', async () => {
registerFindRoute(router, Promise.resolve(managementService));

req.query.workspaces = ['workspace1'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we have a case for workspace is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the no workspace case is already been covered by the above "basic find" test case. For a find request without workspace filtering then the saved object is always opt-in so that it somehow pointless to explicitly test this case.

Comment on lines -101 to +105
workspaces: req.query.workspaces ? Array<string>().concat(req.query.workspaces) : undefined,
...(req.query.workspaces
? {
workspaces: Array<string>().concat(req.query.workspaces),
}
: {}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have another PR to fix the * issue: #9409. I think it should be fine for this PR to leave *.

FriedhelmWS pushed a commit to FriedhelmWS/OpenSearch-Dashboards that referenced this pull request Mar 18, 2025
@FriedhelmWS FriedhelmWS requested a review from Maosaic as a code owner March 26, 2025 02:02
@SuZhou-Joe SuZhou-Joe merged commit 4315eba into opensearch-project:main Mar 26, 2025
74 of 76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants