diff options
author | zeripath <art27@cantab.net> | 2021-03-12 17:45:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-12 18:45:49 +0100 |
commit | 42b9b46ad22840966ecac70ae4e319c49fda3d7e (patch) | |
tree | 783581b00b102d6795a57f0c07dac6bd18f42b0e /models/repo_transfer.go | |
parent | ccfb205ad126ac6fa3490e43a8075947e05a731a (diff) | |
download | gitea-42b9b46ad22840966ecac70ae4e319c49fda3d7e.tar.gz gitea-42b9b46ad22840966ecac70ae4e319c49fda3d7e.zip |
Never add labels not from this repository or organisation and remove org labels on transfer (#14928)
* 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
* switch to use sql
* subquery alias
* once more around the merry go round
* fix api problem
Diffstat (limited to 'models/repo_transfer.go')
-rw-r--r-- | models/repo_transfer.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/models/repo_transfer.go b/models/repo_transfer.go index 9f8fd649b6..273dca1c5d 100644 --- a/models/repo_transfer.go +++ b/models/repo_transfer.go @@ -325,6 +325,33 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err e } } + // Delete labels that belong to the old organization and comments that added these labels + if oldOwner.IsOrganization() { + if _, err := sess.Exec(`DELETE FROM issue_label WHERE issue_label.id IN ( + SELECT il_too.id FROM ( + SELECT il_too_too.id + FROM issue_label AS il_too_too + INNER JOIN label ON il_too_too.id = label.id + INNER JOIN issue on issue.id = il_too_too.issue_id + WHERE + issue.repo_id = ? AND (issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != ?)) + ) AS il_too )`, repo.ID, newOwner.ID); err != nil { + return fmt.Errorf("Unable to remove old org labels: %v", err) + } + + if _, err := sess.Exec(`DELETE FROM comment WHERE comment.id IN ( + SELECT il_too.id FROM ( + SELECT com.id + FROM comment AS com + INNER JOIN label ON com.label_id = label.id + INNER JOIN issue on issue.id = com.issue_id + WHERE + com.type = ? AND issue.repo_id = ? AND (issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != ?)) + ) AS il_too)`, CommentTypeLabel, repo.ID, newOwner.ID); err != nil { + return fmt.Errorf("Unable to remove old org label comments: %v", err) + } + } + // Rename remote repository to new path and delete local copy. dir := UserPath(newOwner.Name) |