MCPcopy Create free account
hub / github.com/bytebase/bytebase / checkProjectIAMPolicyWithExpr

Function checkProjectIAMPolicyWithExpr

frontend/src/utils/v1/iam.ts:221–250  ·  view source on GitHub ↗
(
  user: User,
  project: Project,
  requiredPermissions: QueryPermission[],
  bindingExprCheck: (expr?: Expr) => boolean
)

Source from the content-addressed store, hash-verified

219// policy + roles) via the util bridge — relocated from the deleted Pinia
220// `projectIamPolicy` store, whose data was never populated in the React shell.
221const checkProjectIAMPolicyWithExpr = (
222 user: User,
223 project: Project,
224 requiredPermissions: QueryPermission[],
225 bindingExprCheck: (expr?: Expr) => boolean
226): boolean => {
227 const policy = appStoreUtilBridge()?.getProjectIamPolicy(project.name);
228 if (!policy) {
229 return false;
230 }
231 for (const binding of policy.bindings) {
232 const nameList = getUserListInBinding({ binding, ignoreGroup: false });
233 if (
234 !nameList.includes(getUserFullNameByType(user)) &&
235 !nameList.includes(`${userNamePrefix}${ALL_USERS_USER_EMAIL}`)
236 ) {
237 continue;
238 }
239 const permissions =
240 appStoreUtilBridge()?.getRoleByName(binding.role)?.permissions || [];
241 for (const permission of permissions) {
242 if (requiredPermissions.includes(permission as QueryPermission)) {
243 if (bindingExprCheck(binding.parsedExpr)) {
244 return true;
245 }
246 }
247 }
248 }
249 return false;
250};
251
252export const checkQuerierPermission = (
253 database: Database,

Callers 1

checkQuerierPermissionFunction · 0.85

Calls 4

appStoreUtilBridgeFunction · 0.90
getUserFullNameByTypeFunction · 0.90
getUserListInBindingFunction · 0.85
getProjectIamPolicyMethod · 0.80

Tested by

no test coverage detected