Skip to content

Extends 'aad user get' with email option - #2856

Closed
nanddeepn wants to merge 4 commits into
pnp:mainfrom
nanddeepn:aad-user-get-email
Closed

nanddeepn wants to merge 4 commits into
pnp:mainfrom
nanddeepn:aad-user-get-email

Conversation

@nanddeepn

Copy link
Copy Markdown
Contributor

Extends aad user get with email option. Closes #2855

@garrytrinder

Copy link
Copy Markdown
Member

Thank you @nanddeepn we will review shortly 👍🏻

@waldekmastykarz waldekmastykarz self-assigned this Dec 9, 2021

@waldekmastykarz waldekmastykarz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the changes a bit before we merge

Comment thread src/m365/aad/commands/user/user-get.ts Outdated
request
.get(requestOptions)
.then((res: any): void => {
.then((res: any): Promise<any> => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using any to avoid refactoring issues in the future. Since we know what data we expect from the API, we should use specific types instead.

@nanddeepn
nanddeepn marked this pull request as ready for review December 11, 2021 15:27
Comment thread src/m365/aad/commands/user/User.ts Outdated
@@ -0,0 +1,13 @@
export interface User {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're getting User from MS Graph, let's use the type from the @microsoft/microsoft-graph-types package instead of defining our own.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! I will correct. Thank you.

@nanddeepn

Copy link
Copy Markdown
Contributor Author

The failing test is file convert pdf, not related to this command.

@waldekmastykarz waldekmastykarz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nanddeepn, we're almost there. Sorry I didn't catch the issues earlier and I appreciate you sticking with us ❤️

Comment thread src/m365/aad/commands/user/user-get.ts Outdated
request
.get(requestOptions)
.then((res: any): void => {
.then((res: any): Promise<User> => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we know the shape of the data that we expect from the API, let's avoid using any and use the expected types instead to avoid runtime errors.

Comment thread src/m365/aad/commands/user/user-get.ts Outdated
.then((res: any): Promise<User> => {
if (args.options.email) {
if (res.value.length > 0) {
return Promise.resolve(res.value[0]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than returning the first user silently, it would be better to throw an error and prompt the user to disambiguate using the user name or ID. Otherwise you might end up working with the wrong user object.

@waldekmastykarz waldekmastykarz removed their assignment Dec 16, 2021
@waldekmastykarz
waldekmastykarz marked this pull request as draft December 16, 2021 14:00
@nanddeepn
nanddeepn marked this pull request as ready for review December 23, 2021 11:13
@waldekmastykarz waldekmastykarz self-assigned this Dec 28, 2021

@waldekmastykarz waldekmastykarz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nicely done with just one small change I've done when merging the PR


return Promise.reject(`Multiple users with ${identifier} found. Please disambiguate (user names): ${res.value.map(a => a.userPrincipalName).join(', ')} or (ids): ${res.value.map(a => a.id).join(', ')}`);
})
.then((res: any): any => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be:

 .then((res: User): void => {

or for short:

 .then(res => {

Let's avoid using any when possible

@waldekmastykarz

Copy link
Copy Markdown
Member

Merged manually. Thank you! 👏

@nanddeepn
nanddeepn deleted the aad-user-get-email branch December 30, 2021 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants