diff options
author | zeripath <art27@cantab.net> | 2021-03-19 13:25:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-19 21:25:14 +0800 |
commit | dace0ce1b191d060976bac08f181ca768fc027a0 (patch) | |
tree | 6258fb4991c3ce80c1d188f76d8d561e859e442a /modules/doctor | |
parent | 54d7b0f8e737cda864af981b29dda5116fc5f9ca (diff) | |
download | gitea-dace0ce1b191d060976bac08f181ca768fc027a0.tar.gz gitea-dace0ce1b191d060976bac08f181ca768fc027a0.zip |
Prevent addition of labels from outside the repository or organisation in issues (#14912)
* Never add labels not from this repository or organisation and remove org labels on transfer
Prevent the addition of labels from outside of the repository or
organisation and remove organisation labels on transfer.
Related #14908
Signed-off-by: Andrew Thornton <art27@cantab.net>
* switch to use sql
Signed-off-by: Andrew Thornton <art27@cantab.net>
* remove AS
Signed-off-by: Andrew Thornton <art27@cantab.net>
* subquery alias
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Give me some AS?
Signed-off-by: Andrew Thornton <art27@cantab.net>
* double AS
Signed-off-by: Andrew Thornton <art27@cantab.net>
* try try again
Signed-off-by: Andrew Thornton <art27@cantab.net>
* once more around the merry go round
Signed-off-by: Andrew Thornton <art27@cantab.net>
* fix api problem
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add outside label consistency check into doctor
This PR adds another consistency check into doctor in order to detect
labels that have been added from outside of repositories and organisations
Fix #14908
Signed-off-by: Andrew Thornton <art27@cantab.net>
* fix migration
Signed-off-by: Andrew Thornton <art27@cantab.net>
* prep for merge
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/doctor')
-rw-r--r-- | modules/doctor/dbconsistency.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/modules/doctor/dbconsistency.go b/modules/doctor/dbconsistency.go index 1e3c7258e3..83d3dc5fe2 100644 --- a/modules/doctor/dbconsistency.go +++ b/modules/doctor/dbconsistency.go @@ -130,6 +130,45 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { logger.Warn("%d label comments with empty labels", count) } } + + // find label comments with labels from outside the repository + count, err = models.CountCommentTypeLabelWithOutsideLabels() + if err != nil { + logger.Critical("Error: %v whilst counting label comments with outside labels", err) + return err + } + if count > 0 { + if autofix { + updatedCount, err := models.FixCommentTypeLabelWithOutsideLabels() + if err != nil { + logger.Critical("Error: %v whilst removing label comments with outside labels", err) + return err + } + log.Info("%d label comments with outside labels removed", updatedCount) + } else { + log.Warn("%d label comments with outside labels", count) + } + } + + // find issue_label with labels from outside the repository + count, err = models.CountIssueLabelWithOutsideLabels() + if err != nil { + logger.Critical("Error: %v whilst counting issue_labels from outside the repository or organisation", err) + return err + } + if count > 0 { + if autofix { + updatedCount, err := models.FixIssueLabelWithOutsideLabels() + if err != nil { + logger.Critical("Error: %v whilst removing issue_labels from outside the repository or organisation", err) + return err + } + logger.Info("%d issue_labels from outside the repository or organisation removed", updatedCount) + } else { + logger.Warn("%d issue_labels from outside the repository or organisation", count) + } + } + // TODO: function to recalc all counters if setting.Database.UsePostgreSQL { |