summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2019-12-01 23:57:24 +0100
committertechknowlogick <techknowlogick@gitea.io>2019-12-01 17:57:24 -0500
commit668eaf95d581f68507523563d0701000a4505055 (patch)
tree4a0bf0aea58ca92f7fde2af0881dd518861512cd /routers
parent674bc772fb213e2b79478438d16835d387865ac3 (diff)
downloadgitea-668eaf95d581f68507523563d0701000a4505055.tar.gz
gitea-668eaf95d581f68507523563d0701000a4505055.zip
[Feature] Custom Reactions (#8886)
* add [ui] Reactions * move contend check from form to go functions * use else if * check if reaction is allowed only on react (so previous custom reaction can be still removed) * use $.AllowedReactions in templates * use ctx.Flash.Error * use it there too * add redirection * back to server error because a wrong reaction is a template issue ... * add emoji list link * add docs entry * small wording nit suggestions from @jolheiser - thx * same reactions as github * fix PR reactions * handle error so template JS could check * Add Integrations Test * add REACTIONS setting to cheat-sheet doc page
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/issue.go13
-rw-r--r--routers/repo/pull.go1
2 files changed, 14 insertions, 0 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 739370da69..a2f4022a73 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -673,6 +673,7 @@ func ViewIssue(ctx *context.Context) {
}
}
ctx.Data["IssueWatch"] = iw
+ ctx.Data["AllowedReactions"] = setting.UI.Reactions
issue.RenderedContent = string(markdown.Render([]byte(issue.Content), ctx.Repo.RepoLink,
ctx.Repo.Repository.ComposeMetas()))
@@ -1447,6 +1448,12 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) {
switch ctx.Params(":action") {
case "react":
+ if !util.IsStringInSlice(form.Content, setting.UI.Reactions) {
+ err := fmt.Errorf("ChangeIssueReaction: '%s' is not an allowed reaction", form.Content)
+ ctx.ServerError(err.Error(), err)
+ return
+ }
+
reaction, err := models.CreateIssueReaction(ctx.User, issue, form.Content)
if err != nil {
log.Info("CreateIssueReaction: %s", err)
@@ -1542,6 +1549,12 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) {
switch ctx.Params(":action") {
case "react":
+ if !util.IsStringInSlice(form.Content, setting.UI.Reactions) {
+ err := fmt.Errorf("ChangeIssueReaction: '%s' is not an allowed reaction", form.Content)
+ ctx.ServerError(err.Error(), err)
+ return
+ }
+
reaction, err := models.CreateCommentReaction(ctx.User, comment.Issue, comment, form.Content)
if err != nil {
log.Info("CreateCommentReaction: %s", err)
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 0ff077b462..78406de8ac 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -422,6 +422,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
ctx.Data["NumCommits"] = compareInfo.Commits.Len()
ctx.Data["NumFiles"] = compareInfo.NumFiles
+ ctx.Data["AllowedReactions"] = setting.UI.Reactions
return compareInfo
}