Skip to content

feat: add audit logs for dormancy events #15298

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 14 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! feat: add audit logs for dormancy events
  • Loading branch information
coadler committed Oct 30, 2024
commit 68adf8addc4b788c1c53e96d8c911200c965b163
2 changes: 1 addition & 1 deletion coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
OrganizationIDs: organizationIDs,
// Always create users as active in tests to ignore an extra audit log
// when logging in.
UserStatus: codersdk.UserStatusActive,
UserStatus: ptr.Ref(codersdk.UserStatusActive),
}
for _, m := range mutators {
m(&req)
Expand Down
9 changes: 7 additions & 2 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/coder/coder/v2/coderd/searchquery"
"github.com/coder/coder/v2/coderd/telemetry"
"github.com/coder/coder/v2/coderd/userpassword"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/coderd/util/slice"
"github.com/coder/coder/v2/codersdk"
)
Expand Down Expand Up @@ -192,7 +193,7 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) {
Username: createUser.Username,
Name: createUser.Name,
Password: createUser.Password,
UserStatus: codersdk.UserStatusActive,
UserStatus: ptr.Ref(codersdk.UserStatusActive),
OrganizationIDs: []uuid.UUID{defaultOrg.ID},
},
LoginType: database.LoginTypePassword,
Expand Down Expand Up @@ -1346,6 +1347,10 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create
err := store.InTx(func(tx database.Store) error {
orgRoles := make([]string, 0)

status := ""
if req.UserStatus != nil {
status = string(*req.UserStatus)
}
Comment on lines +1350 to +1353
Copy link
Collaborator

Choose a reason for hiding this comment

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

similarly when would we expect the status to be empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Empty just means use the default behavior, which is dormant. It would be a breaking change if this was required

params := database.InsertUserParams{
ID: uuid.New(),
Email: req.Email,
Expand All @@ -1357,7 +1362,7 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create
// All new users are defaulted to members of the site.
RBACRoles: []string{},
LoginType: req.LoginType,
Status: string(req.UserStatus),
Status: status,
}
// If a user signs up with OAuth, they can have no password!
if req.Password != "" {
Expand Down
3 changes: 2 additions & 1 deletion coderd/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/coder/coder/v2/coderd/database/dbgen"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/coderd/util/slice"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/testutil"
Expand Down Expand Up @@ -724,7 +725,7 @@ func TestPostUsers(t *testing.T) {
Email: "another@user.org",
Username: "someone-else",
Password: "SomeSecurePassword!",
UserStatus: codersdk.UserStatusActive,
UserStatus: ptr.Ref(codersdk.UserStatusActive),
})
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ type CreateUserRequestWithOrgs struct {
// UserLoginType defaults to LoginTypePassword.
UserLoginType LoginType `json:"login_type"`
// UserStatus defaults to UserStatusDormant.
UserStatus UserStatus `json:"user_status"`
UserStatus *UserStatus `json:"user_status"`
// OrganizationIDs is a list of organization IDs that the user should be a member of.
OrganizationIDs []uuid.UUID `json:"organization_ids" validate:"" format:"uuid"`
}
Expand Down
1 change: 0 additions & 1 deletion site/e2e/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const createUser = async (orgId: string) => {
password: "s3cure&password!",
login_type: "password",
organization_ids: [orgId],
user_status: "dormant"
});
return user;
};
Expand Down
2 changes: 1 addition & 1 deletion site/src/api/typesGenerated.ts

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

Loading