Skip to content

Commit 7db401f

Browse files
Piotr Siatkaestruyf
authored andcommitted
#342 Add support for loginName with ensureUser.
1 parent 0596445 commit 7db401f

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/controls/peoplepicker/IPeoplePicker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ export interface IPeoplePickerState {
108108
}
109109

110110
export interface IPeoplePickerUserItem {
111+
/**
112+
* LoginName or Id of the principal in the site.
113+
*/
111114
id: string;
115+
/**
116+
* LoginName of the principal.
117+
*/
118+
loginName: string;
112119
imageUrl: string;
113120
imageInitials: string;
114121
text: string; // name

src/services/PeoplePickerMockClient.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
77
text: "Roger Federer",
88
secondaryText: "[email protected]",
99
tertiaryText: "",
10-
optionalText: ""
10+
optionalText: "",
11+
loginName: "[email protected]"
1112
},
1213
{
1314
id: "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c2",
@@ -16,7 +17,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
1617
text: "Rafael Nadal",
1718
secondaryText: "[email protected]",
1819
tertiaryText: "",
19-
optionalText: ""
20+
optionalText: "",
21+
loginName:"[email protected]"
2022
},
2123
{
2224
id: "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c3",
@@ -25,7 +27,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
2527
text: "Novak Djokovic",
2628
secondaryText: "[email protected]",
2729
tertiaryText: "",
28-
optionalText: ""
30+
optionalText: "",
31+
loginName: "[email protected]"
2932
},
3033
{
3134
id: "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c4",
@@ -34,7 +37,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
3437
text: "Juan Martin del Potro",
3538
secondaryText: "[email protected]",
3639
tertiaryText: "",
37-
optionalText: ""
40+
optionalText: "",
41+
loginName: "[email protected]"
3842
}
3943
];
4044

src/services/PeopleSearchService.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export default class SPPeopleSearchService {
3434

3535
/**
3636
* Generate sum of principal types
37-
*
37+
*
3838
* PrincipalType controls the type of entities that are returned in the results.
3939
* Choices are All - 15, Distribution List - 2 , Security Groups - 4, SharePoint Groups - 8, User - 1.
4040
* These values can be combined (example: 13 is security + SP groups + users)
41-
*
42-
* @param principalTypes
41+
*
42+
* @param principalTypes
4343
*/
4444
public getSumOfPrincipalTypes(principalTypes: PrincipalType[]) {
4545
return !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1;
@@ -217,20 +217,21 @@ export default class SPPeopleSearchService {
217217
// Only ensure the user if it is not a SharePoint group
218218
if (!value.EntityData || (value.EntityData && typeof value.EntityData.SPGroupID === "undefined")) {
219219
const id = await this.ensureUser(value.Key);
220+
value.LoginName = value.Key;
220221
value.Key = id;
221222
}
222223
}
223224
}
224225

225226
// Filter out NULL keys
226227
values = values.filter(v => v.Key !== null);
227-
228228
const userResults = values.map(element => {
229229
switch (element.EntityType) {
230230
case 'User':
231231
let email: string = element.EntityData.Email !== null ? element.EntityData.Email : element.Description;
232232
return {
233233
id: element.Key,
234+
loginName: element.LoginName ? element.LoginName : element.Key,
234235
imageUrl: this.generateUserPhotoLink(email),
235236
imageInitials: this.getFullNameInitials(element.DisplayText),
236237
text: element.DisplayText, // name
@@ -241,20 +242,23 @@ export default class SPPeopleSearchService {
241242
case 'SecGroup':
242243
return {
243244
id: element.Key,
245+
loginName: element.LoginName ? element.LoginName : element.Key,
244246
imageInitials: this.getFullNameInitials(element.DisplayText),
245247
text: element.DisplayText,
246248
secondaryText: element.ProviderName
247249
} as IPeoplePickerUserItem;
248250
case 'FormsRole':
249251
return {
250252
id: element.Key,
253+
loginName: element.LoginName ? element.LoginName : element.Key,
251254
imageInitials: this.getFullNameInitials(element.DisplayText),
252255
text: element.DisplayText,
253256
secondaryText: element.ProviderName
254257
} as IPeoplePickerUserItem;
255258
default:
256259
return {
257260
id: element.EntityData.SPGroupID,
261+
loginName: element.EntityData.AccountName,
258262
imageInitials: this.getFullNameInitials(element.DisplayText),
259263
text: element.DisplayText,
260264
secondaryText: element.EntityData.AccountName

0 commit comments

Comments
 (0)