code.gitea.io/gitea@v1.21.7/routers/web/repo/issue_lock.go (about) 1 // Copyright 2019 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package repo 5 6 import ( 7 issues_model "code.gitea.io/gitea/models/issues" 8 "code.gitea.io/gitea/modules/context" 9 "code.gitea.io/gitea/modules/web" 10 "code.gitea.io/gitea/services/forms" 11 ) 12 13 // LockIssue locks an issue. This would limit commenting abilities to 14 // users with write access to the repo. 15 func LockIssue(ctx *context.Context) { 16 form := web.GetForm(ctx).(*forms.IssueLockForm) 17 issue := GetActionIssue(ctx) 18 if ctx.Written() { 19 return 20 } 21 22 if issue.IsLocked { 23 ctx.JSONError(ctx.Tr("repo.issues.lock_duplicate")) 24 return 25 } 26 27 if !form.HasValidReason() { 28 ctx.JSONError(ctx.Tr("repo.issues.lock.unknown_reason")) 29 return 30 } 31 32 if err := issues_model.LockIssue(&issues_model.IssueLockOptions{ 33 Doer: ctx.Doer, 34 Issue: issue, 35 Reason: form.Reason, 36 }); err != nil { 37 ctx.ServerError("LockIssue", err) 38 return 39 } 40 41 ctx.JSONRedirect(issue.Link()) 42 } 43 44 // UnlockIssue unlocks a previously locked issue. 45 func UnlockIssue(ctx *context.Context) { 46 issue := GetActionIssue(ctx) 47 if ctx.Written() { 48 return 49 } 50 51 if !issue.IsLocked { 52 ctx.JSONError(ctx.Tr("repo.issues.unlock_error")) 53 return 54 } 55 56 if err := issues_model.UnlockIssue(&issues_model.IssueLockOptions{ 57 Doer: ctx.Doer, 58 Issue: issue, 59 }); err != nil { 60 ctx.ServerError("UnlockIssue", err) 61 return 62 } 63 64 ctx.JSONRedirect(issue.Link()) 65 }