feat: skill support auth scope - #2174
Conversation
…d team before toggling
还原本分支误删的 121 行,使 package-lock.json 与 main 保持一致。
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughSkill management now supports team authorization and public/private scope across locale strings, forms, upload and Git import flows, permission-gated actions, and API payloads. Skill resource view components are removed. ChangesSkill authorization
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant SkillSidebar
participant UploadSkillModal
participant SkillAuthFields
participant getTeamInfoList
participant importItem
SkillSidebar->>UploadSkillModal: open upload modal
UploadSkillModal->>SkillAuthFields: render authorization fields
SkillAuthFields->>getTeamInfoList: fetch team options
getTeamInfoList-->>SkillAuthFields: return user groups
UploadSkillModal->>importItem: submit file and authorization values
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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: 1
🧹 Nitpick comments (1)
src/pages/aiConfig/skills/utils/permission.test.ts (1)
4-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider
as constfor test fixture objects.As per coding guidelines, "In test data, prioritize
as constfor type narrowing to prevent string/numeric widening and catch typos in IDE." Addingas constto theadminandalicefixture objects would narrow the literal types and provide IDE-level typo detection.♻️ Optional: add `as const` to fixtures
- const admin = { admin: true, username: 'root' }; - const alice = { admin: false, username: 'alice' }; + const admin = { admin: true, username: 'root' } as const; + const alice = { admin: false, username: 'alice' } as const;🤖 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 `@src/pages/aiConfig/skills/utils/permission.test.ts` around lines 4 - 5, Update the admin and alice test fixture objects in permission.test.ts to use as const, preserving their existing values while narrowing the admin and username properties to literal types.Source: Coding guidelines
🤖 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 `@src/pages/aiConfig/skills/pages/List.tsx`:
- Around line 439-441: Update the onImport callback in List.tsx to return the
promise from handleUpdateImport(selectedSkillData.id, file, auth). Preserve the
existing arguments so UploadSkillModal can await completion and receive upload
failures instead of closing immediately or creating an unhandled rejection.
---
Nitpick comments:
In `@src/pages/aiConfig/skills/utils/permission.test.ts`:
- Around line 4-5: Update the admin and alice test fixture objects in
permission.test.ts to use as const, preserving their existing values while
narrowing the admin and username properties to literal types.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: b4e68a6b-527a-4b75-9a4a-be6fe8098f5d
📒 Files selected for processing (21)
src/pages/aiConfig/skills/locale/en_US.tssrc/pages/aiConfig/skills/locale/ja_JP.tssrc/pages/aiConfig/skills/locale/ru_RU.tssrc/pages/aiConfig/skills/locale/zh_CN.tssrc/pages/aiConfig/skills/locale/zh_HK.tssrc/pages/aiConfig/skills/pages/EditModal.tsxsrc/pages/aiConfig/skills/pages/Form.tsxsrc/pages/aiConfig/skills/pages/GitForm.tsxsrc/pages/aiConfig/skills/pages/GitReplaceConfigModal.tsxsrc/pages/aiConfig/skills/pages/GitUpdateModal.tsxsrc/pages/aiConfig/skills/pages/List.tsxsrc/pages/aiConfig/skills/pages/ResourceModal.tsxsrc/pages/aiConfig/skills/pages/ResourcesTable.tsxsrc/pages/aiConfig/skills/pages/SkillAuthFields.tsxsrc/pages/aiConfig/skills/pages/SkillDetailPanel.tsxsrc/pages/aiConfig/skills/pages/SkillSidebar.tsxsrc/pages/aiConfig/skills/pages/UploadSkillModal.tsxsrc/pages/aiConfig/skills/services.tssrc/pages/aiConfig/skills/types.tssrc/pages/aiConfig/skills/utils/permission.test.tssrc/pages/aiConfig/skills/utils/permission.ts
💤 Files with no reviewable changes (2)
- src/pages/aiConfig/skills/pages/ResourceModal.tsx
- src/pages/aiConfig/skills/pages/ResourcesTable.tsx
| onImport={(file, auth) => { | ||
| handleUpdateImport(selectedSkillData.id, file, auth); | ||
| }} |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
onImport callback doesn't return the promise from handleUpdateImport — modal closes immediately.
The arrow function uses a block body without return, so onImport resolves to undefined. In UploadSkillModal's beforeUpload, await onSubmit(file, auth) resolves immediately and onCancel() fires — the modal closes before the upload completes. If handleUpdateImport fails, its throw _error becomes an unhandled rejection and the user cannot retry without reopening the modal and reselecting the file.
This contrasts with SkillSidebar (L420) and the empty-state modal (L385), where handleImport is passed directly and the promise is correctly awaited.
🐛 Proposed fix
- onImport={(file, auth) => {
- handleUpdateImport(selectedSkillData.id, file, auth);
- }}
+ onImport={(file, auth) => handleUpdateImport(selectedSkillData.id, file, auth)}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| onImport={(file, auth) => { | |
| handleUpdateImport(selectedSkillData.id, file, auth); | |
| }} | |
| onImport={(file, auth) => handleUpdateImport(selectedSkillData.id, file, auth)} |
🤖 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 `@src/pages/aiConfig/skills/pages/List.tsx` around lines 439 - 441, Update the
onImport callback in List.tsx to return the promise from
handleUpdateImport(selectedSkillData.id, file, auth). Preserve the existing
arguments so UploadSkillModal can await completion and receive upload failures
instead of closing immediately or creating an unhandled rejection.
…name to managing teams
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/pages/aiConfig/skills/pages/AddModal.tsx (1)
26-33: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winHandle asynchronous errors and clean up form state.
The form validation and API request lack error handling, which can lead to unhandled promise rejections if validation fails or the network errors out. Additionally, the modal form state is not explicitly cleaned up on unmount or cancellation. As per coding guidelines, async requests must include error handling, and temporary container components must explicitly clean up form data on unmount.
🛠 Proposed fix
- onCancel={onCancel} - onOk={() => { - form.validateFields().then((values) => { - postItem(adjustSubmitValues({ ...values, private: resolveSubmitPrivate(values.private) })).then(() => { - onOk(); - }); - }); - }} + destroyOnClose + onCancel={() => { + form.resetFields(); + onCancel(); + }} + onOk={async () => { + try { + const values = await form.validateFields(); + await postItem(adjustSubmitValues({ ...values, private: resolveSubmitPrivate(values.private) })); + onOk(); + } catch (error) { + console.error(error); + } + }}🤖 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 `@src/pages/aiConfig/skills/pages/AddModal.tsx` around lines 26 - 33, Update the AddModal submit flow around form.validateFields and postItem to handle validation and request failures without unhandled promise rejections, using the component’s established error-handling pattern. Also explicitly reset or destroy the form state when the modal is cancelled and when the component unmounts, using the existing onCancel lifecycle and form instance.Source: Coding guidelines
src/pages/aiConfig/skills/pages/EditModal.tsx (1)
52-62: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winHandle asynchronous errors in form validation and submission.
The form validation and API request lack error handling, which can lead to unhandled promise rejections if validation fails or the request errors out. As per coding guidelines, async requests must include error handling.
🛠 Proposed fix
- onOk={() => { - if (id) { - form.validateFields().then((values) => { - // 非 admin 未挂载「可见范围」字段,validateFields 不含 private;其当前值已由 - // setFieldsValue(data) 存进 form store,用 getFieldValue 取出沿用,避免编辑改变可见性。 - putItem(id, adjustSubmitValues({ ...values, private: resolveSubmitPrivate(values.private, form.getFieldValue('private')) })).then(() => { - onOk(); - }); - }); - } - }} + onOk={async () => { + if (id) { + try { + const values = await form.validateFields(); + // 非 admin 未挂载「可见范围」字段,validateFields 不含 private;其当前值已由 + // setFieldsValue(data) 存进 form store,用 getFieldValue 取出沿用,避免编辑改变可见性。 + await putItem(id, adjustSubmitValues({ ...values, private: resolveSubmitPrivate(values.private, form.getFieldValue('private')) })); + onOk(); + } catch (error) { + console.error(error); + } + } + }}🤖 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 `@src/pages/aiConfig/skills/pages/EditModal.tsx` around lines 52 - 62, Update the onOk handler in EditModal to handle rejections from both form.validateFields() and putItem(), using the existing project error-handling pattern to surface or log failures. Ensure validation errors do not trigger submission or the success callback, and API failures do not leave unhandled promise rejections.Source: Coding guidelines
🧹 Nitpick comments (1)
src/pages/aiConfig/skills/utils/permission.test.ts (1)
4-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNarrow types in test data using
as const.To prevent type widening (e.g., inferring
booleaninstead oftrue) and improve IDE typo detection, useas constwhen defining test data objects. As per coding guidelines, prioritize usingas constin test data to narrow types.🛠 Proposed fix
- const admin = { admin: true, username: 'root' }; - const alice = { admin: false, username: 'alice' }; + const admin = { admin: true, username: 'root' } as const; + const alice = { admin: false, username: 'alice' } as const;🤖 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 `@src/pages/aiConfig/skills/utils/permission.test.ts` around lines 4 - 5, Update the admin and alice test data objects to use as const, preserving their literal property types and improving typo detection without changing the values or surrounding test logic.Source: Coding guidelines
🤖 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.
Outside diff comments:
In `@src/pages/aiConfig/skills/pages/AddModal.tsx`:
- Around line 26-33: Update the AddModal submit flow around form.validateFields
and postItem to handle validation and request failures without unhandled promise
rejections, using the component’s established error-handling pattern. Also
explicitly reset or destroy the form state when the modal is cancelled and when
the component unmounts, using the existing onCancel lifecycle and form instance.
In `@src/pages/aiConfig/skills/pages/EditModal.tsx`:
- Around line 52-62: Update the onOk handler in EditModal to handle rejections
from both form.validateFields() and putItem(), using the existing project
error-handling pattern to surface or log failures. Ensure validation errors do
not trigger submission or the success callback, and API failures do not leave
unhandled promise rejections.
---
Nitpick comments:
In `@src/pages/aiConfig/skills/utils/permission.test.ts`:
- Around line 4-5: Update the admin and alice test data objects to use as const,
preserving their literal property types and improving typo detection without
changing the values or surrounding test logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8948bfee-714f-4edc-b5e9-5ff7358dcb34
📒 Files selected for processing (18)
src/pages/aiConfig/skills/locale/en_US.tssrc/pages/aiConfig/skills/locale/ja_JP.tssrc/pages/aiConfig/skills/locale/ru_RU.tssrc/pages/aiConfig/skills/locale/zh_CN.tssrc/pages/aiConfig/skills/locale/zh_HK.tssrc/pages/aiConfig/skills/pages/AddModal.tsxsrc/pages/aiConfig/skills/pages/EditModal.tsxsrc/pages/aiConfig/skills/pages/Form.tsxsrc/pages/aiConfig/skills/pages/GitInstallModal.tsxsrc/pages/aiConfig/skills/pages/GitReplaceConfigModal.tsxsrc/pages/aiConfig/skills/pages/GitUpdateModal.tsxsrc/pages/aiConfig/skills/pages/List.tsxsrc/pages/aiConfig/skills/pages/SkillAuthFields.tsxsrc/pages/aiConfig/skills/pages/UploadSkillModal.tsxsrc/pages/aiConfig/skills/services.tssrc/pages/aiConfig/skills/types.tssrc/pages/aiConfig/skills/utils/permission.test.tssrc/pages/aiConfig/skills/utils/permission.ts
🚧 Files skipped from review as they are similar to previous changes (10)
- src/pages/aiConfig/skills/locale/zh_CN.ts
- src/pages/aiConfig/skills/types.ts
- src/pages/aiConfig/skills/locale/ja_JP.ts
- src/pages/aiConfig/skills/utils/permission.ts
- src/pages/aiConfig/skills/pages/SkillAuthFields.tsx
- src/pages/aiConfig/skills/pages/GitReplaceConfigModal.tsx
- src/pages/aiConfig/skills/locale/ru_RU.ts
- src/pages/aiConfig/skills/services.ts
- src/pages/aiConfig/skills/pages/UploadSkillModal.tsx
- src/pages/aiConfig/skills/pages/List.tsx
…place flow instead
Form.tsx inlined its own managing-team select + admin-only visibility radio, duplicating SkillAuthFields. Swap the inline block for <SkillAuthFields /> so the team field rules and admin gating live in one place; behavior is unchanged (AddModal/EditModal still fall back via resolveSubmitPrivate for non-admins).
…-teams-fc7805 # Conflicts: # src/pages/aiConfig/skills/pages/ResourcesTable.tsx
| const fieldNames = profile.admin ? ['git_ref_type', 'git_ref', 'user_group_ids', 'private'] : ['git_ref_type', 'git_ref', 'user_group_ids']; | ||
| values = (await form.validateFields(fieldNames)) as Pick<GitInstallPayload, 'git_ref_type' | 'git_ref' | 'user_group_ids' | 'private'>; | ||
| } catch { | ||
| return; |
There was a problem hiding this comment.
catch 得有点动作,哪怕是把错误打印出来,不然上面 try 代码块里出错了,会毫无头绪
validateFields 与 getItem 详情降级的 catch 静默吞错,出问题时毫无排查线索; 按 PR 评论意见统一补 console.error。
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Refactor