mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 08:42:32 -05:00
Remove org users who belong to no teams (#24247)
Fix #24128 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
fe007b65bd
commit
8cc60ee01a
1 changed files with 13 additions and 4 deletions
|
@ -419,6 +419,12 @@ func DeleteTeam(t *organization.Team) error {
|
|||
return err
|
||||
}
|
||||
|
||||
for _, tm := range t.Members {
|
||||
if err := removeInvalidOrgUser(ctx, tm.ID, t.OrgID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Update organization number of teams.
|
||||
if _, err := db.Exec(ctx, "UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
|
||||
return err
|
||||
|
@ -568,16 +574,19 @@ func removeTeamMember(ctx context.Context, team *organization.Team, userID int64
|
|||
}
|
||||
}
|
||||
|
||||
return removeInvalidOrgUser(ctx, userID, team.OrgID)
|
||||
}
|
||||
|
||||
func removeInvalidOrgUser(ctx context.Context, userID, orgID int64) error {
|
||||
// Check if the user is a member of any team in the organization.
|
||||
if count, err := e.Count(&organization.TeamUser{
|
||||
if count, err := db.GetEngine(ctx).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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue