Skip to content

chore: remove organization requirement from convertGroup() #12195

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 12 commits into from
Feb 21, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Feb 16, 2024

Removed role and org information from the Group's api. This information was always excessive (I even had a TODO comment to remove it). It was kept in because dealing with nested structs on the cli was difficult.

Cli table formatter fixed

The cli table formatter used to not work well with nested structs. I fixed the default_sort bug which allows the User struct to be defined in the way this PR does.

I added the golden file for users list to track this change.

Removing role information from some users in the api. This info is
excessive and not required. It is costly to always include
@Emyrk Emyrk requested a review from mafredri February 21, 2024 17:59
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Looks alright, but how is default sort order decided now that it's removed from the struct?

@@ -0,0 +1,3 @@
USERNAME EMAIL CREATED AT STATUS
testuser testuser@coder.com [timestamp] active
Copy link
Member

Choose a reason for hiding this comment

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

Can we replace it with the same length string? Worried someone might think this is a bug. 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I can pad the timestamp in the replace function?

I could do something like this here:

func NormalizeGoldenFile(t *testing.T, byt []byte) []byte {

	// Replace any timestamps with a placeholder.
	byt = timestampRegex.ReplaceAllFunc(byt, func(source []byte) []byte {
		// Pad the timestamps to maintain the same length. This is mainly for tabled
		// output where the padding is important for alignment.
		lenSrc := len(source)
		rpl := "timestamp"
		required := lenSrc - len(rpl) - 2

		return []byte("[" + fmt.Sprintf("%-*s", required, rpl) + "]")
	})

Copy link
Member Author

Choose a reason for hiding this comment

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

It then looks like this:

USERNAME   EMAIL                CREATED AT            STATUS   
testuser   testuser@coder.com   [timestamp         ]  active   
testuser2  testuser2@coder.com  [timestamp         ]  dormant  

Copy link
Member Author

Choose a reason for hiding this comment

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

And in json

    "created_at": "[timestamp                ]",
    "last_seen_at": "[timestamp                ]",

@Emyrk
Copy link
Member Author

Emyrk commented Feb 21, 2024

Looks alright, but how is default sort order decided now that it's removed from the struct?

Default order is not removed, it's fixed. Prior to this PR you had to have default_sort set on nested structures because our code had an issue. With the fix, default_sort is set on the username in MinimalUser. So it's sorted by username

@Emyrk Emyrk merged commit c3a7b13 into main Feb 21, 2024
@Emyrk Emyrk deleted the stevenmasley/convert_group branch February 21, 2024 21:58
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2024
@Emyrk
Copy link
Member Author

Emyrk commented Feb 21, 2024

timestamp padding moved here: #12256

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants