Skip to content

Fix policy automations role restrictions in UI - #46910

Merged
nulmete merged 1 commit into
mainfrom
nulmete/policy-automations-role-restrictions
Jun 5, 2026
Merged

Fix policy automations role restrictions in UI#46910
nulmete merged 1 commit into
mainfrom
nulmete/policy-automations-role-restrictions

Conversation

@nulmete

@nulmete nulmete commented Jun 5, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #46912

  • Webhook/ticket checkbox is now disabled (locked, no explanation) for Maintainers in PolicyAutomationsFields — covers the create modal, edit form, and manage automations modal since all three share the component. (Any role below maintainer can't edit automations.)
  • Automations cell pencil icon and cursor: pointer are now hidden for roles that can't open the automations modal (technician and below).
  • Config and team data are now fetched for all authenticated roles so the webhook automation shows correctly in the table for technicians (previously gated on canAddOrDeletePolicies, which excluded them).

Testing

  • QA'd all new/changed functionality manually

Before

With a global/fleet technician user, Automations cell on Policies page showed "2 automations" when there were actually 3 automations configured.
Also, the pencil (edit) icon and cursor pointer are shown even though technicians can't access the Manage automations modal.

Screen.Recording.2026-06-05.at.12.48.07.PM.mov

Maintainers can manage automations but they can't configure webhooks or tickets (product requirement + also forbidden by BE). This silently failed when checking the "Send webhook" checkbox when creating or editing.

Screen.Recording.2026-06-05.at.12.46.42.PM.mov

After

Technicians see all available automations on the Policies page (and this matches the Details page).
Also, the edit icon is no longer shown, and the Automations cell is no longer clickable.

Screen.Recording.2026-06-05.at.12.44.36.PM.mov

Locked "Send webhook" / "Create ticket" for Maintainers.
https://github.com/user-attachments/assets/f0c0b058-db02-4174-bb8e-33165014806f

Summary by CodeRabbit

Release Notes

  • New Features / Improvements
    • Users without policy modification permissions can now access and view the policies page.
    • Automations column displays read-only state for users without edit permissions.
    • Non-global admin users can view webhook/ticket automations but see them as locked and uneditable.
    • Enhanced visual feedback distinguishing read-only elements from interactive ones.

- Disable webhook/ticket checkbox for non-admins (maintainers, technicians) in PolicyAutomationsFields
- Hide pencil icon and pointer cursor in Automations cell for roles that can't open the automations modal
- Fetch config/team data for all roles so webhook automation shows correctly in the table for technicians
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.02%. Comparing base (41b3b53) to head (5830a18).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...e/components/PoliciesTable/PoliciesTableConfig.tsx 78.57% 3 Missing ⚠️
...olicyAutomationsFields/PolicyAutomationsFields.tsx 70.00% 3 Missing ⚠️
...policies/ManagePoliciesPage/ManagePoliciesPage.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #46910      +/-   ##
==========================================
- Coverage   67.02%   67.02%   -0.01%     
==========================================
  Files        2859     2860       +1     
  Lines      224683   224699      +16     
  Branches    11577    11584       +7     
==========================================
+ Hits       150592   150601       +9     
- Misses      60445    60452       +7     
  Partials    13646    13646              
Flag Coverage Δ
frontend 56.93% <72.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nulmete
nulmete marked this pull request as ready for review June 5, 2026 15:59
Copilot AI review requested due to automatic review settings June 5, 2026 15:59
@nulmete
nulmete requested a review from a team as a code owner June 5, 2026 15:59

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a5048040-ce13-46b3-9dfc-7bc754944649

📥 Commits

Reviewing files that changed from the base of the PR and between 6e2256f and 5830a18.

📒 Files selected for processing (5)
  • frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx
  • frontend/pages/policies/ManagePoliciesPage/components/PoliciesTable/PoliciesTableConfig.tsx
  • frontend/pages/policies/ManagePoliciesPage/components/PoliciesTable/_styles.scss
  • frontend/pages/policies/components/PolicyAutomationsFields/PolicyAutomationsFields.tsx
  • frontend/pages/policies/components/PolicyAutomationsFields/types.ts

Walkthrough

This PR refactors automations UI permission handling across the policies page. Data queries for global config and team details are decoupled from the canAddOrDeletePolicies permission check, allowing these queries to load regardless of user permission level. Permission gating for webhook/ticket automations is moved to use AppContext to determine global admin status. The automations cell rendering is unified to build shared content once, then conditionally render either a readonly <span> or an editable EditableAutomationsCell. A new isLocked flag distinguishes permission-based row disabling from fleet-feature-disabled states.

Possibly related PRs

  • fleetdm/fleet#46254: Updates to ManagePoliciesPage.tsx query gating are related to that PR's wiring of the ManageAutomationsModal with policy automation config props.
  • fleetdm/fleet#46326: Both PRs modify PolicyAutomationsFields to refactor webhook/ticket automation logic; this PR adds AppContext-based admin gating while the other refactors the editable section structure.
  • fleetdm/fleet#46023: Both PRs modify ManagePoliciesPage.tsx around canAddOrDeletePolicies permission gating for automations-related data and modal enablement.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix policy automations role restrictions in UI' clearly summarizes the main change: addressing UI permission restrictions for policy automations across different roles.
Description check ✅ Passed The description is mostly complete, including the related issue (#46912), detailed explanation of changes for different user roles, before/after context, and manual QA confirmation. While some optional checklist items are omitted, the critical information is present.
Linked Issues check ✅ Passed The pull request successfully addresses all three coding objectives from issue #46912: hiding the edit icon for Technicians, fetching config/team data for all roles to show correct automation counts, and locking webhook/ticket options for Maintainers.
Out of Scope Changes check ✅ Passed All code changes are directly related to implementing role-based restrictions for policy automations. The modifications to ManagePoliciesPage, PoliciesTable, and PolicyAutomationsFields align with the stated objectives and issue requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nulmete/policy-automations-role-restrictions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Fleet’s Policies UI permission handling so policy automations are displayed accurately for read-only roles and editing controls are restricted consistently across create/edit/manage flows.

Changes:

  • Fetches global config and team config for all authenticated roles (instead of gating on policy write permissions) so webhook/ticket automations render correctly for technicians.
  • Makes the Policies table “Automations” cell truly read-only when the user can’t open the Manage automations modal (no pencil icon, no pointer cursor, not keyboard-focusable).
  • Introduces a “locked” state for automation checkbox rows and uses it to disable webhook/ticket automation toggles for non-admin roles (e.g., Maintainers).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx Removes write-permission gating from config/team queries so technicians can see accurate webhook/ticket automations in the table.
frontend/pages/policies/ManagePoliciesPage/components/PoliciesTable/PoliciesTableConfig.tsx Refactors AutomationsCell to render a non-interactive <span> when editing is not allowed (removes misleading click affordances).
frontend/pages/policies/ManagePoliciesPage/components/PoliciesTable/_styles.scss Adds styling for read-only automations cells to keep a non-clickable cursor.
frontend/pages/policies/components/PolicyAutomationsFields/types.ts Adds isLocked to distinguish “role-locked” rows from “feature-disabled” rows.
frontend/pages/policies/components/PolicyAutomationsFields/PolicyAutomationsFields.tsx Locks webhook/ticket automation toggles to admins-only (global admin or team admin for real teams), while keeping other automations behavior intact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nulmete
nulmete merged commit c7297e0 into main Jun 5, 2026
26 checks passed
@nulmete
nulmete deleted the nulmete/policy-automations-role-restrictions branch June 5, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Manage automations] UI permissions follow-ups

3 participants