zhoujinsong commented on code in PR #4118:
URL: https://github.com/apache/amoro/pull/4118#discussion_r2993236937


##########
amoro-web/src/utils/permission.ts:
##########
@@ -0,0 +1,106 @@
+/*
+  * 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 useStore from '@/store'
+
+export type UserPrivilege =
+  | 'VIEW_SYSTEM'
+  | 'VIEW_CATALOG'
+  | 'VIEW_TABLE'
+  | 'VIEW_OPTIMIZER'
+  | 'MANAGE_CATALOG'
+  | 'MANAGE_TABLE'
+  | 'MANAGE_OPTIMIZER'
+  | 'EXECUTE_SQL'
+  | 'MANAGE_PLATFORM'
+
+export function getRoles(): string[] {
+  const store = useStore()
+  const roles = store.userInfo.roles || []
+  if (roles.length) {
+    return roles
+  }
+  return store.userInfo.role ? [store.userInfo.role] : []
+}
+
+export function getPrivileges(): UserPrivilege[] {
+  const store = useStore()
+  return (store.userInfo.privileges || []) as UserPrivilege[]
+}

Review Comment:
   **[Minor] `hasPrivilege` returns `true` for all paths when authorization is 
disabled**
   
   When RBAC is disabled the backend sets every user's privileges to the full 
`Privilege` enum set, so `hasPrivilege` will always return `true`. This is 
correct, but it means the frontend permission model silently relies on backend 
behaviour. If a future refactor changes the disabled-mode response, all 
frontend guards will break without a clear indication why. Consider adding a 
comment here explaining the contract: _"When authorization is disabled, the 
backend returns all privileges."_



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

Reply via email to