-
Notifications
You must be signed in to change notification settings - Fork 901
feat: add PUT /api/v2/users/:user-id/suspend endpoint #1154
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
Changes from 5 commits
8c35a6e
c4404cb
d4c7536
76a95d9
ee9f6b0
d0d6915
e9a3434
45623c7
a36c222
33cc398
cdebd55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DROP TYPE user_status_type; | ||
|
||
ALTER TABLE ONLY users | ||
DROP COLUMN IF EXISTS status; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TYPE user_status_type AS ENUM ('active', 'suspended'); | ||
|
||
ALTER TABLE ONLY users | ||
ADD COLUMN IF NOT EXISTS status user_status_type NOT NULL DEFAULT 'active'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,20 @@ type UsersRequest struct { | |
Offset int `json:"offset"` | ||
} | ||
|
||
type UserStatus string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is this conversation here https://codercom.slack.com/archives/C014JH42DBJ/p1650895472652489?thread_ts=1650895472.652489&cid=C014JH42DBJ but I'm good using both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I missed parts of that thread. I'm fine either way honestly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kylecarbs @johnstcn I think we will have more statuses like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could a user be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kylecarbs I believe the user would just be -- Just my take -- A |
||
|
||
const ( | ||
UserStatusActive UserStatus = "active" | ||
UserStatusSuspended UserStatus = "suspended" | ||
) | ||
|
||
// User represents a user in Coder. | ||
type User struct { | ||
ID uuid.UUID `json:"id" validate:"required"` | ||
Email string `json:"email" validate:"required"` | ||
CreatedAt time.Time `json:"created_at" validate:"required"` | ||
Username string `json:"username" validate:"required"` | ||
ID uuid.UUID `json:"id" validate:"required"` | ||
Email string `json:"email" validate:"required"` | ||
CreatedAt time.Time `json:"created_at" validate:"required"` | ||
Username string `json:"username" validate:"required"` | ||
Status UserStatus `json:"status"` | ||
} | ||
|
||
type CreateFirstUserRequest struct { | ||
|
@@ -155,6 +163,20 @@ func (c *Client) UpdateUserProfile(ctx context.Context, userID uuid.UUID, req Up | |
return user, json.NewDecoder(res.Body).Decode(&user) | ||
} | ||
|
||
// SuspendUser enables callers to suspend a user | ||
func (c *Client) SuspendUser(ctx context.Context, userID uuid.UUID) (User, error) { | ||
res, err := c.request(ctx, http.MethodPut, fmt.Sprintf("/api/v2/users/%s/suspend", uuidOrMe(userID)), nil) | ||
if err != nil { | ||
return User{}, err | ||
} | ||
defer res.Body.Close() | ||
if res.StatusCode != http.StatusOK { | ||
return User{}, readBodyAsError(res) | ||
} | ||
var user User | ||
return user, json.NewDecoder(res.Body).Decode(&user) | ||
} | ||
|
||
// CreateAPIKey generates an API key for the user ID provided. | ||
func (c *Client) CreateAPIKey(ctx context.Context, userID uuid.UUID) (*GenerateAPIKeyResponse, error) { | ||
res, err := c.request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/users/%s/keys", uuidOrMe(userID)), nil) | ||
|
Uh oh!
There was an error while loading. Please reload this page.