fix: add missing deleting beans for organizations (#11699)

- Delete blocked users entries.
  - Organization cannot get blocked, it can block other people however.
- Delete following entries.
  - Organization cannot follow, it can be followed by users.
- Resolves forgejo/forgejo#11416

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11699
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2026-03-17 09:11:52 +01:00 committed by Gusted
parent 075ee9ea88
commit c1787d06e2
6 changed files with 37 additions and 0 deletions

View file

@ -397,6 +397,14 @@ func DeleteOrganization(ctx context.Context, org *Organization) error {
return fmt.Errorf("%s is a user not an organization", org.Name)
}
// Decrease following count of users that follow the organisation.
followerIDs, err := db.FindIDs(ctx, "follow", "follow.user_id", builder.Eq{"follow.follow_id": org.ID})
if err != nil {
return fmt.Errorf("get all followers: %w", err)
} else if err = db.DecrByIDs(ctx, followerIDs, "num_following", new(user_model.User)); err != nil {
return fmt.Errorf("decrease user num_following: %w", err)
}
if err := db.DeleteBeans(ctx,
&Team{OrgID: org.ID},
&OrgUser{OrgID: org.ID},
@ -406,6 +414,8 @@ func DeleteOrganization(ctx context.Context, org *Organization) error {
&secret_model.Secret{OwnerID: org.ID},
&actions_model.ActionRunner{OwnerID: org.ID},
&actions_model.ActionRunnerToken{OwnerID: optional.Some(org.ID)},
&user_model.BlockedUser{UserID: org.ID},
&user_model.Follow{FollowID: org.ID},
); err != nil {
return fmt.Errorf("DeleteBeans: %w", err)
}