aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-05-30 17:26:51 +0200
committerGitHub <noreply@github.com>2023-05-30 15:26:51 +0000
commit1b115296d3f2f396eebcb40d79aea814d282edaf (patch)
tree6cb848392a0ddd785d12b1fa5dd569015fe9d221 /models
parentfaae819f5d8a662ec2df88205ab6d9b1871f1dd1 (diff)
downloadgitea-1b115296d3f2f396eebcb40d79aea814d282edaf.tar.gz
gitea-1b115296d3f2f396eebcb40d79aea814d282edaf.zip
Followup to pinned Issues (#24945)
This addressees some things from #24406 that came up after the PR was merged. Mostly from @delvh. --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'models')
-rw-r--r--models/issues/issue.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 5015824e9b..eab18f4892 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -687,6 +687,8 @@ func (issue *Issue) HasOriginalAuthor() bool {
return issue.OriginalAuthor != "" && issue.OriginalAuthorID != 0
}
+var ErrIssueMaxPinReached = util.NewInvalidArgumentErrorf("the max number of pinned issues has been readched")
+
// IsPinned returns if a Issue is pinned
func (issue *Issue) IsPinned() bool {
return issue.PinOrder != 0
@@ -707,7 +709,7 @@ func (issue *Issue) Pin(ctx context.Context, user *user_model.User) error {
// Check if the maximum allowed Pins reached
if maxPin >= setting.Repository.Issue.MaxPinned {
- return fmt.Errorf("You have reached the max number of pinned Issues")
+ return ErrIssueMaxPinReached
}
_, err = db.GetEngine(ctx).Table("issue").
@@ -856,10 +858,15 @@ func GetPinnedIssues(ctx context.Context, repoID int64, isPull bool) ([]*Issue,
// IsNewPinnedAllowed returns if a new Issue or Pull request can be pinned
func IsNewPinAllowed(ctx context.Context, repoID int64, isPull bool) (bool, error) {
var maxPin int
- _, err := db.GetEngine(ctx).SQL("SELECT MAX(pin_order) FROM issue WHERE repo_id = ? AND is_pull = ?", repoID, isPull).Get(&maxPin)
+ _, err := db.GetEngine(ctx).SQL("SELECT COUNT(pin_order) FROM issue WHERE repo_id = ? AND is_pull = ? AND pin_order > 0", repoID, isPull).Get(&maxPin)
if err != nil {
return false, err
}
return maxPin < setting.Repository.Issue.MaxPinned, nil
}
+
+// IsErrIssueMaxPinReached returns if the error is, that the User can't pin more Issues
+func IsErrIssueMaxPinReached(err error) bool {
+ return err == ErrIssueMaxPinReached
+}