diff options
author | Giteabot <teabot@gitea.io> | 2023-11-14 21:50:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-14 14:50:05 +0100 |
commit | 09efce9da2c108cc5b029d352514f9a505216b58 (patch) | |
tree | 6af5daab58b29d1317cbb722dfe407952302a8f5 /tests | |
parent | 124a9957d086a054f45ca79ea5c5b6b6461a7f56 (diff) | |
download | gitea-09efce9da2c108cc5b029d352514f9a505216b58.tar.gz gitea-09efce9da2c108cc5b029d352514f9a505216b58.zip |
enable system users for comment.LoadPoster (#28014) (#28032)
Backport #28014 by @earl-warren
System users (Ghost, ActionsUser, etc) have a negative id and may be the
author of a comment, either because it was created by a now deleted user
or via an action using a transient token.
The GetPossibleUserByID function has special cases related to system
users and will not fail if given a negative id.
Refs: https://codeberg.org/forgejo/forgejo/issues/1425
(cherry picked from commit 6a2d2fa24390116d31ae2507c0a93d423f690b7b)
Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/api_comment_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/integration/api_comment_test.go b/tests/integration/api_comment_test.go index ee648210e5..0be4896105 100644 --- a/tests/integration/api_comment_test.go +++ b/tests/integration/api_comment_test.go @@ -136,6 +136,43 @@ func TestAPIGetComment(t *testing.T) { assert.Equal(t, expect.Created.Unix(), apiComment.Created.Unix()) } +func TestAPIGetSystemUserComment(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) + repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + + for _, systemUser := range []*user_model.User{ + user_model.NewGhostUser(), + user_model.NewActionsUser(), + } { + body := fmt.Sprintf("Hello %s", systemUser.Name) + comment, err := issues_model.CreateComment(db.DefaultContext, &issues_model.CreateCommentOptions{ + Type: issues_model.CommentTypeComment, + Doer: systemUser, + Repo: repo, + Issue: issue, + Content: body, + }) + assert.NoError(t, err) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID) + resp := MakeRequest(t, req, http.StatusOK) + + var apiComment api.Comment + DecodeJSON(t, resp, &apiComment) + + if assert.NotNil(t, apiComment.Poster) { + if assert.Equal(t, systemUser.ID, apiComment.Poster.ID) { + assert.NoError(t, comment.LoadPoster(db.DefaultContext)) + assert.Equal(t, systemUser.Name, apiComment.Poster.UserName) + } + } + assert.Equal(t, body, apiComment.Body) + } +} + func TestAPIEditComment(t *testing.T) { defer tests.PrepareTestEnv(t)() const newCommentBody = "This is the new comment body" |