Skip to content

Commit d6e9870

Browse files
authored
feat: add "dormant" user state (#8644)
1 parent d2c7c8e commit d6e9870

40 files changed

+587
-239
lines changed

cli/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import (
7070
"github.com/coder/coder/coderd/database/migrations"
7171
"github.com/coder/coder/coderd/database/pubsub"
7272
"github.com/coder/coder/coderd/devtunnel"
73+
"github.com/coder/coder/coderd/dormancy"
7374
"github.com/coder/coder/coderd/gitauth"
7475
"github.com/coder/coder/coderd/gitsshkey"
7576
"github.com/coder/coder/coderd/httpapi"
@@ -812,6 +813,9 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
812813
options.SwaggerEndpoint = cfg.Swagger.Enable.Value()
813814
}
814815

816+
closeCheckInactiveUsersFunc := dormancy.CheckInactiveUsers(ctx, logger, options.Database)
817+
defer closeCheckInactiveUsersFunc()
818+
815819
// We use a separate coderAPICloser so the Enterprise API
816820
// can have it's own close functions. This is cleaner
817821
// than abstracting the Coder API itself.

cli/testdata/coder_scaletest_--help.golden

Lines changed: 0 additions & 16 deletions
This file was deleted.

cli/testdata/coder_scaletest_cleanup_--help.golden

Lines changed: 0 additions & 19 deletions
This file was deleted.

cli/testdata/coder_scaletest_create-workspaces_--help.golden

Lines changed: 0 additions & 114 deletions
This file was deleted.

cli/testdata/coder_scaletest_workspace-traffic_--help.golden

Lines changed: 0 additions & 62 deletions
This file was deleted.

cli/testdata/coder_users_list_--output_json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"email": "testuser2@coder.com",
2525
"created_at": "[timestamp]",
2626
"last_seen_at": "[timestamp]",
27-
"status": "active",
27+
"status": "dormant",
2828
"organization_ids": [
2929
"[first org ID]"
3030
],

cli/userstatus_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import (
1414

1515
func TestUserStatus(t *testing.T) {
1616
t.Parallel()
17-
client := coderdtest.New(t, nil)
18-
admin := coderdtest.CreateFirstUser(t, client)
19-
other, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
20-
otherUser, err := other.User(context.Background(), codersdk.Me)
21-
require.NoError(t, err, "fetch user")
2217

2318
t.Run("StatusSelf", func(t *testing.T) {
2419
t.Parallel()
20+
21+
client := coderdtest.New(t, nil)
22+
coderdtest.CreateFirstUser(t, client)
23+
2524
inv, root := clitest.New(t, "users", "suspend", "me")
2625
clitest.SetupConfig(t, client, root)
2726
// Yes to the prompt
@@ -34,13 +33,18 @@ func TestUserStatus(t *testing.T) {
3433

3534
t.Run("StatusOther", func(t *testing.T) {
3635
t.Parallel()
37-
require.Equal(t, codersdk.UserStatusActive, otherUser.Status, "start as active")
36+
37+
client := coderdtest.New(t, nil)
38+
admin := coderdtest.CreateFirstUser(t, client)
39+
other, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
40+
otherUser, err := other.User(context.Background(), codersdk.Me)
41+
require.NoError(t, err, "fetch user")
3842

3943
inv, root := clitest.New(t, "users", "suspend", otherUser.Username)
4044
clitest.SetupConfig(t, client, root)
4145
// Yes to the prompt
4246
inv.Stdin = bytes.NewReader([]byte("yes\n"))
43-
err := inv.Run()
47+
err = inv.Run()
4448
require.NoError(t, err, "suspend user")
4549

4650
// Check the user status

coderd/apidoc/docs.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderdtest/coderdtest.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,14 @@ func createAnotherUserRetry(t *testing.T, client *codersdk.Client, organizationI
587587
sessionToken = token.Key
588588
}
589589

590+
if user.Status == codersdk.UserStatusDormant {
591+
// Use admin client so that user's LastSeenAt is not updated.
592+
// In general we need to refresh the user status, which should
593+
// transition from "dormant" to "active".
594+
user, err = client.User(context.Background(), user.Username)
595+
require.NoError(t, err)
596+
}
597+
590598
other := codersdk.New(client.URL)
591599
other.SetSessionToken(sessionToken)
592600
t.Cleanup(func() {

0 commit comments

Comments
 (0)