Skip to content

Commit 40e533c

Browse files
committed
Remove all lock reason checks
1 parent baf6217 commit 40e533c

File tree

6 files changed

+1
-53
lines changed

6 files changed

+1
-53
lines changed

models/issues/issue_lock.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ package issues
55

66
import (
77
"context"
8-
"slices"
9-
"strings"
108

119
"code.gitea.io/gitea/models/db"
1210
user_model "code.gitea.io/gitea/models/user"
13-
"code.gitea.io/gitea/modules/setting"
1411
)
1512

1613
// IssueLockOptions defines options for locking and/or unlocking an issue/PR
@@ -67,13 +64,3 @@ func updateIssueLock(ctx context.Context, opts *IssueLockOptions, lock bool) err
6764

6865
return committer.Commit()
6966
}
70-
71-
// IsValidReason checks to make sure that the reason submitted
72-
// matches any of the values in the config
73-
func IsValidReason(reason string) bool {
74-
if strings.TrimSpace(reason) == "" {
75-
return true
76-
}
77-
78-
return slices.Contains(setting.Repository.Issue.LockReasons, reason)
79-
}

models/issues/issue_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -466,23 +466,3 @@ func TestMigrate_CreateIssuesIsPullFalse(t *testing.T) {
466466
func TestMigrate_CreateIssuesIsPullTrue(t *testing.T) {
467467
assertCreateIssues(t, true)
468468
}
469-
470-
func TestIssueLock_IsValidReason(t *testing.T) {
471-
cases := []struct {
472-
reason string
473-
expected bool
474-
}{
475-
{"", true}, // an empty reason is accepted
476-
{"Off-topic", true},
477-
{"Too heated", true},
478-
{"Spam", true},
479-
{"Resolved", true},
480-
481-
{"ZZZZ", false},
482-
{"I want to lock this issue", false},
483-
}
484-
485-
for _, v := range cases {
486-
assert.Equal(t, v.expected, issues_model.IsValidReason(v.reason))
487-
}
488-
}

routers/api/v1/repo/issue_lock.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ func LockIssue(ctx *context.APIContext) {
5050
// responses:
5151
// "204":
5252
// "$ref": "#/responses/empty"
53-
// "400":
54-
// "$ref": "#/responses/error"
5553
// "403":
5654
// "$ref": "#/responses/forbidden"
5755
// "404":
@@ -64,11 +62,6 @@ func LockIssue(ctx *context.APIContext) {
6462
reasonParts[0] = caser.String(reasonParts[0])
6563
reason = strings.Join(reasonParts, " ")
6664

67-
if !issues_model.IsValidReason(reason) {
68-
ctx.APIError(http.StatusBadRequest, errors.New("reason not valid"))
69-
return
70-
}
71-
7265
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
7366
if err != nil {
7467
if issues_model.IsErrIssueNotExist(err) {

routers/web/repo/issue_lock.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ func LockIssue(ctx *context.Context) {
2424
return
2525
}
2626

27-
if !issues_model.IsValidReason(form.Reason) {
28-
ctx.JSONError(ctx.Tr("repo.issues.lock.unknown_reason"))
29-
return
30-
}
31-
3227
if err := issues_model.LockIssue(ctx, &issues_model.IssueLockOptions{
3328
Doer: ctx.Doer,
3429
Issue: issue,

templates/swagger/v1_json.tmpl

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_issue_lock_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ func TestAPILockIssue(t *testing.T) {
3131
session := loginUser(t, owner.Name)
3232
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
3333

34-
// check invalid reason
35-
req := NewRequestWithJSON(t, "PUT", urlStr, api.LockIssueOption{Reason: "Not valid"}).AddTokenAuth(token)
36-
MakeRequest(t, req, http.StatusBadRequest)
37-
3834
// check lock issue
39-
req = NewRequestWithJSON(t, "PUT", urlStr, api.LockIssueOption{Reason: "Spam"}).AddTokenAuth(token)
35+
req := NewRequestWithJSON(t, "PUT", urlStr, api.LockIssueOption{Reason: "Spam"}).AddTokenAuth(token)
4036
MakeRequest(t, req, http.StatusNoContent)
4137
issueAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
4238
assert.True(t, issueAfter.IsLocked)

0 commit comments

Comments
 (0)