-
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
Spaces - Hiding management link #38472
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2f3e7fc
Changing the Spaces management section to behave like the other FC
kobelb 131cfc2
Adding those glorious tests and fixing a bug
kobelb 6250324
Fixing some test descriptions
kobelb 00fb4f3
Making the mergeCapabilities operation emulate the old behavior
kobelb 84f8acf
Fixing privileges test with the addition of the new action
kobelb 49e078f
Updating jest snapshot
kobelb f7a48ce
Merge remote-tracking branch 'upstream/master' into authz/spaces-mana…
kobelb 4d21c34
Adding tests, preventing additional clobbering
kobelb 84644c8
Changing requireUICapability to use management.kibana.spaces
kobelb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { mergeCapabilities } from './merge_capabilities'; | ||
|
||
const defaultProps = { | ||
catalogue: {}, | ||
management: {}, | ||
navLinks: {}, | ||
}; | ||
|
||
test(`"{ foo: {} }" doesn't clobber "{ foo: { bar: true } }"`, () => { | ||
const output1 = mergeCapabilities({ foo: { bar: true } }, { foo: {} }); | ||
expect(output1).toEqual({ ...defaultProps, foo: { bar: true } }); | ||
|
||
const output2 = mergeCapabilities({ foo: { bar: true } }, { foo: {} }); | ||
expect(output2).toEqual({ ...defaultProps, foo: { bar: true } }); | ||
}); | ||
|
||
test(`"{ foo: { bar: true } }" doesn't clobber "{ baz: { quz: true } }"`, () => { | ||
const output1 = mergeCapabilities({ foo: { bar: true } }, { baz: { quz: true } }); | ||
expect(output1).toEqual({ ...defaultProps, foo: { bar: true }, baz: { quz: true } }); | ||
|
||
const output2 = mergeCapabilities({ baz: { quz: true } }, { foo: { bar: true } }); | ||
expect(output2).toEqual({ ...defaultProps, foo: { bar: true }, baz: { quz: true } }); | ||
}); | ||
|
||
test(`"{ foo: { bar: { baz: true } } }" doesn't clobber "{ foo: { bar: { quz: true } } }"`, () => { | ||
const output1 = mergeCapabilities( | ||
{ foo: { bar: { baz: true } } }, | ||
{ foo: { bar: { quz: true } } } | ||
); | ||
expect(output1).toEqual({ ...defaultProps, foo: { bar: { baz: true, quz: true } } }); | ||
|
||
const output2 = mergeCapabilities( | ||
{ foo: { bar: { quz: true } } }, | ||
{ foo: { bar: { baz: true } } } | ||
); | ||
expect(output2).toEqual({ ...defaultProps, foo: { bar: { baz: true, quz: true } } }); | ||
}); | ||
|
||
test(`error is thrown if boolean and object clash`, () => { | ||
expect(() => { | ||
mergeCapabilities({ foo: { bar: { baz: true } } }, { foo: { bar: true } }); | ||
}).toThrowErrorMatchingInlineSnapshot(`"a boolean and an object can't be merged"`); | ||
|
||
expect(() => { | ||
mergeCapabilities({ foo: { bar: true } }, { foo: { bar: { baz: true } } }); | ||
}).toThrowErrorMatchingInlineSnapshot(`"a boolean and an object can't be merged"`); | ||
}); | ||
|
||
test(`supports duplicates as long as the booleans are the same`, () => { | ||
const output1 = mergeCapabilities({ foo: { bar: true } }, { foo: { bar: true } }); | ||
expect(output1).toEqual({ ...defaultProps, foo: { bar: true } }); | ||
|
||
const output2 = mergeCapabilities({ foo: { bar: false } }, { foo: { bar: false } }); | ||
expect(output2).toEqual({ ...defaultProps, foo: { bar: false } }); | ||
}); | ||
|
||
test(`error is thrown if merging "true" and "false"`, () => { | ||
expect(() => { | ||
mergeCapabilities({ foo: { bar: false } }, { foo: { bar: true } }); | ||
}).toThrowErrorMatchingInlineSnapshot(`"\\"true\\" and \\"false\\" can't be merged"`); | ||
|
||
expect(() => { | ||
mergeCapabilities({ foo: { bar: true } }, { foo: { bar: false } }); | ||
}).toThrowErrorMatchingInlineSnapshot(`"\\"true\\" and \\"false\\" can't be merged"`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import routes from 'ui/routes'; | |
import { AdvancedSettingsSubtitle } from './components/advanced_settings_subtitle'; | ||
import { AdvancedSettingsTitle } from './components/advanced_settings_title'; | ||
|
||
const MANAGE_SPACES_KEY = 'manage_spaces'; | ||
const MANAGE_SPACES_KEY = 'spaces'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It felt weird to have the ui capability |
||
|
||
routes.defaults(/\/management/, { | ||
resolve: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.../spaces/public/views/management/spaces_grid/__snapshots__/spaces_grid_pages.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We're changing from a shallow merge to a deep merge to support the new
management.kibana.spaces
flag. Originally, this was intentionally designed as a shallow merge so that plugins would not clobber capabilities which didn't belong to them. While it's true thatmerge
won't allow a plugin to delete capabilities defined by other plugins, the addition of capabilities to other plugin's "buckets" is likely not something we want to encourage/support.I know we've discussed letting plugins enhance the capabilities of other plugins, but I don't know if this is the way we want to do so. Since
management
is a defined key of theCapabilities
interface, how do you feel about allowing the merge for this key, but not for the rest?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.
The previous implementation wasn't preventing duplicate definitions of the same first-level ui capability: https://codepen.io/kobelb/pen/MMWROw?editors=0012. We take advantage of this for building the
catalogue
ui capabilities: some of them are hard-coded here and we add to this list within the xpack_main plugin here.I agree, but I don't believe those restrictions where previously enforced, at least not when using
injectDefaultVars
(when we first implemented FC) or the newuiCapabilities
. We have some enforcement on this withinxpack_main
here, but this is only for merging the ui capabilities that we derive from the feature registration.I can look at changing spaces to not use
uiCapabilities
to define the management section, and instead augment uiCapabilitiesForFeatures, but we'll still need the ability to merge all of these "deeply".I think the proper solution to this problem is to follow through on #36221 and make it so that each of these "ui capability sections" is able to define it's own rules and so we can enforce these restrictions throughout the system, I was trying to prevent making this a dependency for fixing this specific issue though.
I added tests with 4d21c34 to ensure we aren't clobbering anything, and added additional safeguards. Does this assuage any of your previous concerns?
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.
So... we can't do this at the moment because we don't register a "Spaces" feature, and these actions are hard-coded here: https://github.com/elastic/kibana/pull/38472/files#diff-f5ed4149300a16c9d74494d7b470b450R68. I don't know what I was thinking previously.
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.
Agreed, thanks for the thoughtful followup!
❤️