UNPKG

@mikezimm/fps-core-v7

Version:

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

64 lines 3.44 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: getUserListRoleAssignmentsD and pnp2: fetchUserListPermsD * * getUserListRoleAssignmentsAPI gets web's Members and RoleDefinitionBindings combined. * * import { getUserListRoleAssignmentsAPI } from '@mikezimm/fps-core-v7/lib/restAPIs/permissions/getUserListRoleAssignmentsAPI'; * * @param fpsSpService * @param webUrl * @param listTitle * @param userIds * @param alertMe * @param consoleLog * @returns */ export async function getUserListRoleAssignmentsAPI(fpsSpService, webUrl, listTitle, userIds, alertMe, consoleLog) { const useUrl = makeAbsoluteUrl(webUrl); if (!useUrl || !listTitle) { // 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/lists/getByTitle('${listTitle}')`; let fetchAPIList = `${baseFetchAPI}?`; fetchAPIList += `$select=Title,ServerRelativeUrl,Id,HasUniqueRoleAssignments`; const listResult = await doSpHttpFetchOrPostAndCheck(fetchAPIList, 'GET', fpsSpService, '', alertMe, consoleLog, 'list', false, null); let fetchAPIRoles = `${baseFetchAPI}/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 = listResult; results.HasUniqueRoleAssignments = listResult.item.HasUniqueRoleAssignments; results.RoleAssignments = results.items.map((item) => { return item; }); results.item = listResult; results.items = AllRoles; results['list'] = listResult.item ? listResult.item : listResult['list']; 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=getUserListRoleAssignmentsAPI.js.map