-
Notifications
You must be signed in to change notification settings - Fork 8.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
Warn & Disallow Creating Role with Existing Name #132218
Conversation
…when attempting to create a role with a name that already exists. Disallows creating a role with a name that already exists. Event handling efficiency needs review.
Implemented unit and functional tests.
3cee9b0
to
46f9a7b
Compare
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.
Nice work, a few nits and suggestions in the comments below 👍
x-pack/plugins/security/server/routes/authorization/roles/put.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/security/server/routes/authorization/roles/put.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/security/server/routes/authorization/roles/put.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/security/server/routes/authorization/roles/put.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx
Show resolved
Hide resolved
@elasticmachine merge upstream |
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.
A couple more nits, LGTM, nice job!!
x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.test.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/security/server/routes/authorization/roles/put.test.ts
Outdated
Show resolved
Hide resolved
…test.ts Co-authored-by: Joe Portner <[email protected]>
…_role_page.test.tsx Co-authored-by: Joe Portner <[email protected]>
💚 Build SucceededMetrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
This PR was mis-labeled 🙈 it actually merged into |
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
* Adds inline warning (name focus/onBlur) and toast warning (saveRole) when attempting to create a role with a name that already exists. Disallows creating a role with a name that already exists. Event handling efficiency needs review. * Updated API documentation. Implemented unit and functional tests. * Added name compare to throttle GET request from onBlur for efficiency. * Reorganized functional and unit tests. Improved UI logic and presentation. * Update x-pack/plugins/security/server/routes/authorization/roles/put.test.ts Co-authored-by: Joe Portner <[email protected]> * Update x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.test.tsx Co-authored-by: Joe Portner <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Joe Portner <[email protected]> (cherry picked from commit cb403a6)
* Adds inline warning (name focus/onBlur) and toast warning (saveRole) when attempting to create a role with a name that already exists. Disallows creating a role with a name that already exists. Event handling efficiency needs review. * Updated API documentation. Implemented unit and functional tests. * Added name compare to throttle GET request from onBlur for efficiency. * Reorganized functional and unit tests. Improved UI logic and presentation. * Update x-pack/plugins/security/server/routes/authorization/roles/put.test.ts Co-authored-by: Joe Portner <[email protected]> * Update x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.test.tsx Co-authored-by: Joe Portner <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Joe Portner <[email protected]> (cherry picked from commit cb403a6)
Resolves #34712
Overview
This PR adds checks to the edit role page, when in create mode, to warn the user and disallow role creation when the user enters a role name that already exists. This is achieved in two ways...
When the name field loses focus:
A new state property and helper function are utilized to flag when the entered name already exists. If the page is in create mode, the state property is checked and set in the onBlur handler for the name field. When the form row containing the field is rendered the isValid and error are set based on the new state property, providing in-line feedback in the form.
When the create button is clicked:
An API get call already occurs during the save operation and is leveraged in this change. A new optional 'createOnly' parameter is passed into the client API saveRole method. The value for createOnly is determined by the page being in create mode (!isEditingExistingRole). The onSave method will throw a conflict (409) error if the create only parameter is true and the role name already exists. The thrown error is displayed in a toast notification.
Non-breaking API Change
The API saveRole method and PUT /api/security/role/ request are both modified with an an optional boolean parameter 'createOnly'. 'createOnly' has a default value of false to avoid a breaking change with any existing references to the method. If 'createOnly' is true, a response/result of 409 will indicate the role cannot be created because it already exists.
Testing