UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

64 lines 3.15 kB
import { check4This, Check4 } from "../../logic/Links/CheckSearch"; import { doSpHttpFetchOrPostAndCheck } from "../../components/molecules/SpHttp/Sp/doSpHttpFetch"; import { SourcePropsNoWebUrl } from "../../components/molecules/source-props/ISourceProps"; import { makeAbsoluteUrl } from "../../logic/Strings/getSiteCollectionUrlFromLink"; import { createErrorFpsListReturn } from "../../components/molecules/process-results/createErrorFpsListItemsReturn"; import { startPerformOpV2, updatePerformanceEndV2 } from "../../components/molecules/Performance/functions"; /** * 2025-01-03: Migrated from fps-library-v2/lib/pnpjs/Permissions, pnp2/lib/services/sp/perms * combination of v2: getUserWebRoleAssignmentsD and pnp2: fetchUserWebPermsD * * getUserWebRoleAssignmentsAPI gets web's Members and RoleDefinitionBindings combined . * * import { getUserWebRoleAssignmentsAPI } from '@mikezimm/fps-core-v7/lib/restAPIs/permissions/getUserWebRoleAssignmentsAPI'; * * @param fpsSpService * @param webUrl * @param userId * @param alertMe * @param consoleLog * @returns */ export async function getUserWebRoleAssignmentsAPI(fpsSpService, webUrl, userId, alertMe, consoleLog) { const useUrl = makeAbsoluteUrl(webUrl); if (!useUrl) { // NO WebURL... Throw Alert if (alertMe === true) alert(`getUserListRoleAssignmentsAPI: ${SourcePropsNoWebUrl}`); const results = createErrorFpsListReturn(useUrl, ''); results.status = 'NoWeb'; results.HasUniqueRoleAssignments = false; results.RoleAssignments = []; return results; } const performanceSettings = { label: 'FetchCheck', includeMsStr: true, updateMiliseconds: true, op: 'fetch' }; let fetchOp = startPerformOpV2(performanceSettings); const baseFetchAPI = `${useUrl}/_api/web`; let fetchAPIWeb = `${baseFetchAPI}?`; fetchAPIWeb += `$select=Title,ServerRelativeUrl,Id,HasUniqueRoleAssignments`; let fetchAPIRoles = `${baseFetchAPI}/RoleAssignments(${userId})?`; fetchAPIRoles += `$expand=Member,RoleDefinitionBindings`; /*** * This little fetchAPI should get an array of items with: * PrinicpalId * Member: [], * RoleDefinitionBindings: */ const [web, roles,] = await Promise.all([ doSpHttpFetchOrPostAndCheck(fetchAPIWeb, 'GET', fpsSpService, '', alertMe, consoleLog, 'web', false, null), doSpHttpFetchOrPostAndCheck(fetchAPIRoles, 'GET', fpsSpService, '', alertMe, consoleLog, 'roles', false, null), ]); const results = web; results.HasUniqueRoleAssignments = web.item.HasUniqueRoleAssignments; results.RoleAssignments = roles.items; results.item = web; results.items = roles; fetchOp = updatePerformanceEndV2({ op: fetchOp, updateMiliseconds: true, count: 1 }); results.fetchOp = fetchOp; if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) { console.log(`fps-core-v7 COMPLETE: getUserListRoleAssignmentsAPI ~ 65`, results); } ; return results; } //# sourceMappingURL=getUserWebRoleAssignmentsAPI.js.map