@kwiz/common 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/_dependencies.d.ts +1 -0
- package/dist/_dependencies.js +8 -0
- package/dist/_dependencies.js.map +1 -0
- package/dist/helpers/Guid.d.ts +119 -0
- package/dist/helpers/Guid.js +183 -0
- package/dist/helpers/Guid.js.map +1 -0
- package/dist/helpers/_dependencies.d.ts +2 -0
- package/dist/helpers/_dependencies.js +21 -0
- package/dist/helpers/_dependencies.js.map +1 -0
- package/dist/helpers/base64.d.ts +8 -0
- package/dist/helpers/base64.js +178 -0
- package/dist/helpers/base64.js.map +1 -0
- package/dist/helpers/browser.d.ts +144 -0
- package/dist/helpers/browser.js +1200 -0
- package/dist/helpers/browser.js.map +1 -0
- package/dist/helpers/browserinfo.d.ts +23 -0
- package/dist/helpers/browserinfo.js +215 -0
- package/dist/helpers/browserinfo.js.map +1 -0
- package/dist/helpers/collections.base.d.ts +128 -0
- package/dist/helpers/collections.base.js +430 -0
- package/dist/helpers/collections.base.js.map +1 -0
- package/dist/helpers/collections.d.ts +18 -0
- package/dist/helpers/collections.js +99 -0
- package/dist/helpers/collections.js.map +1 -0
- package/dist/helpers/color.d.ts +11 -0
- package/dist/helpers/color.js +57 -0
- package/dist/helpers/color.js.map +1 -0
- package/dist/helpers/cookies.d.ts +6 -0
- package/dist/helpers/cookies.js +56 -0
- package/dist/helpers/cookies.js.map +1 -0
- package/dist/helpers/date.d.ts +43 -0
- package/dist/helpers/date.js +158 -0
- package/dist/helpers/date.js.map +1 -0
- package/dist/helpers/debug.d.ts +33 -0
- package/dist/helpers/debug.js +177 -0
- package/dist/helpers/debug.js.map +1 -0
- package/dist/helpers/emails.d.ts +2 -0
- package/dist/helpers/emails.js +10 -0
- package/dist/helpers/emails.js.map +1 -0
- package/dist/helpers/eval.d.ts +1 -0
- package/dist/helpers/eval.js +10 -0
- package/dist/helpers/eval.js.map +1 -0
- package/dist/helpers/file.d.ts +11 -0
- package/dist/helpers/file.js +55 -0
- package/dist/helpers/file.js.map +1 -0
- package/dist/helpers/flatted.d.ts +20 -0
- package/dist/helpers/flatted.js +135 -0
- package/dist/helpers/flatted.js.map +1 -0
- package/dist/helpers/functions.d.ts +4 -0
- package/dist/helpers/functions.js +17 -0
- package/dist/helpers/functions.js.map +1 -0
- package/dist/helpers/graph/calendar.types.d.ts +3 -0
- package/dist/helpers/graph/calendar.types.js +15 -0
- package/dist/helpers/graph/calendar.types.js.map +1 -0
- package/dist/helpers/http.d.ts +25 -0
- package/dist/helpers/http.js +70 -0
- package/dist/helpers/http.js.map +1 -0
- package/dist/helpers/images.d.ts +16 -0
- package/dist/helpers/images.js +21 -0
- package/dist/helpers/images.js.map +1 -0
- package/dist/helpers/index.d.ts +29 -0
- package/dist/helpers/index.js +46 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/json.d.ts +3 -0
- package/dist/helpers/json.js +44 -0
- package/dist/helpers/json.js.map +1 -0
- package/dist/helpers/md5.d.ts +5 -0
- package/dist/helpers/md5.js +172 -0
- package/dist/helpers/md5.js.map +1 -0
- package/dist/helpers/objects.d.ts +49 -0
- package/dist/helpers/objects.js +271 -0
- package/dist/helpers/objects.js.map +1 -0
- package/dist/helpers/promises.d.ts +14 -0
- package/dist/helpers/promises.js +112 -0
- package/dist/helpers/promises.js.map +1 -0
- package/dist/helpers/random.d.ts +2 -0
- package/dist/helpers/random.js +32 -0
- package/dist/helpers/random.js.map +1 -0
- package/dist/helpers/scheduler/scheduler.d.ts +39 -0
- package/dist/helpers/scheduler/scheduler.js +109 -0
- package/dist/helpers/scheduler/scheduler.js.map +1 -0
- package/dist/helpers/sharepoint.d.ts +112 -0
- package/dist/helpers/sharepoint.js +629 -0
- package/dist/helpers/sharepoint.js.map +1 -0
- package/dist/helpers/strings.d.ts +56 -0
- package/dist/helpers/strings.js +282 -0
- package/dist/helpers/strings.js.map +1 -0
- package/dist/helpers/typecheckers.d.ts +56 -0
- package/dist/helpers/typecheckers.js +274 -0
- package/dist/helpers/typecheckers.js.map +1 -0
- package/dist/helpers/url.d.ts +46 -0
- package/dist/helpers/url.js +199 -0
- package/dist/helpers/url.js.map +1 -0
- package/dist/helpers/urlhelper.d.ts +16 -0
- package/dist/helpers/urlhelper.js +96 -0
- package/dist/helpers/urlhelper.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/types/common.types.d.ts +19 -0
- package/dist/types/common.types.js +4 -0
- package/dist/types/common.types.js.map +1 -0
- package/dist/types/flatted.types.d.ts +49 -0
- package/dist/types/flatted.types.js +3 -0
- package/dist/types/flatted.types.js.map +1 -0
- package/dist/types/globals.types.d.ts +6 -0
- package/dist/types/globals.types.js +3 -0
- package/dist/types/globals.types.js.map +1 -0
- package/dist/types/graph/calendar.types.d.ts +79 -0
- package/dist/types/graph/calendar.types.js +3 -0
- package/dist/types/graph/calendar.types.js.map +1 -0
- package/dist/types/graph/index.d.ts +1 -0
- package/dist/types/graph/index.js +18 -0
- package/dist/types/graph/index.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +28 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/knownscript.types.d.ts +22 -0
- package/dist/types/knownscript.types.js +3 -0
- package/dist/types/knownscript.types.js.map +1 -0
- package/dist/types/libs/datajs.types.d.ts +29 -0
- package/dist/types/libs/datajs.types.js +3 -0
- package/dist/types/libs/datajs.types.js.map +1 -0
- package/dist/types/libs/ics.types.d.ts +29 -0
- package/dist/types/libs/ics.types.js +3 -0
- package/dist/types/libs/ics.types.js.map +1 -0
- package/dist/types/libs/index.d.ts +3 -0
- package/dist/types/libs/index.js +20 -0
- package/dist/types/libs/index.js.map +1 -0
- package/dist/types/libs/msal.types.d.ts +33 -0
- package/dist/types/libs/msal.types.js +63 -0
- package/dist/types/libs/msal.types.js.map +1 -0
- package/dist/types/locales.d.ts +122 -0
- package/dist/types/locales.js +1 -0
- package/dist/types/locales.js.map +1 -0
- package/dist/types/localstoragecache.types.d.ts +8 -0
- package/dist/types/localstoragecache.types.js +3 -0
- package/dist/types/localstoragecache.types.js.map +1 -0
- package/dist/types/moment.d.ts +6 -0
- package/dist/types/moment.js +1 -0
- package/dist/types/moment.js.map +1 -0
- package/dist/types/regex.types.d.ts +14 -0
- package/dist/types/regex.types.js +3 -0
- package/dist/types/regex.types.js.map +1 -0
- package/dist/types/rest.types.d.ts +81 -0
- package/dist/types/rest.types.js +24 -0
- package/dist/types/rest.types.js.map +1 -0
- package/dist/types/sharepoint.types.d.ts +1432 -0
- package/dist/types/sharepoint.types.js +629 -0
- package/dist/types/sharepoint.types.js.map +1 -0
- package/dist/types/sharepoint.utils.types.d.ts +246 -0
- package/dist/types/sharepoint.utils.types.js +26 -0
- package/dist/types/sharepoint.utils.types.js.map +1 -0
- package/dist/utils/_dependencies.d.ts +3 -0
- package/dist/utils/_dependencies.js +24 -0
- package/dist/utils/_dependencies.js.map +1 -0
- package/dist/utils/base64.d.ts +2 -0
- package/dist/utils/base64.js +41 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/consolelogger.d.ts +73 -0
- package/dist/utils/consolelogger.js +281 -0
- package/dist/utils/consolelogger.js.map +1 -0
- package/dist/utils/date.d.ts +10 -0
- package/dist/utils/date.js +30 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/emails.d.ts +2 -0
- package/dist/utils/emails.js +24 -0
- package/dist/utils/emails.js.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/knownscript.d.ts +99 -0
- package/dist/utils/knownscript.js +261 -0
- package/dist/utils/knownscript.js.map +1 -0
- package/dist/utils/localstoragecache.d.ts +19 -0
- package/dist/utils/localstoragecache.js +372 -0
- package/dist/utils/localstoragecache.js.map +1 -0
- package/dist/utils/rest.d.ts +17 -0
- package/dist/utils/rest.js +402 -0
- package/dist/utils/rest.js.map +1 -0
- package/dist/utils/script.d.ts +33 -0
- package/dist/utils/script.js +169 -0
- package/dist/utils/script.js.map +1 -0
- package/dist/utils/sharepoint.rest/common.d.ts +32 -0
- package/dist/utils/sharepoint.rest/common.js +146 -0
- package/dist/utils/sharepoint.rest/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/date.d.ts +2 -0
- package/dist/utils/sharepoint.rest/date.js +57 -0
- package/dist/utils/sharepoint.rest/date.js.map +1 -0
- package/dist/utils/sharepoint.rest/file.folder.d.ts +58 -0
- package/dist/utils/sharepoint.rest/file.folder.js +305 -0
- package/dist/utils/sharepoint.rest/file.folder.js.map +1 -0
- package/dist/utils/sharepoint.rest/index.d.ts +11 -0
- package/dist/utils/sharepoint.rest/index.js +28 -0
- package/dist/utils/sharepoint.rest/index.js.map +1 -0
- package/dist/utils/sharepoint.rest/item.d.ts +81 -0
- package/dist/utils/sharepoint.rest/item.js +444 -0
- package/dist/utils/sharepoint.rest/item.js.map +1 -0
- package/dist/utils/sharepoint.rest/list.d.ts +228 -0
- package/dist/utils/sharepoint.rest/list.js +868 -0
- package/dist/utils/sharepoint.rest/list.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.d.ts +19 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +629 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.d.ts +14 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +222 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/common.d.ts +3 -0
- package/dist/utils/sharepoint.rest/listutils/common.js +198 -0
- package/dist/utils/sharepoint.rest/listutils/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/user-search.d.ts +76 -0
- package/dist/utils/sharepoint.rest/user-search.js +239 -0
- package/dist/utils/sharepoint.rest/user-search.js.map +1 -0
- package/dist/utils/sharepoint.rest/user.d.ts +71 -0
- package/dist/utils/sharepoint.rest/user.js +404 -0
- package/dist/utils/sharepoint.rest/user.js.map +1 -0
- package/dist/utils/sharepoint.rest/web.d.ts +107 -0
- package/dist/utils/sharepoint.rest/web.js +929 -0
- package/dist/utils/sharepoint.rest/web.js.map +1 -0
- package/dist/utils/sod.d.ts +29 -0
- package/dist/utils/sod.js +177 -0
- package/dist/utils/sod.js.map +1 -0
- package/package.json +60 -0
- package/readme.md +13 -0
- package/src/_dependencies.ts +2 -0
- package/src/helpers/Guid.ts +182 -0
- package/src/helpers/_dependencies.ts +3 -0
- package/src/helpers/base64.ts +174 -0
- package/src/helpers/browser.test.js +9 -0
- package/src/helpers/browser.ts +1299 -0
- package/src/helpers/browserinfo.ts +293 -0
- package/src/helpers/collections.base.test.js +26 -0
- package/src/helpers/collections.base.ts +439 -0
- package/src/helpers/collections.ts +108 -0
- package/src/helpers/color.ts +55 -0
- package/src/helpers/cookies.ts +55 -0
- package/src/helpers/date.test.js +97 -0
- package/src/helpers/date.ts +163 -0
- package/src/helpers/debug.ts +187 -0
- package/src/helpers/emails.ts +7 -0
- package/src/helpers/eval.ts +5 -0
- package/src/helpers/file.test.js +51 -0
- package/src/helpers/file.ts +59 -0
- package/src/helpers/flatted.ts +150 -0
- package/src/helpers/functions.ts +17 -0
- package/src/helpers/graph/calendar.types.ts +11 -0
- package/src/helpers/http.ts +70 -0
- package/src/helpers/images.ts +23 -0
- package/src/helpers/index.ts +29 -0
- package/src/helpers/json.ts +39 -0
- package/src/helpers/md5.ts +190 -0
- package/src/helpers/objects.test.js +27 -0
- package/src/helpers/objects.ts +256 -0
- package/src/helpers/promises.test.js +18 -0
- package/src/helpers/promises.ts +102 -0
- package/src/helpers/random.ts +27 -0
- package/src/helpers/scheduler/scheduler.test.js +104 -0
- package/src/helpers/scheduler/scheduler.ts +132 -0
- package/src/helpers/sharepoint.ts +681 -0
- package/src/helpers/strings.test.js +43 -0
- package/src/helpers/strings.ts +288 -0
- package/src/helpers/typecheckers.test.js +35 -0
- package/src/helpers/typecheckers.ts +263 -0
- package/src/helpers/url.test.js +18 -0
- package/src/helpers/url.ts +202 -0
- package/src/helpers/urlhelper.ts +104 -0
- package/src/index.ts +24 -0
- package/src/types/common.types.ts +16 -0
- package/src/types/flatted.types.ts +60 -0
- package/src/types/globals.types.ts +7 -0
- package/src/types/graph/calendar.types.ts +81 -0
- package/src/types/graph/index.ts +1 -0
- package/src/types/index.ts +12 -0
- package/src/types/knownscript.types.ts +19 -0
- package/src/types/libs/datajs.types.ts +29 -0
- package/src/types/libs/ics.types.ts +31 -0
- package/src/types/libs/index.ts +4 -0
- package/src/types/libs/msal.types.ts +79 -0
- package/src/types/locales.ts +125 -0
- package/src/types/localstoragecache.types.ts +9 -0
- package/src/types/moment.ts +7 -0
- package/src/types/regex.types.ts +17 -0
- package/src/types/rest.types.ts +94 -0
- package/src/types/sharepoint.types.ts +1413 -0
- package/src/types/sharepoint.utils.types.ts +246 -0
- package/src/utils/_dependencies.ts +4 -0
- package/src/utils/base64.ts +27 -0
- package/src/utils/consolelogger.ts +315 -0
- package/src/utils/date.ts +36 -0
- package/src/utils/emails.ts +25 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/knownscript.ts +280 -0
- package/src/utils/localstoragecache.ts +419 -0
- package/src/utils/rest.ts +465 -0
- package/src/utils/script.ts +168 -0
- package/src/utils/sharepoint.rest/common.ts +149 -0
- package/src/utils/sharepoint.rest/date.ts +61 -0
- package/src/utils/sharepoint.rest/file.folder.ts +368 -0
- package/src/utils/sharepoint.rest/index.ts +11 -0
- package/src/utils/sharepoint.rest/item.ts +456 -0
- package/src/utils/sharepoint.rest/list.ts +1144 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +750 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +265 -0
- package/src/utils/sharepoint.rest/listutils/common.ts +202 -0
- package/src/utils/sharepoint.rest/user-search.ts +254 -0
- package/src/utils/sharepoint.rest/user.ts +447 -0
- package/src/utils/sharepoint.rest/web.ts +1031 -0
- package/src/utils/sod.ts +193 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { IUserInfo, PrincipalType, contentTypes, firstIndexOf, jsonTypes } from "../_dependencies";
|
|
2
|
+
import { GetJson } from "../rest";
|
|
3
|
+
import { EnsureUser } from "./user";
|
|
4
|
+
|
|
5
|
+
interface IPeoplePickerUserItem {
|
|
6
|
+
/**
|
|
7
|
+
* LoginName or Id of the principal in the site.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* LoginName of the principal.
|
|
12
|
+
*/
|
|
13
|
+
loginName: string;
|
|
14
|
+
imageUrl: string;
|
|
15
|
+
imageInitials: string;
|
|
16
|
+
text: string; // name
|
|
17
|
+
secondaryText: string; // role
|
|
18
|
+
tertiaryText: string; // status
|
|
19
|
+
optionalText: string; // anything
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Service implementation to search people in SharePoint
|
|
23
|
+
*/
|
|
24
|
+
export class SPPeopleSearchService {
|
|
25
|
+
private cachedLocalUsers: { [siteUrl: string]: IUserInfo[] };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Service constructor
|
|
29
|
+
*/
|
|
30
|
+
constructor(private context: { siteUrl }) {
|
|
31
|
+
this.cachedLocalUsers = {};
|
|
32
|
+
this.cachedLocalUsers[this.context.siteUrl] = [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Generate the user photo link using SharePoint user photo endpoint.
|
|
37
|
+
*
|
|
38
|
+
* @param value
|
|
39
|
+
*/
|
|
40
|
+
public generateUserPhotoLink(value: string, size: "S" | "M" = "M"): string {
|
|
41
|
+
return `${this.context.siteUrl}/_layouts/15/userphoto.aspx?accountname=${encodeURIComponent(value)}&size=M`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Generate sum of principal types
|
|
46
|
+
*
|
|
47
|
+
* PrincipalType controls the type of entities that are returned in the results.
|
|
48
|
+
* Choices are All - 15, Distribution List - 2 , Security Groups - 4, SharePoint Groups - 8, User - 1.
|
|
49
|
+
* These values can be combined (example: 13 is security + SP groups + users)
|
|
50
|
+
*
|
|
51
|
+
* @param principalTypes
|
|
52
|
+
*/
|
|
53
|
+
public getSumOfPrincipalTypes(principalTypes: PrincipalType[]) {
|
|
54
|
+
return !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve the specified group
|
|
59
|
+
*
|
|
60
|
+
* @param groupName
|
|
61
|
+
* @param siteUrl
|
|
62
|
+
*/
|
|
63
|
+
public async getGroupId(groupName: string, siteUrl: string = null): Promise<number | null> {
|
|
64
|
+
// if (Environment.type === EnvironmentType.Local) {
|
|
65
|
+
// return 1;
|
|
66
|
+
// } else {
|
|
67
|
+
const groups = await this.searchTenant(siteUrl, groupName, 1, [PrincipalType.SharePointGroup], false, 0);
|
|
68
|
+
return (groups && groups.length > 0) ? parseInt(groups[0].id) : null;
|
|
69
|
+
//}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Search person by its email or login name
|
|
74
|
+
*/
|
|
75
|
+
public async searchPersonByEmailOrLogin(email: string, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<IPeoplePickerUserItem> {
|
|
76
|
+
// if (Environment.type === EnvironmentType.Local) {
|
|
77
|
+
// // If the running environment is local, load the data from the mock
|
|
78
|
+
// const mockUsers = await this.searchPeopleFromMock(email);
|
|
79
|
+
// return (mockUsers && mockUsers.length > 0) ? mockUsers[0] : null;
|
|
80
|
+
// } else {
|
|
81
|
+
const userResults = await this.searchTenant(siteUrl, email, 1, principalTypes, ensureUser, groupId);
|
|
82
|
+
return (userResults && userResults.length > 0) ? userResults[0] : null;
|
|
83
|
+
//}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Search All Users from the SharePoint People database
|
|
88
|
+
*/
|
|
89
|
+
public async searchPeople(query: string, maximumSuggestions: number, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<IPeoplePickerUserItem[]> {
|
|
90
|
+
// if (Environment.type === EnvironmentType.Local) {
|
|
91
|
+
// // If the running environment is local, load the data from the mock
|
|
92
|
+
// return this.searchPeopleFromMock(query);
|
|
93
|
+
// } else {
|
|
94
|
+
return await this.searchTenant(siteUrl, query, maximumSuggestions, principalTypes, ensureUser, groupId);
|
|
95
|
+
//}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Tenant search
|
|
100
|
+
*/
|
|
101
|
+
private async searchTenant(siteUrl: string, query: string, maximumSuggestions: number, principalTypes: PrincipalType[], ensureUser: boolean, groupId: number): Promise<IPeoplePickerUserItem[]> {
|
|
102
|
+
try {
|
|
103
|
+
// If the running env is SharePoint, loads from the peoplepicker web service
|
|
104
|
+
const userRequestUrl: string = `${siteUrl || this.context.siteUrl}/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser`;
|
|
105
|
+
const searchBody = {
|
|
106
|
+
queryParams: {
|
|
107
|
+
AllowEmailAddresses: true,
|
|
108
|
+
AllowMultipleEntities: false,
|
|
109
|
+
AllUrlZones: false,
|
|
110
|
+
MaximumEntitySuggestions: maximumSuggestions,
|
|
111
|
+
PrincipalSource: 15,
|
|
112
|
+
PrincipalType: this.getSumOfPrincipalTypes(principalTypes),
|
|
113
|
+
QueryString: query
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Search on the local site when "0"
|
|
118
|
+
if (siteUrl) {
|
|
119
|
+
searchBody.queryParams["SharePointGroupID"] = 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Check if users need to be searched in a specific group
|
|
123
|
+
if (groupId) {
|
|
124
|
+
searchBody.queryParams["SharePointGroupID"] = groupId;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Do the call against the People REST API endpoint
|
|
128
|
+
const userDataResp = await GetJson<{ value: string; }>(
|
|
129
|
+
userRequestUrl,
|
|
130
|
+
JSON.stringify(searchBody),
|
|
131
|
+
{
|
|
132
|
+
headers: {
|
|
133
|
+
Accept: jsonTypes.standard,
|
|
134
|
+
"content-type": contentTypes.json
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
if (userDataResp && userDataResp.value && userDataResp.value.length > 0) {
|
|
139
|
+
let values: any = userDataResp.value;
|
|
140
|
+
|
|
141
|
+
if (typeof userDataResp.value === "string") {
|
|
142
|
+
values = JSON.parse(userDataResp.value);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Filter out "UNVALIDATED_EMAIL_ADDRESS"
|
|
146
|
+
values = values.filter(v => !(v.EntityData && v.EntityData.PrincipalType && v.EntityData.PrincipalType === "UNVALIDATED_EMAIL_ADDRESS"));
|
|
147
|
+
|
|
148
|
+
// Check if local user IDs need to be retrieved
|
|
149
|
+
if (ensureUser) {
|
|
150
|
+
for (const value of values) {
|
|
151
|
+
// Only ensure the user if it is not a SharePoint group
|
|
152
|
+
if (!value.EntityData || (value.EntityData && typeof value.EntityData.SPGroupID === "undefined")) {
|
|
153
|
+
const id = await this.ensureUser(value.Key);
|
|
154
|
+
value.LoginName = value.Key;
|
|
155
|
+
value.Key = id;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Filter out NULL keys
|
|
161
|
+
values = values.filter(v => v.Key !== null);
|
|
162
|
+
const userResults = values.map(element => {
|
|
163
|
+
switch (element.EntityType) {
|
|
164
|
+
case 'User':
|
|
165
|
+
return {
|
|
166
|
+
id: element.Key,
|
|
167
|
+
loginName: element.LoginName ? element.LoginName : element.Key,
|
|
168
|
+
imageUrl: this.generateUserPhotoLink(element.Description || ""),
|
|
169
|
+
imageInitials: this.getFullNameInitials(element.DisplayText),
|
|
170
|
+
text: element.DisplayText, // name
|
|
171
|
+
secondaryText: element.EntityData.Email || element.Description, // email
|
|
172
|
+
tertiaryText: "", // status
|
|
173
|
+
optionalText: "" // anything
|
|
174
|
+
} as IPeoplePickerUserItem;
|
|
175
|
+
case 'SecGroup':
|
|
176
|
+
return {
|
|
177
|
+
id: element.Key,
|
|
178
|
+
loginName: element.LoginName ? element.LoginName : element.Key,
|
|
179
|
+
imageInitials: this.getFullNameInitials(element.DisplayText),
|
|
180
|
+
text: element.DisplayText,
|
|
181
|
+
secondaryText: element.ProviderName
|
|
182
|
+
} as IPeoplePickerUserItem;
|
|
183
|
+
case 'FormsRole':
|
|
184
|
+
return {
|
|
185
|
+
id: element.Key,
|
|
186
|
+
loginName: element.LoginName ? element.LoginName : element.Key,
|
|
187
|
+
imageInitials: this.getFullNameInitials(element.DisplayText),
|
|
188
|
+
text: element.DisplayText,
|
|
189
|
+
secondaryText: element.ProviderName
|
|
190
|
+
} as IPeoplePickerUserItem;
|
|
191
|
+
default:
|
|
192
|
+
return {
|
|
193
|
+
id: element.EntityData.SPGroupID,
|
|
194
|
+
loginName: element.EntityData.AccountName,
|
|
195
|
+
imageInitials: this.getFullNameInitials(element.DisplayText),
|
|
196
|
+
text: element.DisplayText,
|
|
197
|
+
secondaryText: element.EntityData.AccountName
|
|
198
|
+
} as IPeoplePickerUserItem;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return userResults;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
// Nothing to return
|
|
207
|
+
return [];
|
|
208
|
+
} catch (e) {
|
|
209
|
+
console.error("PeopleSearchService::searchTenant: error occured while fetching the users.");
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Retrieves the local user ID
|
|
216
|
+
*
|
|
217
|
+
* @param userId
|
|
218
|
+
*/
|
|
219
|
+
private async ensureUser(userId: string): Promise<number> {
|
|
220
|
+
const siteUrl = this.context.siteUrl;
|
|
221
|
+
if (this.cachedLocalUsers && this.cachedLocalUsers[siteUrl]) {
|
|
222
|
+
const users = this.cachedLocalUsers[siteUrl];
|
|
223
|
+
const userIdx = firstIndexOf(users, u => u.LoginName === userId);
|
|
224
|
+
if (userIdx !== -1) {
|
|
225
|
+
return users[userIdx].Id;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const user = await EnsureUser(siteUrl, userId)
|
|
230
|
+
if (user && user.Id) {
|
|
231
|
+
this.cachedLocalUsers[siteUrl].push(user);
|
|
232
|
+
return user.Id;
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Generates Initials from a full name
|
|
239
|
+
*/
|
|
240
|
+
private getFullNameInitials(fullName: string): string {
|
|
241
|
+
if (fullName === null) {
|
|
242
|
+
return fullName;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const words: string[] = fullName.split(' ');
|
|
246
|
+
if (words.length === 0) {
|
|
247
|
+
return '';
|
|
248
|
+
} else if (words.length === 1) {
|
|
249
|
+
return words[0].charAt(0);
|
|
250
|
+
} else {
|
|
251
|
+
return (words[0].charAt(0) + words[1].charAt(0));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|