codeant-ai-for-open-source[bot] commented on code in PR #32995:
URL: https://github.com/apache/superset/pull/32995#discussion_r3485731255


##########
superset-frontend/src/pages/DashboardList/index.tsx:
##########
@@ -454,6 +455,11 @@ function DashboardList(props: DashboardListProps) {
       },
       {
         Cell: ({ row: { original } }: any) => {
+          // Verify owner or isAdmin
+          const allowEdit: boolean =
+            original.owners.map((o: Owner) => o.id).includes(user.userId) ||
+            isUserAdmin(user);
+

Review Comment:
   **Suggestion:** The new permission gate compares owner IDs to `user.userId` 
without type coercion, but `userId` is typed as `string | number`. If it 
arrives as a string, owners will be treated as non-owners and edit/delete 
actions will be wrongly disabled. Cast to a numeric id before `includes` to 
match owner id type. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Dashboard owners blocked from editing dashboards they own.
   - ⚠️ Delete actions disabled incorrectly for authorized dashboard owners.
   - ⚠️ Inconsistent owner checks across dashboards and datasets lists.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In the dashboard list tests at
   `superset-frontend/src/pages/DashboardList/DashboardList.listview.test.tsx`, 
change
   `mockUser.userId` (lines 52-62) from numeric `1` to the string `'1'`, 
preserving `roles`
   that grant `['can_write', 'Dashboard']` so the user has write permissions.
   
   2. Confirm the mock dashboards include an owner with numeric id `1`, using
   `mockDashboards` from
   `superset-frontend/src/pages/DashboardList/DashboardList.testHelpers.tsx` 
where several
   entries have `owners: [{ id: 1, ... }]` (e.g., lines 39-55), ensuring the 
rendered row
   represents a dashboard owned by the current user.
   
   3. Render the Dashboard list via `renderDashboardList(mockUser)` in
   `DashboardList.testHelpers.tsx` (lines 247-269), or open the dashboards list 
route
   `/superset/dashboard/list` backed by `RoutePaths.DASHBOARD_LIST` in
   `superset-frontend/src/views/routes.tsx` (lines 167-168); during rendering, 
the Actions
   column cell in `DashboardList/index.tsx` computes `allowEdit` at lines 
457-462 using
   `original.owners.map((o: Owner) => o.id).includes(user.userId)`, comparing 
numeric owner
   ids against a string `userId`.
   
   4. Inspect the Actions column for a dashboard the user owns and observe that 
`allowEdit`
   is `false` (string vs number mismatch), causing the edit/delete spans to 
receive the
   `"disabled"` class and only wire `onClick` when `allowEdit` is true (lines 
487-493 and
   538-543 in `DashboardList/index.tsx`); as a result, an owner with write 
permissions cannot
   trigger edit or delete from the list while dataset list uses 
`Number(user.userId)` (lines
   863-867 in `DatasetList/index.tsx`) to avoid this bug.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=43a96f5588f34c37a857c90044a3da27&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=43a96f5588f34c37a857c90044a3da27&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/pages/DashboardList/index.tsx
   **Line:** 460:462
   **Comment:**
        *Type Error: The new permission gate compares owner IDs to 
`user.userId` without type coercion, but `userId` is typed as `string | 
number`. If it arrives as a string, owners will be treated as non-owners and 
edit/delete actions will be wrongly disabled. Cast to a numeric id before 
`includes` to match owner id type.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32995&comment_hash=41950ff0ad44474b1b8dd35d71dc10bf913139872479f99a66c6b74075a6a8e7&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32995&comment_hash=41950ff0ad44474b1b8dd35d71dc10bf913139872479f99a66c6b74075a6a8e7&reaction=dislike'>👎</a>



##########
superset-frontend/src/pages/ChartList/index.tsx:
##########
@@ -501,6 +500,11 @@ function ChartList(props: ChartListProps) {
       },
       {
         Cell: ({ row: { original } }: any) => {
+          // Verify owner or isAdmin
+          const allowEdit: boolean =
+            original.owners.map((o: Owner) => o.id).includes(user.userId) ||
+            isUserAdmin(user);

Review Comment:
   **Suggestion:** The owner check compares numeric owner IDs against 
`user.userId` without normalizing type. Since this prop is declared as `string 
| number`, a string user id (e.g. from bootstrap payloads) will fail `includes` 
even for real owners, incorrectly disabling edit/delete. Normalize 
`user.userId` to a number (as done in DatasetList) before comparing. [type 
error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Chart owners blocked from editing charts in list view.
   - ⚠️ Delete buttons disabled despite server allowing operation.
   - ⚠️ Confusing permission messaging for legitimate chart owners.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Use the Chart list tests at
   `superset-frontend/src/pages/ChartList/ChartList.listview.test.tsx` and 
modify `mockUser`
   (lines 50-62) so `userId` is the string `'1'` instead of the number `1`, 
keeping `roles`
   with `['can_write', 'Chart']` permissions.
   
   2. Ensure at least one chart row is owned by user id `1`, using the existing 
mock data in
   `superset-frontend/src/pages/ChartList/ChartList.testHelpers.tsx` where
   `mockCharts[0].owners` includes `{ id: 1, ... }` (lines 40-54), giving a 
numeric owner id.
   
   3. Render the Chart list via `renderChartList(mockUser)` in 
`ChartList.testHelpers.tsx`
   (lines 260-274), or navigate to the charts list route `/chart/list` wired in
   `superset-frontend/src/views/routes.tsx` (lines 169-171); during render, the 
Actions
   column cell in `ChartList/index.tsx` computes `allowEdit` at lines 503-506 
by calling
   `original.owners.map((o: Owner) => o.id).includes(user.userId)`, comparing 
numeric owner
   ids against a string `userId`.
   
   4. Observe that for the chart owned by id `1`, `allowEdit` is `false` because
   `includes('1')` on a `number[]` fails; the UI applies the `"disabled"` CSS 
class and omits
   the `onClick` handler for edit/delete spans (lines 535-541 and 587-591 in
   `ChartList/index.tsx`), so a legitimate owner with write permission cannot 
edit or delete
   from the list.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2ea30c59b678469c92c8dd764f866505&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2ea30c59b678469c92c8dd764f866505&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/pages/ChartList/index.tsx
   **Line:** 504:506
   **Comment:**
        *Type Error: The owner check compares numeric owner IDs against 
`user.userId` without normalizing type. Since this prop is declared as `string 
| number`, a string user id (e.g. from bootstrap payloads) will fail `includes` 
even for real owners, incorrectly disabling edit/delete. Normalize 
`user.userId` to a number (as done in DatasetList) before comparing.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32995&comment_hash=a43cbaacbe940db3d4382635a451a905ab2bdb890eb9d49f95ebe9e0b854f102&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32995&comment_hash=a43cbaacbe940db3d4382635a451a905ab2bdb890eb9d49f95ebe9e0b854f102&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to