mikebridge commented on code in PR #41551:
URL: https://github.com/apache/superset/pull/41551#discussion_r3707483258


##########
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:
   *Generated by Claude (AI) on behalf of @mikebridge.*
   
   Sharpening my own reply above, because it glossed a distinction worth being 
precise about: **the file is new in this PR even though the predicate isn't.**
   
   `canOverwriteSlice.ts` doesn't exist on master — it was created by 
`50c08e04e5` on this branch, when the version-history menu turned out to be 
hiding itself from admins. What it contains was lifted from `SaveModal`'s 
inline gate, which is where the missing `can_write` came from. So the accurate 
framing is that this PR *inherited* the gap rather than opened it — my 
"pre-existing" referred to the chart/dashboard asymmetry, not to the file.
   
   The part that genuinely is new code: the predicate now also gates the 
history menu entry, the panel's `?version_history=true` entry and the preview's 
restore control. Those have no prior behaviour to preserve, so it's fair to ask 
whether they should carry the stricter contract. Two reasons I've left them 
as-is:
   
   1. All three are behind `VERSION_HISTORY` (each gates through 
`isFeatureEnabled` plus lazy imports), so nothing here reaches a deployment 
that hasn't opted in.
   2. The restore endpoint enforces server-side regardless — the client 
predicate is an affordance, and its failure direction here is showing an action 
the API then refuses, not permitting one it shouldn't.
   
   Adding `can_write` to the shared helper would also tighten `SaveModal` for 
every deployment, flag or no flag — which is precisely the shape that got the 
`extra_editors` fix pulled out into #42708 rather than shipped inside this PR. 
If the team wants the chart and dashboard contracts aligned, that's the right 
vehicle and I'm happy to file it; I'd just rather not smuggle an unflagged 
permission change into a flagged feature branch, having already been 
(correctly) called out for that once on this PR.



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