MCPcopy Index your code
hub / github.com/simstudioai/sim / getUserEntityPermissions

Function getUserEntityPermissions

apps/sim/lib/workspaces/permissions/utils.ts:197–232  ·  view source on GitHub ↗
(
  userId: string,
  entityType: string,
  entityId: string
)

Source from the content-addressed store, hash-verified

195 * @returns Promise<PermissionType | null> - The highest permission the user has for the entity, or null if none
196 */
197export async function getUserEntityPermissions(
198 userId: string,
199 entityType: string,
200 entityId: string
201): Promise<PermissionType | null> {
202 if (entityType === 'workspace') {
203 const ws = await getWorkspaceWithOwner(entityId)
204 if (!ws) {
205 return null
206 }
207 return getEffectiveWorkspacePermission(userId, ws)
208 }
209
210 const result = await db
211 .select({ permissionType: permissions.permissionType })
212 .from(permissions)
213 .where(
214 and(
215 eq(permissions.userId, userId),
216 eq(permissions.entityType, entityType),
217 eq(permissions.entityId, entityId)
218 )
219 )
220
221 if (result.length === 0) {
222 return null
223 }
224
225 const highestPermission = result.reduce((highest, current) => {
226 return PERMISSION_RANK[current.permissionType] > PERMISSION_RANK[highest.permissionType]
227 ? current
228 : highest
229 })
230
231 return highestPermission.permissionType
232}
233
234/**
235 * Retrieves a list of users with their associated permissions for a given workspace.

Callers 15

hasWriteAccessFunction · 0.90
executeInboxTaskFunction · 0.90
resolveUserIdFunction · 0.90
authorizeCredentialUseFunction · 0.90
utils.test.tsFile · 0.90
resolveBranchFunction · 0.90
handleUnifiedChatPostFunction · 0.90
createKnowledgeBaseFunction · 0.90
updateKnowledgeBaseFunction · 0.90
validateMcpAuthFunction · 0.90
createWorkspaceSSEFunction · 0.90

Calls 3

getWorkspaceWithOwnerFunction · 0.85
eqFunction · 0.50

Tested by

no test coverage detected