Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RCCA-4684] ignore errors getting user profile when listing invitations #1069

Merged
merged 4 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions internal/cmd/iam/command_invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ func (c invitationCommand) listInvitations(cmd *cobra.Command, _ []string) error
return err
}
for _, invitation := range invitations {
userProfile, err := c.Client.User.GetUserProfile(context.Background(), &orgv1.User{
var firstName, lastName string
user, err := c.Client.User.Describe(context.Background(), &orgv1.User{
ResourceId: invitation.UserResourceId,
})
if err != nil {
return err
if err == nil {
firstName = user.FirstName
lastName = user.LastName
}
outputWriter.AddElement(&invitationStruct{
Id: invitation.Id,
Email: invitation.Email,
FirstName: userProfile.FirstName,
LastName: userProfile.LastName,
FirstName: firstName,
LastName: lastName,
Comment on lines +91 to +92
Copy link
Member

Choose a reason for hiding this comment

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

So if there's an error, it's going to add a row with a missing first and last name? Is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct - which is fine since a user that has not accepted the invite yet (error case) would not yet have a first name / last name associated

UserResourceId: invitation.UserResourceId,
Status: invitation.Status,
})
Expand Down
12 changes: 9 additions & 3 deletions internal/cmd/iam/command_invitation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func (suite *InvitationTestSuite) SetupTest() {
LastName: "lastname",
}, nil
},
DescribeFunc: func(arg0 context.Context, arg1 *orgv1.User) (*orgv1.User, error) {
return &orgv1.User{
FirstName: "TEST",
LastName: "lastname",
}, nil
},
ListInvitationsFunc: func(_ context.Context) ([]*orgv1.Invitation, error) {
return []*orgv1.Invitation{
{
Expand Down Expand Up @@ -80,9 +86,9 @@ func (suite *InvitationTestSuite) TestInvitationList() {
req := require.New(suite.T())
req.NoError(err)
req.True(suite.userMock.ListInvitationsCalled())
req.Equal(2, len(suite.userMock.GetUserProfileCalls()))
req.Equal("u-1234", suite.userMock.GetUserProfileCalls()[0].Arg1.ResourceId)
req.Equal("u-4321", suite.userMock.GetUserProfileCalls()[1].Arg1.ResourceId)
req.Equal(2, len(suite.userMock.DescribeCalls()))
req.Equal("u-1234", suite.userMock.DescribeCalls()[0].Arg1.ResourceId)
req.Equal("u-4321", suite.userMock.DescribeCalls()[1].Arg1.ResourceId)
}

func (suite *InvitationTestSuite) TestCreateInvitation() {
Expand Down