feat(frontend): add admin UI for Lua MRF policies#36
Conversation
Adds an admin page (/admin/mrf-policies) to manage DB-backed Lua MRF policies: list with enable/priority/built-in status, per-policy editor with a Lua code editor (MkCodeEditor), dynamic params form driven by the policy's paramsSchema, scope editing, warnings, and a dry-run test panel wired to admin/mrf-policies/test. Built-in policies restrict edits to enabled/priority/params (matching the update endpoint guard). On source change the client omits stale params and reseeds from the returned policy; the dry-run test endpoint now filters incompatible params instead of hard-failing so live editing converges. Also describes the test endpoint's decision in its response schema and regenerates misskey-js types and locale typings.
|
Warning Review limit reached
Next review available in: 58 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughAdds an MRF (Message Rewrite Facility) policy management feature: new admin frontend pages for listing/editing/testing/creating/deleting policies, router and menu entries, a backend endpoint change replacing strict param validation with param filtering, generated misskey-js API types for new endpoints, and corresponding locale strings. ChangesMRF Policies feature
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant XPolicy
participant API
participant LuaRuntime
User->>XPolicy: edit draft, click Run Test
XPolicy->>API: admin/mrf-policies/test (source, activity, params)
API->>API: filterCompatibleParams
API->>LuaRuntime: execute policy
LuaRuntime-->>API: decision, warnings
API-->>XPolicy: testResult, paramsSchema
XPolicy->>XPolicy: pruneParams, refresh currentSchema
User->>XPolicy: click Save
XPolicy->>API: admin/mrf-policies/update
API-->>XPolicy: updated policy
XPolicy-->>User: emit updated event
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts (1)
101-101: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRedundant nullish coalescing.
ps.paramsalready defaults to{}viaparamDef.params.default: {}, sops.params ?? {}is dead defensive code (AJV applies the default before the handler runs).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts` at line 101, The `filterCompatibleParams` call in the admin MRF policy test is doing redundant fallback logic because `ps.params` is already defaulted by the schema. Update the `mrfLuaPolicyService.filterCompatibleParams` usage to pass `ps.params` directly and remove the unnecessary nullish coalescing, keeping the change localized to the handler/test code where `paramsSchema` and `ps.params` are used.packages/frontend/src/pages/admin/mrf-policies.policy.vue (1)
73-76: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winNo guard against duplicate Save submissions.
runTest()disables its trigger button viatestingwhile in flight (Line 109), butsave()has no equivalentsavingflag, so rapid double-clicks on Save can fire concurrentadmin/mrf-policies/updaterequests.♻️ Proposed fix
+const saving = ref(false); + async function save() { + if (saving.value) return; + saving.value = true; + try { const sourceChanged = !props.policy.isBuiltin && draft.source !== props.policy.source; ... const updated = await os.apiWithDialog('admin/mrf-policies/update', patch); applyPolicy(updated); emit('updated', updated); + } finally { + saving.value = false; + } }- <MkButton primary inline `@click`="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton> + <MkButton primary inline :disabled="saving" `@click`="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/frontend/src/pages/admin/mrf-policies.policy.vue` around lines 73 - 76, The Save action in mrf-policies.policy.vue can be triggered multiple times because save() has no in-flight guard like runTest() does with testing. Add a saving state in the component, set it while the save request is running, and bind the Save MkButton to that state so rapid clicks cannot fire concurrent admin/mrf-policies/update requests. Update the save() method and the button in the template to use the new saving flag, following the existing runTest()/testing pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts`:
- Around line 99-101: The dry-run path in the admin MRF policy test flow
silently drops incompatible submitted params via
mrfLuaPolicyService.filterCompatibleParams, so add a warning when params are
removed. Update the logic around the paramsSchema/ps.params handling to detect
dropped keys and append a warning into the response’s warnings collection,
alongside metadata.warnings and result.warnings, so admins can see which
submitted values were ignored.
In `@packages/frontend/src/pages/admin/mrf-policies.policy.vue`:
- Around line 168-176: The dynamic policy params in mrf-policies.policy.vue are
being submitted as raw strings for integer/number fields, unlike other numeric
inputs that are normalized with Number(...). Update the form handling around the
draft.params model so numeric entries are coerced to numbers before submission
in both the patch payload and runTest() test payload. Use the existing symbols
draft, patch.params, runTest(), and the paramsSchema-driven MkInput bindings to
locate the conversion point, and ensure only integer/number param types are
converted while non-numeric params remain unchanged.
In `@packages/frontend/src/pages/admin/mrf-policies.vue`:
- Around line 48-50: The refresh flow in refresh() can overwrite newer local
edits with a stale admin/mrf-policies/list response, so guard it with a request
token or abort/cancel mechanism and ignore outdated results. Make sure the
initial load in refresh() and the create/update/delete paths all consult the
same freshness state, or block mutations until the first load settles, so later
edits are not clobbered by an earlier in-flight request.
---
Nitpick comments:
In `@packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts`:
- Line 101: The `filterCompatibleParams` call in the admin MRF policy test is
doing redundant fallback logic because `ps.params` is already defaulted by the
schema. Update the `mrfLuaPolicyService.filterCompatibleParams` usage to pass
`ps.params` directly and remove the unnecessary nullish coalescing, keeping the
change localized to the handler/test code where `paramsSchema` and `ps.params`
are used.
In `@packages/frontend/src/pages/admin/mrf-policies.policy.vue`:
- Around line 73-76: The Save action in mrf-policies.policy.vue can be triggered
multiple times because save() has no in-flight guard like runTest() does with
testing. Add a saving state in the component, set it while the save request is
running, and bind the Save MkButton to that state so rapid clicks cannot fire
concurrent admin/mrf-policies/update requests. Update the save() method and the
button in the template to use the new saving flag, following the existing
runTest()/testing pattern.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bf61100e-7e26-4517-b59a-e5ad7a9ae12f
📒 Files selected for processing (14)
locales/en-US.ymllocales/index.d.tspackages/backend/src/server/api/endpoints/admin/mrf-policies/test.tspackages/frontend/src/pages/admin/index.vuepackages/frontend/src/pages/admin/mrf-policies.policy.vuepackages/frontend/src/pages/admin/mrf-policies.vuepackages/frontend/src/router.definition.tspackages/misskey-js/etc/misskey-js.api.mdpackages/misskey-js/src/autogen/apiClientJSDoc.tspackages/misskey-js/src/autogen/endpoint.tspackages/misskey-js/src/autogen/entities.tspackages/misskey-js/src/autogen/models.tspackages/misskey-js/src/autogen/types.tssharkey-locales/en-US.yml
💤 Files with no reviewable changes (1)
- locales/en-US.yml
The dry-run endpoint silently dropped submitted params that no longer
matched the policy's schema. Emit an incompatible_param_ignored warning
per dropped key so admins can tell the test didn't use their values.
Also drop the redundant 'ps.params ?? {}' fallback (the schema default
already applies).
Claude-Session: https://claude.ai/code/session_01NkWAnRDVKZc2Bgq6szruAj
- Coerce dynamic param values by schema type before submitting to update/test: numeric params through Number(), matching the explicit coercion convention used for priority/timeoutMs, and string_array params edited as comma-separated text (previously the raw array was bound to a text input and edits produced a string the server rejects). - Guard save() with a saving flag and disable the Save button while a request is in flight, mirroring the runTest()/testing pattern. - Guard the policy list against a stale in-flight initial load clobbering newer local state: refresh() only applies the latest request's response, mutations invalidate pending responses, and create() re-syncs from the server. Claude-Session: https://claude.ai/code/session_01NkWAnRDVKZc2Bgq6szruAj
7af3387 to
be67124
Compare
Summary by CodeRabbit