Skip to content

Commit 0ab22a1

Browse files
Zettat123zeripathlunny
authored
fix incorrect role labels for migrated issues and comments (#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: zeripath <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 2c04595 commit 0ab22a1

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

models/issues/comment.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,3 +1244,8 @@ func FixCommentTypeLabelWithOutsideLabels(ctx context.Context) (int64, error) {
12441244

12451245
return res.RowsAffected()
12461246
}
1247+
1248+
// HasOriginalAuthor returns if a comment was migrated and has an original author.
1249+
func (c *Comment) HasOriginalAuthor() bool {
1250+
return c.OriginalAuthor != "" && c.OriginalAuthorID != 0
1251+
}

models/issues/issue.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,3 +2403,8 @@ func DeleteOrphanedIssues(ctx context.Context) error {
24032403
}
24042404
return nil
24052405
}
2406+
2407+
// HasOriginalAuthor returns if an issue was migrated and has an original author.
2408+
func (issue *Issue) HasOriginalAuthor() bool {
2409+
return issue.OriginalAuthor != "" && issue.OriginalAuthorID != 0
2410+
}

routers/web/repo/issue.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,11 @@ func NewIssuePost(ctx *context.Context) {
11421142
}
11431143

11441144
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
1145-
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue) (issues_model.RoleDescriptor, error) {
1145+
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue, hasOriginalAuthor bool) (issues_model.RoleDescriptor, error) {
1146+
if hasOriginalAuthor {
1147+
return issues_model.RoleDescriptorNone, nil
1148+
}
1149+
11461150
perm, err := access_model.GetUserRepoPermission(ctx, repo, poster)
11471151
if err != nil {
11481152
return issues_model.RoleDescriptorNone, err
@@ -1444,7 +1448,7 @@ func ViewIssue(ctx *context.Context) {
14441448
// check if dependencies can be created across repositories
14451449
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
14461450

1447-
if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue); err != nil {
1451+
if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue, issue.HasOriginalAuthor()); err != nil {
14481452
ctx.ServerError("roleDescriptor", err)
14491453
return
14501454
}
@@ -1483,7 +1487,7 @@ func ViewIssue(ctx *context.Context) {
14831487
continue
14841488
}
14851489

1486-
comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue)
1490+
comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue, comment.HasOriginalAuthor())
14871491
if err != nil {
14881492
ctx.ServerError("roleDescriptor", err)
14891493
return
@@ -1582,7 +1586,7 @@ func ViewIssue(ctx *context.Context) {
15821586
continue
15831587
}
15841588

1585-
c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue)
1589+
c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue, c.HasOriginalAuthor())
15861590
if err != nil {
15871591
ctx.ServerError("roleDescriptor", err)
15881592
return

0 commit comments

Comments
 (0)