Skip to content

Commit 9e68261

Browse files
yardenshohamZettat123zeripathlunny
authored
fix incorrect role labels for migrated issues and comments (#22914) (#22923)
Backport #22914 Fix #22797. ## Reason If a comment was migrated from other platforms, this comment may have an original author and its poster is always not the original author. When the `roleDescriptor` func get the poster's role descriptor for a comment, it does not check if the comment has an original author. So the migrated comments' original authors might be marked as incorrect roles. Co-authored-by: Zettat123 <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent e423858 commit 9e68261

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

models/issues/comment.go

+5
Original file line numberDiff line numberDiff line change
@@ -1549,3 +1549,8 @@ func FixCommentTypeLabelWithOutsideLabels() (int64, error) {
15491549

15501550
return res.RowsAffected()
15511551
}
1552+
1553+
// HasOriginalAuthor returns if a comment was migrated and has an original author.
1554+
func (c *Comment) HasOriginalAuthor() bool {
1555+
return c.OriginalAuthor != "" && c.OriginalAuthorID != 0
1556+
}

models/issues/issue.go

+5
Original file line numberDiff line numberDiff line change
@@ -2466,3 +2466,8 @@ func DeleteOrphanedIssues() error {
24662466
}
24672467
return nil
24682468
}
2469+
2470+
// HasOriginalAuthor returns if an issue was migrated and has an original author.
2471+
func (issue *Issue) HasOriginalAuthor() bool {
2472+
return issue.OriginalAuthor != "" && issue.OriginalAuthorID != 0
2473+
}

routers/web/repo/issue.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,11 @@ func NewIssuePost(ctx *context.Context) {
11181118
}
11191119

11201120
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
1121-
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue) (issues_model.RoleDescriptor, error) {
1121+
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue, hasOriginalAuthor bool) (issues_model.RoleDescriptor, error) {
1122+
if hasOriginalAuthor {
1123+
return issues_model.RoleDescriptorNone, nil
1124+
}
1125+
11221126
perm, err := access_model.GetUserRepoPermission(ctx, repo, poster)
11231127
if err != nil {
11241128
return issues_model.RoleDescriptorNone, err
@@ -1420,7 +1424,7 @@ func ViewIssue(ctx *context.Context) {
14201424
// check if dependencies can be created across repositories
14211425
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
14221426

1423-
if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue); err != nil {
1427+
if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue, issue.HasOriginalAuthor()); err != nil {
14241428
ctx.ServerError("roleDescriptor", err)
14251429
return
14261430
}
@@ -1459,7 +1463,7 @@ func ViewIssue(ctx *context.Context) {
14591463
continue
14601464
}
14611465

1462-
comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue)
1466+
comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue, comment.HasOriginalAuthor())
14631467
if err != nil {
14641468
ctx.ServerError("roleDescriptor", err)
14651469
return
@@ -1558,7 +1562,7 @@ func ViewIssue(ctx *context.Context) {
15581562
continue
15591563
}
15601564

1561-
c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue)
1565+
c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue, c.HasOriginalAuthor())
15621566
if err != nil {
15631567
ctx.ServerError("roleDescriptor", err)
15641568
return

0 commit comments

Comments
 (0)