-
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
[Security Solution] [Detections] Only display actions options if user has "read" privileges #78812
Conversation
...ins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.ts
Outdated
Show resolved
Hide resolved
c94b7a0
to
490d4b0
Compare
Pinging @elastic/siem (Team:SIEM) |
This all works as is. Just tested it, but instead of us showing the error message in the combo box and populating it and running the risk of us pushing the value from the combo box to the backend: Can we change the code around here to remove the combo box and use regular text elements to display the error? Somewhere down here add the conditional logic and html: return isReadOnlyView ? (
<StepContentWrapper addPadding={addPadding}>
<StepRuleDescription schema={schema} data={initialState} columns="single" />
</StepContentWrapper>
) : (
<>
<StepContentWrapper addPadding={!isUpdateView}>
<Form form={form} data-test-subj="stepRuleActions">
<EuiForm>
<UseField
path="throttle"
component={ThrottleSelectField}
componentProps={throttleFieldComponentProps}
/>
{throttle !== stepActionsDefaultValue.throttle ? ( |
Technically the value is still the default value of |
0f06a39
to
c24b0f4
Compare
form={form} | ||
style={{ display: application.capabilities.actions.show ? 'block' : 'none' }} | ||
data-test-subj="stepRuleActions" | ||
> |
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.
If things begin to feel or get messy in here, feel ok to drop all the boolean logic weirdness with expressions. That is meant to be a helper for when things look very templatey and nice in React but as time marches on along with permission booleans and things begin getting complex where we have branching logic within branching logic and things look like a bunch of && and ! mashed together we can refactor out the expressions and do regular:
if/else if/else if/else
or if we want to we can do the regular:
if (condition) return this chunk of code early/if (second condition) return this chunk of code ...
Since that will allow us to execute more than one block of code within brackets compared to excessive and hard to reason about expressions within expressions and React doing odd things like adding {false/null/undefined<></>} to its tree to later parse out and remove.
I would avoid having elements with block
vs none
on them compared to just not displaying the component altogether based on conditional logic. Usually it is better to omit an HTML element altogether and DOM weight unless we have a bunch of DOM elements that are constantly being added and removed in which case doing a shown vs. being hidden is better (It will then prevent reflows from happening).
Already looking at this logic if it was me writing the code I would drop all the boolean template expressions and just use normal if/else if logic rather than mixing all these booleans together and trying to get them all correct.
Already we have these that cause us to keep a lot of state in our head:
- isReadOnlyView
- isUpdateView
- application.capabilities.actions.show
And the way the logic flows it's not clear branches that show relationships between the booleans but rather the booleans look rather disjointed from each other and nested within each other.
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.
Other tips is there is an unset
css keyword if you're going this route you can utilize maybe instead of assuming that your form is always going to be a block
:
https://developer.mozilla.org/en-US/docs/Web/CSS/unset#:~:text=The%20unset%20CSS%20keyword%20resets,its%20initial%20value%20if%20not.
Also you might be able to use destructoring to avoid assuming the block?
...{ application.capabilities.actions.show ? { display: 'block' } : {} }
But you will always render the form there when you have data as you introduce a new object but I don't think that's going to be a big deal.
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 agree with @FrankHassanabad's comment here. We could just do something like this to avoid having to use style block
or none
, right?
{ application.capabilities.actions.show && (
<Form ...>...</Form>
)}
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 result of not rendering the actions step form is having to increase the complexity of the state of the whole rule creation form. The state of the rule creation form depends on pulling a default value from this and when the actions step form is not rendered, the rule creation form blows up. I'm going to look into using the GhostFormField
and maybe rendering that with the throttle
default somehow so that I don't need to mess with state.
Also a good thing to note, after talking with @rylnd I learned that we are submitting the entire form on edit. This implies that an analyst with no privileges on actions goes to edit a rule created by another analyst with actions privileges and they will be greeted with this error upon "save" in the "edit rules" page and the rule changes will not be saved.
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
…privileges for actions
… text saying user is missing required privileges
ebbb0a7
to
782e0bd
Compare
💚 Build SucceededMetrics [docs]async chunks size
History
To update your PR or re-run it, just comment with: |
…f user has "read" privileges (#78812) (#79364) * adds new 'can_read_actions' property to privileges api * only display rule actions piece if user has 'read' privileges for actions * display dropdown with custom text telling user they do not have read privileges for actions * fixes type error * update tests * utilize application capabilities instead of making a server request * remove changes to route tests * don't show form unless user has read permissions for actions, display text saying user is missing required privileges * pr feedback: refactor logic for rendering form fields
* master: (128 commits) add core-js production dependency (elastic#79395) Add support for sharing saved objects to all spaces (elastic#76132) [Alerting UI] Display a banner to users when some alerts have failures, added alert statuses column and filters (elastic#79038) load js-yaml lazily (elastic#79092) skip flaky suite (elastic#77278) Fix agentPolicyUpdateEventHandler() to use app context soClient for creation of actions (elastic#79341) [Security Solution] Untitled Timeline created when first action is to add note (elastic#78988) [Security Solutions][Detection Engine] Updates the edit rules page to:wq! only have what is selected for editing (elastic#79233) Cleanup yarn.lock from duplicates (elastic#66617) [kbn/optimizer] implement more efficient auto transpilation for node (elastic#79052) [Ingest Manager] Rename Fleet setup and requirement, Fleet => Central… (elastic#79291) [core/server/plugins] don't run discovery in dev server parent process (take 2) (elastic#79358) [babel/register] remove from build (take 2) (elastic#79379) [Security Solution] Changes rules table tag display (elastic#77102) define integrationTestRoot in config file and use to define screensho… (elastic#79247) Revert "[babel/register] remove from build (elastic#79176)" skip flaky suite (elastic#75241) [Uptime] Synthetics UI (elastic#77960) [Security Solution] [Detections] Only display actions options if user has "read" privileges (elastic#78812) [babel/register] remove from build (elastic#79176) ...
* master: (288 commits) add core-js production dependency (elastic#79395) Add support for sharing saved objects to all spaces (elastic#76132) [Alerting UI] Display a banner to users when some alerts have failures, added alert statuses column and filters (elastic#79038) load js-yaml lazily (elastic#79092) skip flaky suite (elastic#77278) Fix agentPolicyUpdateEventHandler() to use app context soClient for creation of actions (elastic#79341) [Security Solution] Untitled Timeline created when first action is to add note (elastic#78988) [Security Solutions][Detection Engine] Updates the edit rules page to only have what is selected for editing (elastic#79233) Cleanup yarn.lock from duplicates (elastic#66617) [kbn/optimizer] implement more efficient auto transpilation for node (elastic#79052) [Ingest Manager] Rename Fleet setup and requirement, Fleet => Central… (elastic#79291) [core/server/plugins] don't run discovery in dev server parent process (take 2) (elastic#79358) [babel/register] remove from build (take 2) (elastic#79379) [Security Solution] Changes rules table tag display (elastic#77102) define integrationTestRoot in config file and use to define screensho… (elastic#79247) Revert "[babel/register] remove from build (elastic#79176)" skip flaky suite (elastic#75241) [Uptime] Synthetics UI (elastic#77960) [Security Solution] [Detections] Only display actions options if user has "read" privileges (elastic#78812) [babel/register] remove from build (elastic#79176) ...
Pinging @elastic/security-solution (Team: SecuritySolution) |
Summary
Fixes #74170
updates the detections privileges route to include checking for "read" privilege on actions.Also updates the rule create / edit steps to display a message if the user is missing the actions privileges while still allowing the user to create and activate a rule.testing:
This script will post a role with the necessary detections permissions
This is what the "Rule Actions" step on the rule creation form looks like if the user does not have "read" privileges for actions:
And here it is on the edit page
Checklist
Delete any items that are not applicable to this PR.
For maintainers