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

Add First and Last name to the user identity object #3832

Merged
merged 1 commit into from
Jul 10, 2024
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
2 changes: 2 additions & 0 deletions docs/docs/ref/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/auth/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ type Identity struct {
// UserID and HumanName are only unique within the context of a single
// identity provider.
Provider IdentityProvider
// FirstName and LastName are optional fields that may be provided by the
// identity provider. These are not guaranteed to be present, and may be
// empty.
FirstName string
LastName string
}

// String implements strings.Stringer, and also provides a stable storage
Expand Down
10 changes: 9 additions & 1 deletion internal/auth/keycloak/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,19 @@ func (k *KeyCloak) userToIdentity(user client.UserRepresentation) *auth.Identity
if user.Attributes == nil || user.Id == nil {
return nil
}
return &auth.Identity{
ret := &auth.Identity{
UserID: *user.Id,
HumanName: *user.Username,
Provider: k,
}
// If the user has a first and last name, return them too
if user.FirstName != nil {
ret.FirstName = *user.FirstName
}
if user.LastName != nil {
ret.LastName = *user.LastName
}
return ret
Comment on lines +160 to +172
Copy link
Member

Choose a reason for hiding this comment

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

I think you can take advantage of proto3's empty-field behavior and simplify:

Suggested change
ret := &auth.Identity{
UserID: *user.Id,
HumanName: *user.Username,
Provider: k,
}
// If the user has a first and last name, return them too
if user.FirstName != nil {
ret.FirstName = *user.FirstName
}
if user.LastName != nil {
ret.LastName = *user.LastName
}
return ret
ret := &auth.Identity{
UserID: *user.Id,
HumanName: *user.Username,
Provider: k,
FirstName: *user.FirstName,
LastName: *user.LastName,
}
return ret

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I did try it like that but for users where this was missing, it was failing because of the nil reference.

}

func (_ *KeyCloak) lookupGithubUser(_ context.Context, _ string) (*auth.Identity, error) {
Expand Down
2 changes: 2 additions & 0 deletions internal/controlplane/handlers_authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ func (s *Server) ListRoleAssignments(
continue
}
as[i].DisplayName = identity.Human()
as[i].FirstName = identity.FirstName
as[i].LastName = identity.LastName
if mapIdToDisplay[as[i].Subject] == "" {
mapIdToDisplay[as[i].Subject] = identity.Human()
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/api/openapi/minder/v1/minder.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,968 changes: 995 additions & 973 deletions pkg/api/protobuf/go/minder/v1/minder.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions proto/minder/v1/minder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,10 @@ message RoleAssignment {
optional string project = 4;
// email is the email address of the subject used for invitations.
string email = 6;
// first_name is the first name of the subject.
string first_name = 7;
// last_name is the last name of the subject.
string last_name = 8;

reserved 3; // deprecated context
}
Expand Down