Skip to content

Commit

Permalink
#342 Add support for loginName with ensureUser.
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Siatka authored and estruyf committed Sep 3, 2019
1 parent 0596445 commit 7db401f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/controls/peoplepicker/IPeoplePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ export interface IPeoplePickerState {
}

export interface IPeoplePickerUserItem {
/**
* LoginName or Id of the principal in the site.
*/
id: string;
/**
* LoginName of the principal.
*/
loginName: string;
imageUrl: string;
imageInitials: string;
text: string; // name
Expand Down
12 changes: 8 additions & 4 deletions src/services/PeoplePickerMockClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
text: "Roger Federer",
secondaryText: "roger@tennis.onmicrosoft.com",
tertiaryText: "",
optionalText: ""
optionalText: "",
loginName: "roger@tennis.onmicrosoft.com"
},
{
id: "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c2",
Expand All @@ -16,7 +17,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
text: "Rafael Nadal",
secondaryText: "rafael@tennis.onmicrosoft.com",
tertiaryText: "",
optionalText: ""
optionalText: "",
loginName:"rafael@tennis.onmicrosoft.com"
},
{
id: "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c3",
Expand All @@ -25,7 +27,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
text: "Novak Djokovic",
secondaryText: "novak@tennis.onmicrosoft.com",
tertiaryText: "",
optionalText: ""
optionalText: "",
loginName: "novak@tennis.onmicrosoft.com"
},
{
id: "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c4",
Expand All @@ -34,7 +37,8 @@ export const MockUsers : IPeoplePickerUserItem[] = [{
text: "Juan Martin del Potro",
secondaryText: "juanmartin@tennis.onmicrosoft.com",
tertiaryText: "",
optionalText: ""
optionalText: "",
loginName: "juanmartin@tennis.onmicrosoft.com"
}
];

Expand Down
12 changes: 8 additions & 4 deletions src/services/PeopleSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export default class SPPeopleSearchService {

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

// Filter out NULL keys
values = values.filter(v => v.Key !== null);

const userResults = values.map(element => {
switch (element.EntityType) {
case 'User':
let email: string = element.EntityData.Email !== null ? element.EntityData.Email : element.Description;
return {
id: element.Key,
loginName: element.LoginName ? element.LoginName : element.Key,
imageUrl: this.generateUserPhotoLink(email),
imageInitials: this.getFullNameInitials(element.DisplayText),
text: element.DisplayText, // name
Expand All @@ -241,20 +242,23 @@ export default class SPPeopleSearchService {
case 'SecGroup':
return {
id: element.Key,
loginName: element.LoginName ? element.LoginName : element.Key,
imageInitials: this.getFullNameInitials(element.DisplayText),
text: element.DisplayText,
secondaryText: element.ProviderName
} as IPeoplePickerUserItem;
case 'FormsRole':
return {
id: element.Key,
loginName: element.LoginName ? element.LoginName : element.Key,
imageInitials: this.getFullNameInitials(element.DisplayText),
text: element.DisplayText,
secondaryText: element.ProviderName
} as IPeoplePickerUserItem;
default:
return {
id: element.EntityData.SPGroupID,
loginName: element.EntityData.AccountName,
imageInitials: this.getFullNameInitials(element.DisplayText),
text: element.DisplayText,
secondaryText: element.EntityData.AccountName
Expand Down

0 comments on commit 7db401f

Please sign in to comment.