Skip to content

Added frontend support for No team automations - #32507

Merged
getvictor merged 1 commit into
mainfrom
victor/32061-frontend
Sep 2, 2025
Merged

Added frontend support for No team automations#32507
getvictor merged 1 commit into
mainfrom
victor/32061-frontend

Conversation

@getvictor

@getvictor getvictor commented Sep 2, 2025

Copy link
Copy Markdown
Member

Fixes #32061

Checklist for submitter

Testing

  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • New Features

    • Team-level configuration now supports the “No Team” selection (team 0).
    • Expanded availability of the “Other” option in the Automations dropdown for non-maintainers.
  • Bug Fixes

    • Team 0 loads correctly in Policies management.
    • Automations configuration correctly switches between global (All Teams) and team contexts, including No Team.
    • Post-update refresh behavior is consistent: global refresh for All Teams, team refresh otherwise.

@getvictor

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 2, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@codecov

codecov Bot commented Sep 2, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.13%. Comparing base (10c73cb) to head (bddd73d).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...policies/ManagePoliciesPage/ManagePoliciesPage.tsx 0.00% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32507   +/-   ##
=======================================
  Coverage   62.13%   62.13%           
=======================================
  Files        1985     1985           
  Lines      195470   195462    -8     
  Branches     6520     6512    -8     
=======================================
  Hits       121446   121446           
+ Misses      64348    64340    -8     
  Partials     9676     9676           
Flag Coverage Δ
frontend 52.48% <14.28%> (+0.02%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@coderabbitai

coderabbitai Bot commented Sep 2, 2025

Copy link
Copy Markdown
Contributor
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/32061-frontend

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx (2)

754-761: Bug: responses.concat(...) doesn’t mutate; policy updates never enqueued.

The calendar-events policy updates aren’t added to responses, so they’re never awaited/executed.

Apply:

-      // update changed policies calendar events enabled
-      responses.concat(
-        formData.changedPolicies.map((changedPolicy) => {
-          return teamPoliciesAPI.update(changedPolicy.id, {
-            calendar_events_enabled: changedPolicy.calendar_events_enabled,
-            team_id: teamIdForApi,
-          });
-        })
-      );
+      // update changed policies calendar events enabled
+      responses.push(
+        ...formData.changedPolicies.map((changedPolicy) =>
+          teamPoliciesAPI.update(changedPolicy.id, {
+            calendar_events_enabled: changedPolicy.calendar_events_enabled,
+            team_id: teamIdForApi,
+          })
+        )
+      );

821-829: Bug: Same concat issue — conditional access policy updates not enqueued.

responses.concat(...) result is ignored; no policy updates run.

-      // handle any changed policies for no team or a team
-      responses.concat(
-        changedPolicies.map((changedPolicy) => {
-          return teamPoliciesAPI.update(changedPolicy.id, {
-            conditional_access_enabled:
-              changedPolicy.conditional_access_enabled,
-            team_id: teamIdForApi,
-          });
-        })
-      );
+      // handle any changed policies for no team or a team
+      responses.push(
+        ...changedPolicies.map((changedPolicy) =>
+          teamPoliciesAPI.update(changedPolicy.id, {
+            conditional_access_enabled: changedPolicy.conditional_access_enabled,
+            team_id: teamIdForApi,
+          })
+        )
+      );
🧹 Nitpick comments (2)
frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx (2)

525-538: Guard against undefined teamId before teamsAPI.update in “Other workflows”.

Edge-case: if routing glitches leave teamIdForApi undefined while not on All Teams, this would call update with undefined. Add a quick guard.

-      } else {
-        // For any team including "No team" (team ID 0), use the teams API
-        await teamsAPI.update(requestBody, teamIdForApi);
+      } else {
+        // For any team including "No team" (team ID 0), use the teams API
+        if (teamIdForApi === undefined) {
+          renderFlash("error", "No team selected.");
+          return;
+        }
+        await teamsAPI.update(requestBody, teamIdForApi);
       }

666-673: Send updates only for changed policies (avoid unnecessary writes).

You compute changedPolicies above but then issue requests for all formData. Prefer updating just the changed subset to reduce load and noise.

-      const promises = formData.map((changedPolicy) =>
+      const promises = changedPolicies.map((changedPolicy) =>
         teamPoliciesAPI.update(changedPolicy.id, {
           // "script_id": null will unset running a script for the policy
           // "script_id": X will sets script X to run when the policy fails
           script_id: changedPolicy.scriptIdToRun || null,
           team_id: teamIdForApi,
         })
       );
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 10c73cb and bddd73d.

📒 Files selected for processing (2)
  • frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx (7 hunks)
  • frontend/services/entities/teams.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-21T21:10:00.844Z
Learnt from: getvictor
PR: fleetdm/fleet#32129
File: server/service/global_policies.go:398-421
Timestamp: 2025-08-21T21:10:00.844Z
Learning: In Fleet's codebase, there's a distinction between "global policies" and "No team policies": Global policies have TeamID = nil, while "No team" policies have TeamID = 0. This means "No team" policies are treated as belonging to a specific team (team ID 0) rather than being truly global.

Applied to files:

  • frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx
🔇 Additional comments (5)
frontend/services/entities/teams.ts (1)

84-89: Allowing 0 (No team) is correct; validation/readability LGTM.

Good strict check (teamId === undefined || teamId < API_NO_TEAM_ID) and clearer error. This unblocks GET /teams/0 while rejecting negatives.

Please confirm BE PR #32387 returns the expected payload for GET /teams/0 and that downstream consumers handle team.id === 0 without special-casing. Also confirm that keeping addUsers/removeUsers rejecting 0 is intended.

frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx (4)

395-399: Enable team config query for “No team” (0) — LGTM.

Gate now includes 0 via teamIdForApi !== undefined, matching the new teams.load().

QA path: with team_id=0 in URL, verify team config loads and renders automations without 404s once BE #32387 is merged.


958-968: Confirm intent: No team automations use teamConfig, but Conditional Access uses globalConfig for No team.

Elsewhere (lines 1123–1126, 788–818) Conditional Access reads/writes globalConfig when teamId=0. If “No team ≙ team 0” should behave like a regular team (per our prior learning), consider moving CA toggles for No team to teamConfig for consistency, or confirm this exception is deliberate.

Note: Using retrieved learning about “No team = team ID 0” vs global.


1127-1224: Dropdown options refactor — LGTM; “Other” now admin-only (not maintainers).

Paramless helper simplifies call sites. Visibility rule now effectively admins-only given the dropdown itself is limited to maintainers/admins.


1236-1237: Callsite updated to new signature — LGTM.

@getvictor
getvictor marked this pull request as ready for review September 2, 2025 16:21
@getvictor
getvictor requested a review from a team as a code owner September 2, 2025 16:21
@getvictor
getvictor merged commit 808250f into main Sep 2, 2025
15 checks passed
@getvictor
getvictor deleted the victor/32061-frontend branch September 2, 2025 23:02
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.

FE - No team automation

2 participants