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


##########
superset-frontend/src/explore/exploreUtils/canOverwriteSlice.ts:
##########
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  isUserAdmin,
+  isUserInSubjects,
+  type SubjectRef,
+} from 'src/dashboard/util/permissionUtils';
+import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
+
+interface SliceLike {
+  editors?: SubjectRef[] | null;
+  extra_editors?: SubjectRef[] | null;
+  is_managed_externally?: boolean | null;
+}
+
+/**
+ * Whether *user* may modify *slice*, in the sense that governs both saving
+ * over a chart and acting on its version history.
+ *
+ * `canOverwrite` is the value the explore store holds, which `hydrateExplore`
+ * computes purely as "the current user is among the slice's editors". That is
+ * necessary but not sufficient: a chart with no explicit editors — which
+ * includes every seeded and example chart — yields false for everyone,
+ * administrators included. So the store value is treated as one of several
+ * routes to permission rather than the whole answer.
+ *
+ * Externally managed slices are excluded: their source of truth lives outside
+ * Superset, so overwriting or reverting one would be overwritten again by the
+ * next sync.
+ */
+export function canOverwriteSlice({
+  slice,
+  user,
+  canOverwrite = false,
+}: {
+  slice?: SliceLike | null;
+  user?: UserWithPermissionsAndRoles;
+  canOverwrite?: boolean;
+}): boolean {
+  if (!slice || slice.is_managed_externally) {
+    return false;
+  }
+  if (canOverwrite || isUserAdmin(user)) {
+    return true;
+  }

Review Comment:
   **Suggestion:** The new permission path grants overwrite and restore actions 
to every admin or editor without checking the required `can_write` permission. 
The existing dashboard permission contract explicitly requires `can_write` 
before allowing either admin or editor status, so users with an Admin role but 
no write permission will see actions that the API rejects. Include the relevant 
write-permission check in this shared predicate rather than treating role 
membership alone as sufficient. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Unauthorized users see overwrite and restore affordances.
   - ⚠️ Chart saves fail with permission errors after interaction.
   - ⚠️ Version-history actions disagree with server authorization.
   ```
   </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=b2ff8a74a3634074a250108776291388&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=b2ff8a74a3634074a250108776291388&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/explore/exploreUtils/canOverwriteSlice.ts
   **Line:** 59:61
   **Comment:**
        *Api Mismatch: The new permission path grants overwrite and restore 
actions to every admin or editor without checking the required `can_write` 
permission. The existing dashboard permission contract explicitly requires 
`can_write` before allowing either admin or editor status, so users with an 
Admin role but no write permission will see actions that the API rejects. 
Include the relevant write-permission check in this shared predicate rather 
than treating role membership alone as sufficient.
   
   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%2F41551&comment_hash=afe1290d678edea77127a00f3af38ff6b946f310d25ddb49e3276e9325393f74&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41551&comment_hash=afe1290d678edea77127a00f3af38ff6b946f310d25ddb49e3276e9325393f74&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