mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-20 08:00:52 +00:00
fix: aggregate deleted team as ghost team (#7987)
- If a review was requested from a deleted team, use the ghost team for the comment aggregator. - Resolves Codeberg/Community#1952 - Unit test added. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7987 Reviewed-by: Beowulf <beowulf@beocode.eu> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
99d697263f
commit
d6ab2a464f
3 changed files with 42 additions and 2 deletions
|
@ -652,8 +652,11 @@ func (c *Comment) LoadAssigneeUserAndTeam(ctx context.Context) error {
|
||||||
|
|
||||||
if c.Issue.Repo.Owner.IsOrganization() {
|
if c.Issue.Repo.Owner.IsOrganization() {
|
||||||
c.AssigneeTeam, err = organization.GetTeamByID(ctx, c.AssigneeTeamID)
|
c.AssigneeTeam, err = organization.GetTeamByID(ctx, c.AssigneeTeamID)
|
||||||
if err != nil && !organization.IsErrTeamNotExist(err) {
|
if err != nil {
|
||||||
return err
|
if !organization.IsErrTeamNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.AssigneeTeam = organization.NewGhostTeam()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,3 +292,11 @@ func FixInconsistentOwnerTeams(ctx context.Context) (int64, error) {
|
||||||
|
|
||||||
return int64(len(teamIDs)), nil
|
return int64(len(teamIDs)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewGhostTeam() *Team {
|
||||||
|
return &Team{
|
||||||
|
ID: -1,
|
||||||
|
Name: "Ghost team",
|
||||||
|
LowerName: "ghost team",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -94,6 +94,14 @@ func reqReview(t int64, name string, delReq bool) *issue_model.Comment {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ghostReqReview(t, id int64) *issue_model.Comment {
|
||||||
|
c := testComment(t)
|
||||||
|
c.Type = issue_model.CommentTypeReviewRequest
|
||||||
|
c.AssigneeTeam = organization.NewGhostTeam()
|
||||||
|
c.AssigneeTeamID = id
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
func reqReviewList(t int64, del bool, names ...string) *issue_model.Comment {
|
func reqReviewList(t int64, del bool, names ...string) *issue_model.Comment {
|
||||||
req := []issue_model.RequestReviewTarget{}
|
req := []issue_model.RequestReviewTarget{}
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
|
@ -588,6 +596,27 @@ func TestCombineReviewRequests(t *testing.T) {
|
||||||
reqReviewList(121, true, "titi", "toto-team"),
|
reqReviewList(121, true, "titi", "toto-team"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Ghost.
|
||||||
|
{
|
||||||
|
name: "ghost reviews",
|
||||||
|
beforeCombined: []*issue_model.Comment{
|
||||||
|
reqReview(1, "titi", false),
|
||||||
|
ghostReqReview(2, 50),
|
||||||
|
ghostReqReview(3, 51),
|
||||||
|
ghostReqReview(4, 50),
|
||||||
|
},
|
||||||
|
afterCombined: []*issue_model.Comment{
|
||||||
|
{
|
||||||
|
PosterID: 1,
|
||||||
|
Type: issue_model.CommentTypeReviewRequest,
|
||||||
|
CreatedUnix: timeutil.TimeStamp(1),
|
||||||
|
AddedRequestReview: []issue_model.RequestReviewTarget{
|
||||||
|
createReqReviewTarget("titi"), {Team: organization.NewGhostTeam()},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, kase := range kases {
|
for _, kase := range kases {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue