-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Allow the default space to be accessed via /s/default
#77109
Allow the default space to be accessed via /s/default
#77109
Conversation
cd783c1
to
d4a89e5
Compare
d4a89e5
to
64786c2
Compare
return { | ||
spaceId: DEFAULT_SPACE_ID, | ||
pathHasExplicitSpaceIdentifier: false, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love that this function now has two responsibilities, but this function is called in some hot paths, and I didn't want to have to do regex matching twice when I'm already doing the work here to extract the space identifier.
@@ -45,3 +50,10 @@ export function addSpaceIdToPath( | |||
} | |||
return `${basePath}${requestedPath}`; | |||
} | |||
|
|||
function stripServerBasePath(requestBasePath: string, serverBasePath: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No functional changes: extracted for readability
|
||
if (spaceId !== DEFAULT_SPACE_ID) { | ||
if (pathHasExplicitSpaceIdentifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual change which enables the default space to be accessed via /s/default
Pinging @elastic/kibana-security (Team:Security) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
It might be worthwhile to simplify this reporting code as well (CC @tsullivan):
kibana/x-pack/plugins/reporting/server/core.ts
Lines 223 to 226 in d10d70b
if (spaceId && spaceId !== DEFAULT_SPACE_ID) { | |
logger.info(`Generating request for space: ${spaceId}`); | |
this.getPluginSetupDeps().basePath.set(fakeRequest, `/s/${spaceId}`); | |
} |
@@ -10,41 +10,60 @@ describe('getSpaceIdFromPath', () => { | |||
describe('without a serverBasePath defined', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just from naively reading the tests, it's not clear that the default space can be used as an explicit space identifier.
Optional nit: what do you think about adding some additional test cases to make that more clear?
diff --git a/x-pack/plugins/spaces/common/lib/spaces_url_parser.test.ts b/x-pack/plugins/spaces/common/lib/spaces_url_parser.test.ts
index d563a0c86cd..c4379574f85 100644
--- a/x-pack/plugins/spaces/common/lib/spaces_url_parser.test.ts
+++ b/x-pack/plugins/spaces/common/lib/spaces_url_parser.test.ts
@@ -16,6 +16,14 @@ describe('getSpaceIdFromPath', () => {
});
});
+ test('it identifies the space url context with the default space', () => {
+ const basePath = `/s/${DEFAULT_SPACE_ID}`;
+ expect(getSpaceIdFromPath(basePath)).toEqual({
+ spaceId: DEFAULT_SPACE_ID,
+ pathHasExplicitSpaceIdentifier: true,
+ });
+ });
+
test('ignores space identifiers in the middle of the path', () => {
const basePath = `/this/is/a/crazy/path/s/my-awesome-space-lives-here`;
expect(getSpaceIdFromPath(basePath)).toEqual({
@@ -42,6 +50,14 @@ describe('getSpaceIdFromPath', () => {
});
});
+ test('it identifies the space url context with the default space', () => {
+ const basePath = `/s/${DEFAULT_SPACE_ID}`;
+ expect(getSpaceIdFromPath(basePath)).toEqual({
+ spaceId: DEFAULT_SPACE_ID,
+ pathHasExplicitSpaceIdentifier: true,
+ });
+ });
+
test('it identifies the space url context following the server base path', () => {
const basePath = `/server-base-path-here/s/my-awesome-space-lives-here`;
expect(getSpaceIdFromPath(basePath, '/server-base-path-here')).toEqual({
@@ -50,6 +66,14 @@ describe('getSpaceIdFromPath', () => {
});
});
+ test('it identifies the space url context with the default space following the server base path', () => {
+ const basePath = `/server-base-path-here/s/${DEFAULT_SPACE_ID}`;
+ expect(getSpaceIdFromPath(basePath, '/server-base-path-here')).toEqual({
+ spaceId: DEFAULT_SPACE_ID,
+ pathHasExplicitSpaceIdentifier: true,
+ });
+ });
+
test('ignores space identifiers in the middle of the path', () => {
const basePath = `/this/is/a/crazy/path/s/my-awesome-space-lives-here`;
expect(getSpaceIdFromPath(basePath, '/this/is/a')).toEqual({
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! Done in 2084f12
(#77109)
💚 Build SucceededMetrics [docs]page load bundle size
History
To update your PR or re-run it, just comment with: |
#80815) * Allow the default space to be accessed via /s/default * apply suggestions from code review
* master: (51 commits) [Discover] Unskip flaky test (elastic#80670) Fix security solution template label (elastic#80754) [Ingest]: ignore 404, check if there are transforms in results. (elastic#80721) Moving loader to logo in header, add a slight 250ms pause (elastic#78879) [Security Solution][Cases] Fix bug with case connectors (elastic#80642) Update known-plugins.asciidoc (elastic#75388) [Lens] Add median operation (elastic#79453) Fix navigateToApp logic when navigating to the current app. (elastic#80809) [Visualizations] Fix bad color mapping with multiple split series (elastic#80801) [ILM] Add esErrorHandler for the new es js client (elastic#80302) Fix codeowners (elastic#80826) skip flaky suite (elastic#79463) [Timelion] Remove kui usage (elastic#80287) [Ingest Manager] add skipIfNoDockerRegistry to package_install_complete test (elastic#80779) [Alerting UI] Disable "Save" button for Alerts with broken Connectors (elastic#80579) Allow the default space to be accessed via `/s/default` (elastic#77109) Add script to identify plugin dependencies for TS project references migration (elastic#80463) [Search] Client side session service (elastic#76889) feat: 🎸 add separator for different context menu groups (elastic#80498) Lazy load reporting (elastic#80492) ...
Summary
Allows the default space to be accessed via
/s/default
as well as/
.Resolves #62053