codeant-ai-for-open-source[bot] commented on code in PR #41551: URL: https://github.com/apache/superset/pull/41551#discussion_r3707487364
########## 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: ✅ **Customized review instruction saved!** **Instruction:** > Do not add a can_write check to this shared predicate; preserve the current role-based client affordance behavior because version-history is feature-flagged and the server enforces authorization. **Applied to:** - `superset-frontend/src/explore/exploreUtils/canOverwriteSlice.ts` --- 💡 *To manage or update this instruction, visit: [CodeAnt AI Settings](https://app.codeant.ai/org/settings/learnings)* -- 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]
