Skip to content

Commit bfecf3b

Browse files
authored
Fix internal sever error when visiting a PR that bound to the deleted team (#24127)
Close: #23738 The actual cause of `500 Internal Server Error` in the issue is not what is descirbed in the issue. The actual cause is that after deleting team, if there is a PR which has requested reivew from the deleted team, the comment could not match with the deleted team by `assgin_team_id`. So the value of `.AssigneeTeam` (see below code block) is `nil` which cause `500 error`. https://github.com/go-gitea/gitea/blob/1c8bc4081a4f4d0d921ac218cb724ce97924d410/templates/repo/issue/view_content/comments.tmpl#L691-L695 To fix this bug, there are the following problems to be resolved: - [x] 1. ~~Stroe the name of the team in `content` column when inserting `comment` into DB in case that we cannot get the name of team after it is deleted. But for comments that already exist, just display "Unknown Team"~~ Just display "Ghost Team" in the comment if the assgined team is deleted. - [x] 2. Delete the PR&team binding (the row of which `review_team_id = ${team_id} ` in table `review`) when deleting team. - [x] 3.For already exist and undeleted binding rows in in table `review`, ~~we can delete these rows when executing migrations.~~ they do not affect the function, so won't delete them.
1 parent da6e9f6 commit bfecf3b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

models/org_team.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ func DeleteTeam(t *organization.Team) error {
414414
&organization.TeamUser{OrgID: t.OrgID, TeamID: t.ID},
415415
&organization.TeamUnit{TeamID: t.ID},
416416
&organization.TeamInvite{TeamID: t.ID},
417+
&issues_model.Review{Type: issues_model.ReviewTypeRequest, ReviewerTeamID: t.ID}, // batch delete the binding relationship between team and PR (request review from team)
417418
); err != nil {
418419
return err
419420
}

templates/repo/issue/view_content/comments.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,15 @@
688688
{{$.locale.Tr "repo.issues.review.add_review_request" (.Assignee.GetDisplayName|Escape) $createdStr | Safe}}
689689
{{end}}
690690
{{else}}
691+
<!-- If the assigned team is deleted, just displaying "Ghost Team" in the comment -->
692+
{{$teamName := "Ghost Team"}}
693+
{{if .AssigneeTeam}}
694+
{{$teamName = .AssigneeTeam.Name}}
695+
{{end}}
691696
{{if .RemovedAssignee}}
692-
{{$.locale.Tr "repo.issues.review.remove_review_request" (.AssigneeTeam.Name|Escape) $createdStr | Safe}}
697+
{{$.locale.Tr "repo.issues.review.remove_review_request" ($teamName|Escape) $createdStr | Safe}}
693698
{{else}}
694-
{{$.locale.Tr "repo.issues.review.add_review_request" (.AssigneeTeam.Name|Escape) $createdStr | Safe}}
699+
{{$.locale.Tr "repo.issues.review.add_review_request" ($teamName|Escape) $createdStr | Safe}}
695700
{{end}}
696701
{{end}}
697702
</span>

0 commit comments

Comments
 (0)