Skip to content
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

Remove org users who belong to no teams #24247

Merged
Merged
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
21 changes: 8 additions & 13 deletions models/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,8 @@ func DeleteTeam(t *organization.Team) error {
}

for _, tm := range t.Members {
// Check if the user is a member of any team in the organization.
if count, err := sess.Count(&organization.TeamUser{
UID: tm.ID,
OrgID: t.OrgID,
}); err != nil {
if err := removeInvaildOrgUser(ctx, sess, tm.ID, t.OrgID); err != nil {
return err
} else if count == 0 {
if err = removeOrgUser(ctx, t.OrgID, tm.ID); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -583,16 +575,19 @@ func removeTeamMember(ctx context.Context, team *organization.Team, userID int64
}
}

return removeInvaildOrgUser(ctx, e, userID, team.OrgID)
}

func removeInvaildOrgUser(ctx context.Context, sess db.Engine, userID, orgID int64) error {
yp05327 marked this conversation as resolved.
Show resolved Hide resolved
// Check if the user is a member of any team in the organization.
if count, err := e.Count(&organization.TeamUser{
if count, err := sess.Count(&organization.TeamUser{
UID: userID,
OrgID: team.OrgID,
OrgID: orgID,
}); err != nil {
return err
} else if count == 0 {
return removeOrgUser(ctx, team.OrgID, userID)
return removeOrgUser(ctx, orgID, userID)
}

return nil
}

Expand Down