UNPKG

@mikezimm/fps-core-v7

Version:

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

118 lines (116 loc) 5.59 kB
/** * CodeAnalizerComment: Updated 2 imports on 2024-09-21 23:07:24 * Update:: import { ISiteUserInfo } to '@mikezimm/fps-core-v7/lib/types/@pnp/@2.14.0/sp/site-users;' * Update:: import { IUser } to '@mikezimm/fps-core-v7/lib/logic/Users/IUserInterfaces;' */ import { checkForLoginName } from "./checkForLoginName"; import { isGuestUser } from "./checkIsGuest"; import { makeAbsoluteUrl } from "../../../logic/Strings/getSiteCollectionUrlFromLink"; /** * createIUsersFromUsersPlural just standardizes the user object so you can for instance pass a Group in and set same property keys as a User * Used in PivotTiles and replaces createISiteUsersInfoObjectD which also does some duplicate error handling as the fps-core-v7 SPHTTPFetch * Call createIUsersFromUsersPlural to map through the array of users or createIUserFromUser for individual user object * * import { createIUsersFromUsersPlural, createIUserFromUser } from '@mikezimm/fps-core-v7/lib/components/atoms/Users/createIUserFromUser'; * @param webUrl * @param resultInfo * @returns */ export function createIUsersFromUsersArray(webUrl, resultInfo) { const newIUsers = []; resultInfo.users.map(user => { const newuser = createIUserFromUser(user, webUrl, null); if (newuser !== null) newIUsers.push(newuser); }); resultInfo.users = newIUsers; return resultInfo; } /** * user MAY need to be cast as any to avoid this error. * casting as unknown or any other type did not work * Argument of type 'ISiteUser' is not assignable to parameter of type 'ISiteUserInfo'. * Type 'ISiteUser' is missing the following properties from type 'ISiteUserInfo': Expiration, IsEmailAuthenticationGuestUser, UserId, UserPrincipalName, and 8 more.ts(2345) * @param user * @param webUrl * @param ForceId * @returns */ export function createIUserFromUser(user, webUrl, ForceId) { var _a, _b; if (!user) return user; // alert('NEED TO FIX createIUserFromUser - Needs to somehow add Group Detail objects.'); // const data = user.data; const data = user; const notes = []; //Add these checks to find at least something based on all the different cases that might come in const userName = checkForLoginName(data); let Title = data.Title; if (!Title && data) { Title = data[`title`] ? data[`title`] : data[`displayName`] ? data[`displayName`] : ''; } if (!Title) notes.push(`Not User Title`); let Email = data.Email; // Choosing NOT to include LoginName in Email at this point since it really isn't the same. if (!Email && data) { Email = data[`email`] ? data[`email`] : ''; } // Added all the 'as' so that it passes linting if (!Email) notes.push(`Not valid Email`); let LoginName = data.LoginName; if (!LoginName && data) { LoginName = data[`loginName`] ? data[`loginName`] : userName ? userName : ''; } // Added all the 'as' so that it passes linting if (!LoginName) notes.push(`Not valid Email or login`); let imageUrl = ''; //Found this in getSiteAdmins response. if (data && ((_a = data[`Picture`]) === null || _a === void 0 ? void 0 : _a['Url'])) imageUrl = (_b = data[`Picture`]) === null || _b === void 0 ? void 0 : _b['Url']; // Added all the 'as' so that it passes linting /** * Changed this from : string to : any because data.Id was a number and was getting forced to a string. * This was causing the default logic in the eval create buttons to fail because the Id value of a user on an item is a number. * I remeber adding this recently for some reason (likely typing was telling me to do it) */ const Id = ForceId ? ForceId : data ? data.Id : 'Not valid User ID'; const IsSiteAdmin = data ? data.IsSiteAdmin : false; const PrincipalType = data ? data.PrincipalType : null; /** * LOOK AT Object Construction to just take original object and add these props to it. * = { ...{Original}, ...{NEW}} */ const thisUser = { ...user, ...{ title: Title, Title: Title, initials: data ? Title.split(" ").map((n) => n[0]).join("") : '-NA-', email: Email, Email: Email, LoginName: LoginName, Name: LoginName, id: Id, Id: Id, ID: Id, UserId: user.UserId ? user.UserId : undefined, isSiteAdmin: IsSiteAdmin, IsSiteAdmin: IsSiteAdmin, isGuest: isGuestUser(user), /** * Added for src\pnpjs\Users\getSiteUsers.ts * Through testing, found that system accounts have a LoginName but NOT UserPrincipalName * So for "real test", I'm using UserPrincipalName to check. */ UserPrincipalName: user.UserPrincipalName ? user.UserPrincipalName : undefined, //These optional props are from the React PeoplePicker control imageInitials: '', imageUrl: imageUrl, loginName: LoginName, text: Title, remoteID: null, ensureWeb: webUrl, // 2022-12-10: Added fullWebUrl just because ensureWeb was not always consistant here fullWebUrl: makeAbsoluteUrl(webUrl), PrincipalType: PrincipalType ? PrincipalType : undefined, } }; return thisUser; } //# sourceMappingURL=createIUserFromUser.js.map