You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
66 lines
1.5 KiB
6 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package issues
|
||
6 years ago
|
|
||
3 years ago
|
import (
|
||
|
"code.gitea.io/gitea/models/db"
|
||
|
user_model "code.gitea.io/gitea/models/user"
|
||
|
)
|
||
3 years ago
|
|
||
6 years ago
|
// IssueLockOptions defines options for locking and/or unlocking an issue/PR
|
||
|
type IssueLockOptions struct {
|
||
3 years ago
|
Doer *user_model.User
|
||
6 years ago
|
Issue *Issue
|
||
|
Reason string
|
||
|
}
|
||
|
|
||
|
// LockIssue locks an issue. This would limit commenting abilities to
|
||
|
// users with write access to the repo
|
||
|
func LockIssue(opts *IssueLockOptions) error {
|
||
|
return updateIssueLock(opts, true)
|
||
|
}
|
||
|
|
||
|
// UnlockIssue unlocks a previously locked issue.
|
||
|
func UnlockIssue(opts *IssueLockOptions) error {
|
||
|
return updateIssueLock(opts, false)
|
||
|
}
|
||
|
|
||
|
func updateIssueLock(opts *IssueLockOptions, lock bool) error {
|
||
|
if opts.Issue.IsLocked == lock {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
opts.Issue.IsLocked = lock
|
||
|
var commentType CommentType
|
||
|
if opts.Issue.IsLocked {
|
||
|
commentType = CommentTypeLock
|
||
|
} else {
|
||
|
commentType = CommentTypeUnlock
|
||
|
}
|
||
|
|
||
3 years ago
|
ctx, committer, err := db.TxContext()
|
||
|
if err != nil {
|
||
5 years ago
|
return err
|
||
|
}
|
||
3 years ago
|
defer committer.Close()
|
||
5 years ago
|
|
||
3 years ago
|
if err := UpdateIssueCols(ctx, opts.Issue, "is_locked"); err != nil {
|
||
6 years ago
|
return err
|
||
|
}
|
||
|
|
||
4 years ago
|
opt := &CreateCommentOptions{
|
||
6 years ago
|
Doer: opts.Doer,
|
||
|
Issue: opts.Issue,
|
||
|
Repo: opts.Issue.Repo,
|
||
|
Type: commentType,
|
||
|
Content: opts.Reason,
|
||
5 years ago
|
}
|
||
3 years ago
|
if _, err := CreateCommentCtx(ctx, opt); err != nil {
|
||
5 years ago
|
return err
|
||
|
}
|
||
|
|
||
3 years ago
|
return committer.Commit()
|
||
6 years ago
|
}
|