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

User API: Add missing project display name and description #3451

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
19 changes: 15 additions & 4 deletions internal/controlplane/handlers_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,22 @@ func (s *Server) getUserDependencies(ctx context.Context, user db.User) ([]*pb.P
return nil, err
}

// Try to parse the project metadata to complete the response fields
pDisplay := pinfo.Name
pDescr := ""
meta, err := projects.ParseMetadata(&pinfo)
if err == nil {
pDisplay = meta.Public.DisplayName
pDescr = meta.Public.Description
}

projectsPB = append(projectsPB, &pb.Project{
ProjectId: proj.String(),
Name: pinfo.Name,
CreatedAt: timestamppb.New(pinfo.CreatedAt),
UpdatedAt: timestamppb.New(pinfo.UpdatedAt),
ProjectId: proj.String(),
Name: pinfo.Name,
CreatedAt: timestamppb.New(pinfo.CreatedAt),
UpdatedAt: timestamppb.New(pinfo.UpdatedAt),
DisplayName: pDisplay,
Description: pDescr,
Comment on lines +216 to +217
Copy link
Member

Choose a reason for hiding this comment

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

@kantord - hey, in case the parsing above fails for some reason is it okay with you to have the default variable values here, i.e. empty strings?

Copy link

Choose a reason for hiding this comment

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

you mean specifically for description? I think for description, empty string is a reasonable fallback value, but for displayName I think that using the name as a fallback value would make more sense

Copy link

Choose a reason for hiding this comment

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

also, I'm not very informed about how the BE codebase works, but as I understand the fallback logic happens at insertion time, meaning this code itself does not address existing data in the database. I guess those could be fixed using a database migration or a manual query?

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this code is happening on the way out of the database when answering the query, not on insertion. (That's both what I would expect, and matches the pattern in the code where we're constructing a protocol buffer for output.) If we change 203 to:

pDisplay := pinfo.Name
pDescr := ""

before calling ParseMetadata, that should be sufficient to fill in the defaults when the metadata doesn't exist in the database, without needing a backfill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @evankanderson , I've changed the initial values as suggested :)

})
}

Expand Down