Skip to content

fix!: omit name, avatar_url and last_seen_at from responses when empty #18005

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

Merged
merged 1 commit into from
May 23, 2025
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
1 change: 0 additions & 1 deletion cli/testdata/coder_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"workspace_name": "test-workspace",
"workspace_owner_id": "==========[first user ID]===========",
"workspace_owner_name": "testuser",
"workspace_owner_avatar_url": "",
"template_version_id": "============[version ID]============",
"template_version_name": "===========[version name]===========",
"build_number": 1,
Expand Down
3 changes: 0 additions & 3 deletions cli/testdata/coder_users_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
"id": "==========[first user ID]===========",
"username": "testuser",
"avatar_url": "",
"name": "Test User",
"email": "testuser@coder.com",
"created_at": "====[timestamp]=====",
Expand All @@ -23,8 +22,6 @@
{
"id": "==========[second user ID]==========",
"username": "testuser2",
"avatar_url": "",
"name": "",
"email": "testuser2@coder.com",
"created_at": "====[timestamp]=====",
"updated_at": "====[timestamp]=====",
Expand Down
4 changes: 2 additions & 2 deletions codersdk/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ type OrganizationMember struct {

type OrganizationMemberWithUserData struct {
Username string `table:"username,default_sort" json:"username"`
Name string `table:"name" json:"name"`
AvatarURL string `json:"avatar_url"`
Name string `table:"name" json:"name,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
Email string `json:"email"`
GlobalRoles []SlimRole `json:"global_roles"`
OrganizationMember `table:"m,recursive_inline"`
Expand Down
6 changes: 3 additions & 3 deletions codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type UsersRequest struct {
type MinimalUser struct {
ID uuid.UUID `json:"id" validate:"required" table:"id" format:"uuid"`
Username string `json:"username" validate:"required" table:"username,default_sort"`
AvatarURL string `json:"avatar_url" format:"uri"`
AvatarURL string `json:"avatar_url,omitempty" format:"uri"`
}

// ReducedUser omits role and organization information. Roles are deduced from
Expand All @@ -49,11 +49,11 @@ type MinimalUser struct {
// required by the frontend.
type ReducedUser struct {
MinimalUser `table:"m,recursive_inline"`
Name string `json:"name"`
Name string `json:"name,omitempty"`
Email string `json:"email" validate:"required" table:"email" format:"email"`
CreatedAt time.Time `json:"created_at" validate:"required" table:"created at" format:"date-time"`
UpdatedAt time.Time `json:"updated_at" table:"updated at" format:"date-time"`
LastSeenAt time.Time `json:"last_seen_at" format:"date-time"`
LastSeenAt time.Time `json:"last_seen_at,omitempty" format:"date-time"`

Status UserStatus `json:"status" table:"status" enums:"active,suspended"`
LoginType LoginType `json:"login_type"`
Expand Down
2 changes: 1 addition & 1 deletion codersdk/workspacebuilds.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type WorkspaceBuild struct {
WorkspaceName string `json:"workspace_name"`
WorkspaceOwnerID uuid.UUID `json:"workspace_owner_id" format:"uuid"`
WorkspaceOwnerName string `json:"workspace_owner_name"`
WorkspaceOwnerAvatarURL string `json:"workspace_owner_avatar_url"`
WorkspaceOwnerAvatarURL string `json:"workspace_owner_avatar_url,omitempty"`
TemplateVersionID uuid.UUID `json:"template_version_id" format:"uuid"`
TemplateVersionName string `json:"template_version_name"`
BuildNumber int32 `json:"build_number"`
Expand Down
12 changes: 6 additions & 6 deletions site/src/api/typesGenerated.ts

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

2 changes: 1 addition & 1 deletion site/src/components/UserAutocomplete/UserAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { prepareQuery } from "utils/filters";

// The common properties between users and org members that we need.
export type SelectedUser = {
avatar_url: string;
avatar_url?: string;
email: string;
username: string;
};
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/ChatPage/ChatLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ChatLanding: FC = () => {
textAlign: "center",
}}
>
Good evening, {user?.name.split(" ")[0]}
Good evening, {(user.name ?? user.username).split(" ")[0]}
</h1>
<p
css={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("AccountForm", () => {
// Given
const mockInitialValues: UpdateUserProfileRequest = {
username: MockUserMember.username,
name: MockUserMember.name,
name: MockUserMember.name ?? MockUserMember.username,
};

// When
Expand Down Expand Up @@ -44,7 +44,7 @@ describe("AccountForm", () => {
// Given
const mockInitialValues: UpdateUserProfileRequest = {
username: MockUserMember.username,
name: MockUserMember.name,
name: MockUserMember.name ?? MockUserMember.username,
};

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const AccountPage: FC = () => {
email={me.email}
updateProfileError={updateProfileError}
isLoading={isUpdatingProfile}
initialValues={{ username: me.username, name: me.name }}
initialValues={{ username: me.username, name: me.name ?? "" }}
onSubmit={updateProfile}
/>
</Section>
Expand Down
8 changes: 4 additions & 4 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ export const MockOrganizationMember: TypesGen.OrganizationMemberWithUserData = {
user_id: MockUserOwner.id,
username: MockUserOwner.username,
email: MockUserOwner.email,
created_at: "",
updated_at: "",
updated_at: "2025-05-22T17:51:49.49745Z",
created_at: "2025-05-22T17:51:49.497449Z",
name: MockUserOwner.name,
avatar_url: MockUserOwner.avatar_url,
global_roles: MockUserOwner.roles,
Expand All @@ -553,8 +553,8 @@ export const MockOrganizationMember2: TypesGen.OrganizationMemberWithUserData =
user_id: MockUserMember.id,
username: MockUserMember.username,
email: MockUserMember.email,
created_at: "",
updated_at: "",
updated_at: "2025-05-22T17:51:49.49745Z",
created_at: "2025-05-22T17:51:49.497449Z",
name: MockUserMember.name,
avatar_url: MockUserMember.avatar_url,
global_roles: MockUserMember.roles,
Expand Down
Loading