UNPKG

@mikezimm/fps-core-v7

Version:

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

69 lines 3.82 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: getUserWebRoleAssignmentsInBatchD and pnp2: fetchUserWebPermsInBatchesD * * getWebRoleAssignmentsAPI gets all the web's Members and RoleDefinitionBindings combined. * * import { getWebRoleAssignmentsAPI } from '@mikezimm/fps-core-v7/lib/restAPIs/permissions/getWebRoleAssignmentsAPI'; * import { getUserWebRoleAssignmentsInBatchAPI } from '@mikezimm/fps-core-v7/lib/restAPIs/permissions/getUserWebRoleAssignmentsInBatchAPI'; * * NOTE: IT MAY BE MORE EFFECTIVE TO JUST use getWebRoleAssignmentsAPI to get all role assignments instead of piece mealing specific users. * Unless you only need a couple individuals. * * This essentially gives you the same net result object. * * @param fpsSpService * @param webUrl * @param userIds * @param alertMe * @param consoleLog * @returns */ export async function getUserWebRoleAssignmentsInBatchAPI(fpsSpService, webUrl, userIds, alertMe, consoleLog) { const useUrl = makeAbsoluteUrl(webUrl); const hasIds = !userIds || userIds.length === 0 ? false : true; if (!useUrl || hasIds === false) { // NO WebURL... Throw Alert if (alertMe === true) alert(` hasIds: ${hasIds} getGroupInfoAPI: ${SourcePropsNoWebUrl}`); const results = createErrorFpsListReturn(useUrl, ''); results.status = !useUrl ? 'NoWeb' : 'NoUser'; 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`; const webResult = await doSpHttpFetchOrPostAndCheck(fetchAPIWeb, 'GET', fpsSpService, '', alertMe, consoleLog, 'web', false, null); let fetchAPIRoles = `${useUrl}/_api/web/RoleAssignments(userId)?`; fetchAPIRoles += `$expand=Member,RoleDefinitionBindings`; /*** * This little fetchAPI should get an array of items with: * PrinicpalId * Member: [], * RoleDefinitionBindings: */ const AllRoles = await Promise.all(userIds.map((Id, idx) => { return doSpHttpFetchOrPostAndCheck(fetchAPIRoles.replace(`userId`, `${Id}`), 'GET', fpsSpService, '', alertMe, consoleLog, 'roleAssginments', false, null); })); const results = webResult; results.HasUniqueRoleAssignments = webResult['web'].HasUniqueRoleAssignments; results.RoleAssignments = results.items.map((item) => { return item; }); results.item = webResult; results.items = AllRoles; fetchOp = updatePerformanceEndV2({ op: fetchOp, updateMiliseconds: true, count: 1 }); results.fetchOp = fetchOp; if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) { console.log(`fps-core-v7 COMPLETE: getUserWebRoleAssignmentsInBatchAPI ~ 78`, results); } ; return results; } //# sourceMappingURL=getUserWebRoleAssignmentsInBatchAPI.js.map