diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2019-09-20 02:45:38 -0300 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-09-20 01:45:38 -0400 |
commit | 2a2b46c62ee0ac2b42b8bd0f28e05642d0cee25b (patch) | |
tree | 1b71938c5d9931808c336062859f6c1fb82b9c7a /routers | |
parent | 8a0379d68aa723be9cf1b304068e6b0d098b8a6d (diff) | |
download | gitea-2a2b46c62ee0ac2b42b8bd0f28e05642d0cee25b.tar.gz gitea-2a2b46c62ee0ac2b42b8bd0f28e05642d0cee25b.zip |
Reference issues from pull requests and other issues (#8137)
* Update ref comment
* Generate comment on simple ref
* Make fmt + remove unneeded repo load
* Add TODO comments
* Add ref-check in issue creation; re-arrange template
* Make unit tests pass; rearrange code
* Make fmt
* Filter out xref comment if user can't see the referencing issue
* Add TODOs
* Add cross reference
* Rearrange code; add cross-repository references
* Striketrhough obsolete references
* Remove unnecesary TODO
* Add "not supported" note
* Support for edits and deletes, and issue title
* Revert changes to go.mod
* Fix fmt
* Add support for xref from API
* Add first integration test
* Add integration tests
* Correct formatting
* Fix add comment test
* Add migration
* Remove outdated comments; fix typo
* Some code refactoring and rearranging
* Rename findCrossReferences to createCrossReferences
* Delete xrefs when repository is deleted
* Corrections as suggested by @lafriks
* Prepare for merge
* Fix log for errors
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/issue.go | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 4ae791221c..b9083e20e9 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -643,9 +643,13 @@ func ViewIssue(ctx *context.Context) { ctx.Data["RequireTribute"] = true renderAttachmentSettings(ctx) - err = issue.LoadAttributes() - if err != nil { - ctx.ServerError("GetIssueByIndex", err) + if err = issue.LoadAttributes(); err != nil { + ctx.ServerError("LoadAttributes", err) + return + } + + if err = filterXRefComments(ctx, issue); err != nil { + ctx.ServerError("filterXRefComments", err) return } @@ -1572,3 +1576,28 @@ func addParticipant(poster *models.User, participants []*models.User) []*models. } return append(participants, poster) } + +func filterXRefComments(ctx *context.Context, issue *models.Issue) error { + // Remove comments that the user has no permissions to see + for i := 0; i < len(issue.Comments); { + c := issue.Comments[i] + if models.CommentTypeIsRef(c.Type) && c.RefRepoID != issue.RepoID && c.RefRepoID != 0 { + var err error + // Set RefRepo for description in template + c.RefRepo, err = models.GetRepositoryByID(c.RefRepoID) + if err != nil { + return err + } + perm, err := models.GetUserRepoPermission(c.RefRepo, ctx.User) + if err != nil { + return err + } + if !perm.CanReadIssuesOrPulls(c.RefIsPull) { + issue.Comments = append(issue.Comments[:i], issue.Comments[i+1:]...) + continue + } + } + i++ + } + return nil +} |