forked from wrenn/wrenn
Destroy owned sandboxes on user disable and fix OAuth login resilience
When an admin disables a user, all active sandboxes (running, paused, hibernated) for teams they own are now destroyed and their API keys are deleted. User queries now filter by status column instead of deleted_at, so re-enabling a user always works. OAuth login paths use ensureDefaultTeam to auto-create a team if the user has none, matching the email/password login behavior.
This commit is contained in:
@ -4,10 +4,10 @@ VALUES ($1, $2, $3, $4)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetUserByEmail :one
|
||||
SELECT * FROM users WHERE email = $1 AND deleted_at IS NULL;
|
||||
SELECT * FROM users WHERE email = $1 AND status != 'deleted';
|
||||
|
||||
-- name: GetUserByID :one
|
||||
SELECT * FROM users WHERE id = $1 AND deleted_at IS NULL;
|
||||
SELECT * FROM users WHERE id = $1 AND status != 'deleted';
|
||||
|
||||
-- name: InsertUserOAuth :one
|
||||
INSERT INTO users (id, email, name)
|
||||
@ -63,14 +63,14 @@ SELECT
|
||||
(SELECT COUNT(*) FROM users_teams ut WHERE ut.user_id = u.id)::int AS teams_joined,
|
||||
(SELECT COUNT(*) FROM users_teams ut WHERE ut.user_id = u.id AND ut.role = 'owner')::int AS teams_owned
|
||||
FROM users u
|
||||
WHERE u.deleted_at IS NULL
|
||||
WHERE u.status != 'deleted'
|
||||
ORDER BY u.created_at DESC
|
||||
LIMIT $1 OFFSET $2;
|
||||
|
||||
-- name: CountUsersAdmin :one
|
||||
SELECT COUNT(*)::int AS total
|
||||
FROM users
|
||||
WHERE deleted_at IS NULL;
|
||||
WHERE status != 'deleted';
|
||||
|
||||
-- name: SetUserStatus :exec
|
||||
UPDATE users SET status = $2, updated_at = NOW() WHERE id = $1;
|
||||
|
||||
Reference in New Issue
Block a user