mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 16:37:52 +01:00
Backport #24247 by @yp05327 Fix #24128 Co-authored-by: yp05327 <576951401@qq.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
8044d87c18
commit
b1094ff28c
@ -418,6 +418,12 @@ func DeleteTeam(t *organization.Team) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, tm := range t.Members {
|
||||||
|
if err := removeInvalidOrgUser(ctx, tm.ID, t.OrgID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update organization number of teams.
|
// Update organization number of teams.
|
||||||
if _, err := db.Exec(ctx, "UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
|
if _, err := db.Exec(ctx, "UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -567,16 +573,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.
|
// 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,
|
UID: userID,
|
||||||
OrgID: team.OrgID,
|
OrgID: orgID,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if count == 0 {
|
} else if count == 0 {
|
||||||
return removeOrgUser(ctx, team.OrgID, userID)
|
return removeOrgUser(ctx, orgID, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user