mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
fix: Deleting a user from a group should only delete from a single group (#5977)
This commit is contained in:
@ -3551,12 +3551,12 @@ func (q *fakeQuerier) InsertGroupMember(_ context.Context, arg database.InsertGr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) DeleteGroupMember(_ context.Context, userID uuid.UUID) error {
|
||||
func (q *fakeQuerier) DeleteGroupMemberFromGroup(_ context.Context, arg database.DeleteGroupMemberFromGroupParams) error {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for i, member := range q.groupMembers {
|
||||
if member.UserID == userID {
|
||||
if member.UserID == arg.UserID && member.GroupID == arg.GroupID {
|
||||
q.groupMembers = append(q.groupMembers[:i], q.groupMembers[i+1:]...)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ type sqlcQuerier interface {
|
||||
DeleteAPIKeysByUserID(ctx context.Context, userID uuid.UUID) error
|
||||
DeleteGitSSHKey(ctx context.Context, userID uuid.UUID) error
|
||||
DeleteGroupByID(ctx context.Context, id uuid.UUID) error
|
||||
DeleteGroupMember(ctx context.Context, userID uuid.UUID) error
|
||||
DeleteGroupMemberFromGroup(ctx context.Context, arg DeleteGroupMemberFromGroupParams) error
|
||||
DeleteLicense(ctx context.Context, id int32) (int32, error)
|
||||
DeleteOldAgentStats(ctx context.Context) error
|
||||
DeleteParameterValueByID(ctx context.Context, id uuid.UUID) error
|
||||
|
@ -990,15 +990,21 @@ func (q *sqlQuerier) DeleteGroupByID(ctx context.Context, id uuid.UUID) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteGroupMember = `-- name: DeleteGroupMember :exec
|
||||
const deleteGroupMemberFromGroup = `-- name: DeleteGroupMemberFromGroup :exec
|
||||
DELETE FROM
|
||||
group_members
|
||||
WHERE
|
||||
user_id = $1
|
||||
user_id = $1 AND
|
||||
group_id = $2
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) DeleteGroupMember(ctx context.Context, userID uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteGroupMember, userID)
|
||||
type DeleteGroupMemberFromGroupParams struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"user_id"`
|
||||
GroupID uuid.UUID `db:"group_id" json:"group_id"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) DeleteGroupMemberFromGroup(ctx context.Context, arg DeleteGroupMemberFromGroupParams) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteGroupMemberFromGroup, arg.UserID, arg.GroupID)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -1220,7 +1226,7 @@ INSERT INTO group_members (
|
||||
user_id,
|
||||
group_id
|
||||
)
|
||||
VALUES ( $1, $2)
|
||||
VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type InsertGroupMemberParams struct {
|
||||
|
@ -85,13 +85,14 @@ INSERT INTO group_members (
|
||||
user_id,
|
||||
group_id
|
||||
)
|
||||
VALUES ( $1, $2);
|
||||
VALUES ($1, $2);
|
||||
|
||||
-- name: DeleteGroupMember :exec
|
||||
-- name: DeleteGroupMemberFromGroup :exec
|
||||
DELETE FROM
|
||||
group_members
|
||||
WHERE
|
||||
user_id = $1;
|
||||
user_id = $1 AND
|
||||
group_id = $2;
|
||||
|
||||
-- name: DeleteGroupByID :exec
|
||||
DELETE FROM
|
||||
|
Reference in New Issue
Block a user