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

Allow the default space to be accessed via /s/default #77109

Merged
merged 3 commits into from
Oct 16, 2020

Conversation

legrego
Copy link
Member

@legrego legrego commented Sep 9, 2020

Summary

Allows the default space to be accessed via /s/default as well as /.

Resolves #62053

@legrego legrego force-pushed the spaces/explicit-default-space-path branch 2 times, most recently from cd783c1 to d4a89e5 Compare September 22, 2020 14:09
@legrego legrego force-pushed the spaces/explicit-default-space-path branch from d4a89e5 to 64786c2 Compare September 22, 2020 16:47
@legrego legrego added Feature:Security/Spaces Platform Security - Spaces feature Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.11.0 v8.0.0 release_note:enhancement labels Oct 14, 2020
Comment on lines +20 to +23
return {
spaceId: DEFAULT_SPACE_ID,
pathHasExplicitSpaceIdentifier: false,
};
Copy link
Member Author

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) {
Copy link
Member Author

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) {
Copy link
Member Author

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

@legrego legrego marked this pull request as ready for review October 14, 2020 15:46
@legrego legrego requested a review from a team as a code owner October 14, 2020 15:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@jportner jportner self-requested a review October 15, 2020 16:42
Copy link
Contributor

@jportner jportner left a 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):

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', () => {
Copy link
Contributor

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({

Copy link
Member Author

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)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

page load bundle size

id before after diff
spaces 364.2KB 364.4KB +246.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@legrego legrego merged commit 51ac14b into elastic:master Oct 16, 2020
@legrego legrego deleted the spaces/explicit-default-space-path branch October 16, 2020 11:22
legrego added a commit that referenced this pull request Oct 16, 2020
#80815)

* Allow the default space to be accessed via /s/default

* apply suggestions from code review
gmmorris added a commit to gmmorris/kibana that referenced this pull request Oct 19, 2020
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Security/Spaces Platform Security - Spaces feature release_note:enhancement Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SPACES] default space should support /s/ api
4 participants