Skip to content

Commit 156ea96

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Fix cli command restore-repo: "units" should be splitted to string slice, to match the old behavior and match the dump-repo's behavior (go-gitea#20183) [skip ci] Updated translations via Crowdin Fix `dump-repo` git init, fix wrong error type for NullDownloader (go-gitea#20182) Check if project has the same repository id with issue when assign project to issue (go-gitea#20133) [skip ci] Updated translations via Crowdin
2 parents bf611b1 + 7c1f18a commit 156ea96

File tree

16 files changed

+109
-29
lines changed

16 files changed

+109
-29
lines changed

cmd/dump_repo.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/modules/convert"
13+
"code.gitea.io/gitea/modules/git"
1314
"code.gitea.io/gitea/modules/log"
1415
base "code.gitea.io/gitea/modules/migration"
1516
"code.gitea.io/gitea/modules/setting"
@@ -83,6 +84,11 @@ func runDumpRepository(ctx *cli.Context) error {
8384
return err
8485
}
8586

87+
// migrations.GiteaLocalUploader depends on git module
88+
if err := git.InitSimple(context.Background()); err != nil {
89+
return err
90+
}
91+
8692
log.Info("AppPath: %s", setting.AppPath)
8793
log.Info("AppWorkPath: %s", setting.AppWorkPath)
8894
log.Info("Custom path: %s", setting.CustomPath)
@@ -128,7 +134,9 @@ func runDumpRepository(ctx *cli.Context) error {
128134
} else {
129135
units := strings.Split(ctx.String("units"), ",")
130136
for _, unit := range units {
131-
switch strings.ToLower(unit) {
137+
switch strings.ToLower(strings.TrimSpace(unit)) {
138+
case "":
139+
continue
132140
case "wiki":
133141
opts.Wiki = true
134142
case "issues":
@@ -145,6 +153,8 @@ func runDumpRepository(ctx *cli.Context) error {
145153
opts.Comments = true
146154
case "pull_requests":
147155
opts.PullRequests = true
156+
default:
157+
return errors.New("invalid unit: " + unit)
148158
}
149159
}
150160
}

cmd/restore_repo.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"errors"
99
"net/http"
10+
"strings"
1011

1112
"code.gitea.io/gitea/modules/log"
1213
"code.gitea.io/gitea/modules/private"
@@ -37,10 +38,10 @@ var CmdRestoreRepository = cli.Command{
3738
Value: "",
3839
Usage: "Restore destination repository name",
3940
},
40-
cli.StringSliceFlag{
41+
cli.StringFlag{
4142
Name: "units",
42-
Value: nil,
43-
Usage: `Which items will be restored, one or more units should be repeated with this flag.
43+
Value: "",
44+
Usage: `Which items will be restored, one or more units should be separated as comma.
4445
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
4546
},
4647
cli.BoolFlag{
@@ -55,13 +56,16 @@ func runRestoreRepository(c *cli.Context) error {
5556
defer cancel()
5657

5758
setting.LoadFromExisting()
58-
59+
var units []string
60+
if s := c.String("units"); s != "" {
61+
units = strings.Split(s, ",")
62+
}
5963
statusCode, errStr := private.RestoreRepo(
6064
ctx,
6165
c.String("repo_dir"),
6266
c.String("owner_name"),
6367
c.String("repo_name"),
64-
c.StringSlice("units"),
68+
units,
6569
c.Bool("validation"),
6670
)
6771
if statusCode == http.StatusOK {

models/issues/issue_project.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64
124124
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
125125
oldProjectID := issue.projectID(ctx)
126126

127+
// Only check if we add a new project and not remove it.
128+
if newProjectID > 0 {
129+
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
130+
if err != nil {
131+
return err
132+
}
133+
if newProject.RepoID != issue.RepoID {
134+
return fmt.Errorf("issue's repository is not the same as project's repository")
135+
}
136+
}
137+
127138
if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
128139
return err
129140
}

models/issues/milestone.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ func NewMilestone(m *Milestone) (err error) {
124124
return committer.Commit()
125125
}
126126

127+
// HasMilestoneByRepoID returns if the milestone exists in the repository.
128+
func HasMilestoneByRepoID(ctx context.Context, repoID, id int64) (bool, error) {
129+
return db.GetEngine(ctx).ID(id).Where("repo_id=?", repoID).Exist(new(Milestone))
130+
}
131+
127132
// GetMilestoneByRepoID returns the milestone in a repository.
128133
func GetMilestoneByRepoID(ctx context.Context, repoID, id int64) (*Milestone, error) {
129134
m := new(Milestone)

modules/indexer/code/elastic_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (b *ElasticSearchIndexer) Index(ctx context.Context, repo *repo_model.Repos
284284
reqs := make([]elastic.BulkableRequest, 0)
285285
if len(changes.Updates) > 0 {
286286
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
287-
if err := git.EnsureValidGitRepository(git.DefaultContext, repo.RepoPath()); err != nil {
287+
if err := git.EnsureValidGitRepository(ctx, repo.RepoPath()); err != nil {
288288
log.Error("Unable to open git repo: %s for %-v: %v", repo.RepoPath(), repo, err)
289289
return err
290290
}

modules/migration/null_downloader.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,52 @@ func (n NullDownloader) SetContext(_ context.Context) {}
1919

2020
// GetRepoInfo returns a repository information
2121
func (n NullDownloader) GetRepoInfo() (*Repository, error) {
22-
return nil, &ErrNotSupported{Entity: "RepoInfo"}
22+
return nil, ErrNotSupported{Entity: "RepoInfo"}
2323
}
2424

2525
// GetTopics return repository topics
2626
func (n NullDownloader) GetTopics() ([]string, error) {
27-
return nil, &ErrNotSupported{Entity: "Topics"}
27+
return nil, ErrNotSupported{Entity: "Topics"}
2828
}
2929

3030
// GetMilestones returns milestones
3131
func (n NullDownloader) GetMilestones() ([]*Milestone, error) {
32-
return nil, &ErrNotSupported{Entity: "Milestones"}
32+
return nil, ErrNotSupported{Entity: "Milestones"}
3333
}
3434

3535
// GetReleases returns releases
3636
func (n NullDownloader) GetReleases() ([]*Release, error) {
37-
return nil, &ErrNotSupported{Entity: "Releases"}
37+
return nil, ErrNotSupported{Entity: "Releases"}
3838
}
3939

4040
// GetLabels returns labels
4141
func (n NullDownloader) GetLabels() ([]*Label, error) {
42-
return nil, &ErrNotSupported{Entity: "Labels"}
42+
return nil, ErrNotSupported{Entity: "Labels"}
4343
}
4444

4545
// GetIssues returns issues according start and limit
4646
func (n NullDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
47-
return nil, false, &ErrNotSupported{Entity: "Issues"}
47+
return nil, false, ErrNotSupported{Entity: "Issues"}
4848
}
4949

5050
// GetComments returns comments of an issue or PR
5151
func (n NullDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
52-
return nil, false, &ErrNotSupported{Entity: "Comments"}
52+
return nil, false, ErrNotSupported{Entity: "Comments"}
5353
}
5454

5555
// GetAllComments returns paginated comments
5656
func (n NullDownloader) GetAllComments(page, perPage int) ([]*Comment, bool, error) {
57-
return nil, false, &ErrNotSupported{Entity: "AllComments"}
57+
return nil, false, ErrNotSupported{Entity: "AllComments"}
5858
}
5959

6060
// GetPullRequests returns pull requests according page and perPage
6161
func (n NullDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
62-
return nil, false, &ErrNotSupported{Entity: "PullRequests"}
62+
return nil, false, ErrNotSupported{Entity: "PullRequests"}
6363
}
6464

6565
// GetReviews returns pull requests review
6666
func (n NullDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
67-
return nil, &ErrNotSupported{Entity: "Reviews"}
67+
return nil, ErrNotSupported{Entity: "Reviews"}
6868
}
6969

7070
// FormatCloneURL add authentication into remote URLs

options/locale/locale_ja-JP.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,8 @@ pulls.auto_merge_canceled_schedule=このプルリクエストの自動マージ
16091609
pulls.auto_merge_newly_scheduled_comment=`が、すべてのチェックが成功すると自動マージを行うよう、このプルリクエストをスケジュール %[1]s`
16101610
pulls.auto_merge_canceled_schedule_comment=`が、すべてのチェックが成功したときのプルリクエストの自動マージをキャンセル %[1]s`
16111611

1612+
pulls.delete.title=このプルリクエストを削除しますか?
1613+
pulls.delete.text=本当にこのプルリクエストを削除しますか? (これはすべてのコンテンツを完全に削除します。 保存しておきたい場合は、代わりにクローズすることを検討してください)
16121614

16131615
milestones.new=新しいマイルストーン
16141616
milestones.closed=%s にクローズ

options/locale/locale_pt-BR.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ home=Inicio
22
dashboard=Painel
33
explore=Explorar
44
help=Ajuda
5+
logo=Logotipo
56
sign_in=Acessar
67
sign_in_with=Acessar com
78
sign_out=Sair
@@ -441,6 +442,7 @@ size_error=`deve ser do tamanho %s.`
441442
min_size_error=` deve conter pelo menos %s caracteres.`
442443
max_size_error=` deve conter no máximo %s caracteres.`
443444
email_error=` não é um endereço de e-mail válido.`
445+
url_error=`'%s' não é uma URL válida.`
444446
include_error=` deve conter '%s'.`
445447
glob_pattern_error=` padrão glob é inválido: %s.`
446448
regex_pattern_error=` o regex é inválido: %s.`
@@ -714,6 +716,9 @@ generate_token_success=Seu novo token foi gerado. Copie-o agora, pois ele não s
714716
generate_token_name_duplicate=<strong>%s</strong> já foi usado como um nome de aplicativo. Por favor, use outro.
715717
delete_token=Excluir
716718
access_token_deletion=Excluir token de acesso
719+
access_token_deletion_cancel_action=Cancelar
720+
access_token_deletion_confirm_action=Excluir
721+
access_token_deletion_desc=A exclusão de um token revoga o acesso à sua conta para aplicativos que o usam. Continuar?
717722
delete_token_success=O token foi excluído. Os aplicativos que o utilizam já não têm acesso à sua conta.
718723

719724
manage_oauth2_applications=Gerenciar aplicativos OAuth2
@@ -1486,6 +1491,7 @@ pulls.new=Novo pull request
14861491
pulls.view=Ver Pull Request
14871492
pulls.compare_changes=Novo pull request
14881493
pulls.allow_edits_from_maintainers=Permitir edições de mantenedores
1494+
pulls.allow_edits_from_maintainers_err=Falha na atualização
14891495
pulls.compare_changes_desc=Selecione o branch de destino (push) e o branch de origem (pull) para o merge.
14901496
pulls.has_viewed_file=Visto
14911497
pulls.has_changed_since_last_review=Alterado desde a última revisão
@@ -1589,6 +1595,7 @@ pulls.merge_instruction_hint=`Você também pode ver as <a class="show-instructi
15891595
pulls.merge_instruction_step1_desc=No repositório do seu projeto, crie um novo branch e teste as alterações.
15901596
pulls.merge_instruction_step2_desc=Faça merge das alterações e atualize no Gitea.
15911597

1598+
pulls.auto_merge_button_when_succeed=(Quando a verificação for bem-sucedida)
15921599

15931600

15941601

routers/api/v1/repo/pull_review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
886886
return
887887
}
888888

889-
_, err := pull_service.DismissReview(ctx, review.ID, msg, ctx.Doer, isDismiss)
889+
_, err := pull_service.DismissReview(ctx, review.ID, ctx.Repo.Repository.ID, msg, ctx.Doer, isDismiss)
890890
if err != nil {
891891
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
892892
return

routers/web/repo/issue.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,8 @@ func NewIssue(ctx *context.Context) {
803803
body := ctx.FormString("body")
804804
ctx.Data["BodyQuery"] = body
805805

806-
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects)
806+
isProjectsEnabled := ctx.Repo.CanRead(unit.TypeProjects)
807+
ctx.Data["IsProjectsEnabled"] = isProjectsEnabled
807808
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
808809
upload.AddUploadContext(ctx, "comment")
809810

@@ -819,7 +820,7 @@ func NewIssue(ctx *context.Context) {
819820
}
820821

821822
projectID := ctx.FormInt64("project")
822-
if projectID > 0 {
823+
if projectID > 0 && isProjectsEnabled {
823824
project, err := project_model.GetProjectByID(ctx, projectID)
824825
if err != nil {
825826
log.Error("GetProjectByID: %d: %v", projectID, err)
@@ -1043,6 +1044,11 @@ func NewIssuePost(ctx *context.Context) {
10431044
}
10441045

10451046
if projectID > 0 {
1047+
if !ctx.Repo.CanRead(unit.TypeProjects) {
1048+
// User must also be able to see the project.
1049+
ctx.Error(http.StatusBadRequest, "user hasn't permissions to read projects")
1050+
return
1051+
}
10461052
if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil {
10471053
ctx.ServerError("ChangeProjectAssign", err)
10481054
return
@@ -1783,6 +1789,10 @@ func getActionIssues(ctx *context.Context) []*issues_model.Issue {
17831789
issueUnitEnabled := ctx.Repo.CanRead(unit.TypeIssues)
17841790
prUnitEnabled := ctx.Repo.CanRead(unit.TypePullRequests)
17851791
for _, issue := range issues {
1792+
if issue.RepoID != ctx.Repo.Repository.ID {
1793+
ctx.NotFound("some issue's RepoID is incorrect", errors.New("some issue's RepoID is incorrect"))
1794+
return nil
1795+
}
17861796
if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled {
17871797
ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
17881798
return nil

routers/web/repo/projects.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package repo
66

77
import (
8+
"errors"
89
"fmt"
910
"net/http"
1011
"net/url"
@@ -633,10 +634,17 @@ func MoveIssues(ctx *context.Context) {
633634
}
634635

635636
if len(movedIssues) != len(form.Issues) {
636-
ctx.ServerError("IssuesNotFound", err)
637+
ctx.ServerError("some issues do not exist", errors.New("some issues do not exist"))
637638
return
638639
}
639640

641+
for _, issue := range movedIssues {
642+
if issue.RepoID != project.RepoID {
643+
ctx.ServerError("Some issue's repoID is not equal to project's repoID", errors.New("Some issue's repoID is not equal to project's repoID"))
644+
return
645+
}
646+
}
647+
640648
if err = project_model.MoveIssuesOnProjectBoard(board, sortedIssueIDs); err != nil {
641649
ctx.ServerError("MoveIssuesOnProjectBoard", err)
642650
return

routers/web/repo/pull_review.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package repo
66

77
import (
8+
"errors"
89
"fmt"
910
"net/http"
1011

@@ -118,6 +119,11 @@ func UpdateResolveConversation(ctx *context.Context) {
118119
return
119120
}
120121

122+
if comment.Issue.RepoID != ctx.Repo.Repository.ID {
123+
ctx.NotFound("comment's repoID is incorrect", errors.New("comment's repoID is incorrect"))
124+
return
125+
}
126+
121127
var permResult bool
122128
if permResult, err = issues_model.CanMarkConversation(comment.Issue, ctx.Doer); err != nil {
123129
ctx.ServerError("CanMarkConversation", err)
@@ -236,7 +242,7 @@ func SubmitReview(ctx *context.Context) {
236242
// DismissReview dismissing stale review by repo admin
237243
func DismissReview(ctx *context.Context) {
238244
form := web.GetForm(ctx).(*forms.DismissReviewForm)
239-
comm, err := pull_service.DismissReview(ctx, form.ReviewID, form.Message, ctx.Doer, true)
245+
comm, err := pull_service.DismissReview(ctx, form.ReviewID, ctx.Repo.Repository.ID, form.Message, ctx.Doer, true)
240246
if err != nil {
241247
ctx.ServerError("pull_service.DismissReview", err)
242248
return

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ func RegisterRoutes(m *web.Route) {
901901

902902
m.Post("/labels", reqRepoIssuesOrPullsWriter, repo.UpdateIssueLabel)
903903
m.Post("/milestone", reqRepoIssuesOrPullsWriter, repo.UpdateIssueMilestone)
904-
m.Post("/projects", reqRepoIssuesOrPullsWriter, repo.UpdateIssueProject)
904+
m.Post("/projects", reqRepoIssuesOrPullsWriter, reqRepoProjectsReader, repo.UpdateIssueProject)
905905
m.Post("/assignee", reqRepoIssuesOrPullsWriter, repo.UpdateIssueAssignee)
906906
m.Post("/request_review", reqRepoIssuesOrPullsReader, repo.UpdatePullReviewRequest)
907907
m.Post("/dismiss_review", reqRepoAdmin, bindIgnErr(forms.DismissReviewForm{}), repo.DismissReview)

services/issue/milestone.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ import (
1515
)
1616

1717
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error {
18+
// Only check if milestone exists if we don't remove it.
19+
if issue.MilestoneID > 0 {
20+
has, err := issues_model.HasMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
21+
if err != nil {
22+
return fmt.Errorf("HasMilestoneByRepoID: %v", err)
23+
}
24+
if !has {
25+
return fmt.Errorf("HasMilestoneByRepoID: issue doesn't exist")
26+
}
27+
}
28+
1829
if err := issues_model.UpdateIssueCols(ctx, issue, "milestone_id"); err != nil {
1930
return err
2031
}

services/migrations/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) error {
590590
opts.ReleaseAssets = true
591591
} else {
592592
for _, unit := range units {
593-
switch strings.ToLower(unit) {
593+
switch strings.ToLower(strings.TrimSpace(unit)) {
594594
case "":
595595
continue
596596
case "wiki":

0 commit comments

Comments
 (0)