summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLanre Adelowo <adelowomailbox@gmail.com>2019-02-18 21:55:04 +0100
committerLauris BH <lauris@nix.lv>2019-02-18 22:55:04 +0200
commit44114b38e601c8bf44f575daef1d0e0597f37d1d (patch)
treed2d271b31bff505a09c2faf04d5fea69a9f9d58c /modules
parent64ce159a6eacc81962d07a8f5ef7f69c17365363 (diff)
downloadgitea-44114b38e601c8bf44f575daef1d0e0597f37d1d.tar.gz
gitea-44114b38e601c8bf44f575daef1d0e0597f37d1d.zip
Implement "conversation lock" for issue comments (#5073)
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/repo_form.go27
-rw-r--r--modules/auth/repo_form_test.go25
-rw-r--r--modules/setting/setting.go12
3 files changed, 64 insertions, 0 deletions
diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go
index 1a67f2b884..0a97b08c71 100644
--- a/modules/auth/repo_form.go
+++ b/modules/auth/repo_form.go
@@ -10,6 +10,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/utils"
"github.com/Unknwon/com"
@@ -308,6 +309,32 @@ func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) bindi
return validate(errs, ctx.Data, f, ctx.Locale)
}
+// IssueLockForm form for locking an issue
+type IssueLockForm struct {
+ Reason string `binding:"Required"`
+}
+
+// Validate validates the fields
+func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
+ return validate(errs, ctx.Data, i, ctx.Locale)
+}
+
+// HasValidReason checks to make sure that the reason submitted in
+// the form matches any of the values in the config
+func (i IssueLockForm) HasValidReason() bool {
+ if strings.TrimSpace(i.Reason) == "" {
+ return true
+ }
+
+ for _, v := range setting.Repository.Issue.LockReasons {
+ if v == i.Reason {
+ return true
+ }
+ }
+
+ return false
+}
+
// _____ .__.__ __
// / \ |__| | ____ _______/ |_ ____ ____ ____
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
diff --git a/modules/auth/repo_form_test.go b/modules/auth/repo_form_test.go
index f6223d6c8a..a3369b006e 100644
--- a/modules/auth/repo_form_test.go
+++ b/modules/auth/repo_form_test.go
@@ -7,6 +7,7 @@ package auth
import (
"testing"
+ "code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
@@ -39,3 +40,27 @@ func TestSubmitReviewForm_IsEmpty(t *testing.T) {
assert.Equal(t, v.expected, v.form.HasEmptyContent())
}
}
+
+func TestIssueLock_HasValidReason(t *testing.T) {
+
+ // Init settings
+ _ = setting.Repository
+
+ cases := []struct {
+ form IssueLockForm
+ expected bool
+ }{
+ {IssueLockForm{""}, true}, // an empty reason is accepted
+ {IssueLockForm{"Off-topic"}, true},
+ {IssueLockForm{"Too heated"}, true},
+ {IssueLockForm{"Spam"}, true},
+ {IssueLockForm{"Resolved"}, true},
+
+ {IssueLockForm{"ZZZZ"}, false},
+ {IssueLockForm{"I want to lock this issue"}, false},
+ }
+
+ for _, v := range cases {
+ assert.Equal(t, v.expected, v.form.HasValidReason())
+ }
+}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index d3b45ec29d..5f65570540 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -227,6 +227,11 @@ var (
PullRequest struct {
WorkInProgressPrefixes []string
} `ini:"repository.pull-request"`
+
+ // Issue Setting
+ Issue struct {
+ LockReasons []string
+ } `ini:"repository.issue"`
}{
AnsiCharset: "",
ForcePrivate: false,
@@ -279,6 +284,13 @@ var (
}{
WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
},
+
+ // Issue settings
+ Issue: struct {
+ LockReasons []string
+ }{
+ LockReasons: strings.Split("Too heated,Off-topic,Spam,Resolved", ","),
+ },
}
RepoRootPath string
ScriptType = "bash"