fix: filter recipients for new release mails

Remove recipients that are not active (e.g. done by moderation or
organizational reasons) and those that have the permi ssion to read
releases on that repository.
This commit is contained in:
Gusted 2026-02-21 14:47:07 +01:00 committed by Mathieu Fenniak
parent 58d844b320
commit 5e1a2f9cc4

View file

@ -6,8 +6,11 @@ package mailer
import (
"bytes"
"context"
"slices"
access_model "forgejo.org/models/perm/access"
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unit"
user_model "forgejo.org/models/user"
"forgejo.org/modules/base"
"forgejo.org/modules/log"
@ -40,6 +43,12 @@ func MailNewRelease(ctx context.Context, rel *repo_model.Release) {
return
}
// Users are not eligible to receive this mail if they are not active or
// they don't have permissions to read releases.
recipients = slices.DeleteFunc(recipients, func(u *user_model.User) bool {
return !u.IsActive || !access_model.CheckRepoUnitUser(ctx, rel.Repo, u, unit.TypeReleases)
})
langMap := make(map[string][]*user_model.User)
for _, user := range recipients {
if user.ID != rel.PublisherID {