mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-19 15:40:50 +00:00
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Closes #2415 Permissions checks are already done by the callee, which also do more correct permission checks. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7835 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Maxim Slipenko <maks1ms@altlinux.org> Co-committed-by: Maxim Slipenko <maks1ms@altlinux.org>
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forgejo.org/models/db"
|
|
issues_model "forgejo.org/models/issues"
|
|
user_model "forgejo.org/models/user"
|
|
notify_service "forgejo.org/services/notify"
|
|
)
|
|
|
|
// ClearLabels clears all of an issue's labels
|
|
func ClearLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User) error {
|
|
if err := issues_model.ClearIssueLabels(ctx, issue, doer); err != nil {
|
|
return err
|
|
}
|
|
|
|
notify_service.IssueClearLabels(ctx, doer, issue)
|
|
|
|
return nil
|
|
}
|
|
|
|
// AddLabel adds a new label to the issue.
|
|
func AddLabel(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
|
|
if err := issues_model.NewIssueLabel(ctx, issue, label, doer); err != nil {
|
|
return err
|
|
}
|
|
|
|
notify_service.IssueChangeLabels(ctx, doer, issue, []*issues_model.Label{label}, nil)
|
|
return nil
|
|
}
|
|
|
|
// AddLabels adds a list of new labels to the issue.
|
|
func AddLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
|
|
if err := issues_model.NewIssueLabels(ctx, issue, labels, doer); err != nil {
|
|
return err
|
|
}
|
|
|
|
notify_service.IssueChangeLabels(ctx, doer, issue, labels, nil)
|
|
return nil
|
|
}
|
|
|
|
// RemoveLabel removes a label from issue by given ID.
|
|
func RemoveLabel(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
|
|
dbCtx, committer, err := db.TxContext(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer committer.Close()
|
|
|
|
if err := issue.LoadRepo(dbCtx); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := issues_model.DeleteIssueLabel(dbCtx, issue, label, doer); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := committer.Commit(); err != nil {
|
|
return err
|
|
}
|
|
|
|
notify_service.IssueChangeLabels(ctx, doer, issue, nil, []*issues_model.Label{label})
|
|
return nil
|
|
}
|
|
|
|
// ReplaceLabels removes all current labels and add new labels to the issue.
|
|
func ReplaceLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
|
|
old, err := issues_model.GetLabelsByIssueID(ctx, issue.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := issues_model.ReplaceIssueLabels(ctx, issue, labels, doer); err != nil {
|
|
return err
|
|
}
|
|
|
|
notify_service.IssueChangeLabels(ctx, doer, issue, labels, old)
|
|
return nil
|
|
}
|