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

Function memberMapToRolesInProjectIAM

frontend/src/utils/v1/iam.ts:148–195  ·  view source on GitHub ↗
(
  iamPolicy: IamPolicy,
  targetRole?: string,
  getGroupByIdentifier?: (identifier: string) => Group | undefined
)

Source from the content-addressed store, hash-verified

146// memberMapToRolesInProjectIAM return the Map<users/{email}, Set<roles/{role}>>
147// the user could includes users/ALL_USERS_USER_EMAIL
148export const memberMapToRolesInProjectIAM = (
149 iamPolicy: IamPolicy,
150 targetRole?: string,
151 getGroupByIdentifier?: (identifier: string) => Group | undefined
152): Map<string, Set<string>> => {
153 // Map<userfullname, Set<roles/{role}>>
154 const rolesMapByName = new Map<string, Set<string>>();
155
156 // Handle project level roles.
157 for (const binding of iamPolicy.bindings) {
158 if (targetRole && binding.role !== targetRole) {
159 continue;
160 }
161 if (isBindingPolicyExpired(binding)) {
162 continue;
163 }
164
165 const fullnames = getUserListInBinding({
166 binding,
167 ignoreGroup: false,
168 getGroupByIdentifier,
169 });
170 for (const fullname of fullnames) {
171 if (!rolesMapByName.has(fullname)) {
172 rolesMapByName.set(fullname, new Set());
173 }
174 rolesMapByName.get(fullname)?.add(binding.role);
175 }
176 }
177
178 // Handle workspace level project roles.
179 const roleMapToUsers =
180 appStoreUtilBridge()?.workspaceRoleMapToUsers() ??
181 new Map<string, Set<string>>();
182 for (const [role, userSet] of roleMapToUsers.entries()) {
183 if (targetRole && role !== targetRole) {
184 continue;
185 }
186 for (const user of userSet.values()) {
187 if (!rolesMapByName.has(user)) {
188 rolesMapByName.set(user, new Set());
189 }
190 rolesMapByName.get(user)?.add(role);
191 }
192 }
193
194 return rolesMapByName;
195};
196
197export const filterBindingsByUserName = ({
198 policy,

Callers 4

useApprovalStepFunction · 0.90
candidatesForRolesFunction · 0.90
canRolloutTasksFunction · 0.90
useApprovalCandidatesFunction · 0.90

Calls 6

appStoreUtilBridgeFunction · 0.90
isBindingPolicyExpiredFunction · 0.85
getUserListInBindingFunction · 0.85
addMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected