Skip to content

Commit b320eac

Browse files
brechtvlbartvdbraak
authored andcommitted
BLENDER: Don't allow assigning large teams as reviewers
To avoid accidentally spamming hundreds of people.
1 parent 209ff38 commit b320eac

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

models/organization/team.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,19 @@ func IncrTeamRepoNum(ctx context.Context, teamID int64) error {
247247
_, err := db.GetEngine(ctx).Incr("num_repos").ID(teamID).Update(new(Team))
248248
return err
249249
}
250+
251+
// Avoid notifying large teams accidentally
252+
func FilterLargeTeams(teams []*Team, err error) ([]*Team, error) {
253+
if err != nil {
254+
return nil, err
255+
}
256+
257+
var smallTeams []*Team
258+
for _, team := range teams {
259+
if team.NumMembers <= 10 {
260+
smallTeams = append(smallTeams, team)
261+
}
262+
}
263+
264+
return smallTeams, nil
265+
}

routers/web/repo/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,13 @@ func handleMentionableAssigneesAndTeams(ctx *context.Context, assignees []*user_
673673
}
674674

675675
if isAdmin {
676-
teams, err = org.LoadTeams(ctx)
676+
teams, err = organization.FilterLargeTeams(org.LoadTeams(ctx))
677677
if err != nil {
678678
ctx.ServerError("LoadTeams", err)
679679
return
680680
}
681681
} else {
682-
teams, err = org.GetUserTeams(ctx, ctx.Doer.ID)
682+
teams, err = organization.FilterLargeTeams(org.GetUserTeams(ctx, ctx.Doer.ID))
683683
if err != nil {
684684
ctx.ServerError("GetUserTeams", err)
685685
return

services/pull/reviewer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ func GetReviewerTeams(ctx context.Context, repo *repo_model.Repository) ([]*orga
8585
return nil, nil
8686
}
8787

88-
return organization.GetTeamsWithAccessToRepoUnit(ctx, repo.OwnerID, repo.ID, perm.AccessModeRead, unit.TypePullRequests)
88+
return organization.FilterLargeTeams(organization.GetTeamsWithAccessToRepoUnit(ctx, repo.OwnerID, repo.ID, perm.AccessModeRead, unit.TypePullRequests))
8989
}

0 commit comments

Comments
 (0)