-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Show generate creds for static-roles when you have read permissions #19190
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9775002
fix, need to test and write test for
Monkeychip 2a73ff0
the fix
Monkeychip 171f5dd
add test coverage
Monkeychip 4fdc3fb
changelog:
Monkeychip 405adbf
woops param already existed
Monkeychip 0383aff
remove test coverage
Monkeychip 4a67091
Delete database-role-edit-test.js
Monkeychip 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,3 @@ | ||
```release-note:bug | ||
ui: show Get credentials button for static roles detail page when a user has the proper permissions. | ||
``` |
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 |
---|---|---|
|
@@ -36,12 +36,17 @@ | |
Rotate credentials | ||
</button> | ||
{{/if}} | ||
{{#if @model.canGenerateCredentials}} | ||
{{#if | ||
(or | ||
(and (eq @model.type "static") @model.canGenerateStaticCredentials) | ||
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. can be reverted if the above is possible! |
||
(and (eq @model.type "dynamic") @model.canGenerateCredentials) | ||
) | ||
}} | ||
<button | ||
type="button" | ||
class="toolbar-link" | ||
{{on "click" (fn this.generateCreds @model.id @model.type)}} | ||
data-test-database-role-generate-creds | ||
data-test-database-role-creds={{@model.type}} | ||
> | ||
{{if (eq @model.type "static") "Get credentials" "Generate credentials"}} | ||
</button> | ||
|
45 changes: 45 additions & 0 deletions
45
ui/tests/integration/components/database-role-edit-test.js
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,45 @@ | ||
import { module, test } from 'qunit'; | ||
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. I'll remove this file and put in another pr that will not get backported. |
||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { setupMirage } from 'ember-cli-mirage/test-support'; | ||
import { capabilitiesStub } from 'vault/tests/helpers/stubs'; | ||
|
||
module('Integration | Component | database-role-edit meep', function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupMirage(hooks); | ||
|
||
hooks.beforeEach(function () { | ||
this.store = this.owner.lookup('service:store'); | ||
this.store.pushPayload('database-role', { | ||
modelName: 'database/role', | ||
database: ['my-mongodb-database'], | ||
backend: 'database', | ||
type: 'static', | ||
name: 'my-static-role', | ||
id: 'my-static-role', | ||
}); | ||
this.store.pushPayload('database-role', { | ||
modelName: 'database/role', | ||
database: ['my-mongodb-database'], | ||
backend: 'database', | ||
type: 'dynamic', | ||
name: 'my-dynamic-role', | ||
id: 'my-dynamic-role', | ||
}); | ||
this.modelStatic = this.store.peekRecord('database/role', 'my-static-role'); | ||
this.modelDynamic = this.store.peekRecord('database/role', 'my-dynamic-role'); | ||
}); | ||
|
||
test('it should show Get credentials button when a user has the correct policy', async function (assert) { | ||
this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['read'])); | ||
await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`); | ||
assert.dom('[data-test-database-role-creds="static"]').exists('Get credentials button exists'); | ||
}); | ||
|
||
test('it should show Generate credentials button when a user has the correct policy', async function (assert) { | ||
this.server.post('/sys/capabilities-self', capabilitiesStub('database/creds/my-role', ['read'])); | ||
await render(hbs`<DatabaseRoleEdit @model={{this.modelDynamic}} @mode="show"/>`); | ||
assert.dom('[data-test-database-role-creds="dynamic"]').exists('Generate credentials button exists'); | ||
}); | ||
}); |
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.
could this be a computed instead and true if
staticCredentialPath.canRead
ORcredentialPath.canRead
is true? that way the HBS template could still be just@model.canGenerateCredentials
?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.
Good idea. The type matters here. So if type is static then we have to check the static path and if type is dynamic check the dynamic path. We could still do a computed given this logic but I go back and forth on this. I think because this is a backport, and I just noticed (my bad) that the the static param already existed
canGetCredentials
I'll keep the changes to a minimum. ThecanGenerateCreds
andcanGetCredentials
are used in another template so to use a computed I would need to amend the logic there as well. Thoughts?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.
Nice catch! I see that now, good call removing!