Skip to content

Commit 2dc43be

Browse files
committed
fix
1 parent ed67149 commit 2dc43be

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

Diff for: models/issues/issue_project.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
113113
}
114114
newColumnID = newDefaultColumn.ID
115115
}
116-
if !newProject.CanBeAccessedByOwnerRepo(issue.Repo.OwnerID, issue.Repo.ID) {
116+
if !newProject.CanBeAccessedByOwnerRepo(issue.Repo.OwnerID, issue.Repo) {
117117
return util.NewPermissionDeniedErrorf("issue %d can't be accessed by project %d", issue.ID, newProject.ID)
118118
}
119119
}
@@ -145,7 +145,7 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
145145
MaxSorting int64
146146
IssueCount int64
147147
}{}
148-
if _, err := db.GetEngine(ctx).Select("max(sorting) as MaxSorting, count(*) as IssueCount").Table("project_issue").
148+
if _, err := db.GetEngine(ctx).Select("max(sorting) as max_sorting, count(*) as issue_count").Table("project_issue").
149149
Where("project_id=?", newProjectID).
150150
And("project_board_id=?", newColumnID).
151151
Get(&res); err != nil {

Diff for: models/project/board.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func NewBoard(ctx context.Context, board *Board) error {
176176
MaxSorting int64
177177
ColumnCount int64
178178
}{}
179-
if _, err := db.GetEngine(ctx).Select("max(sorting) as MaxSorting, count(*) as ColumnCount").Table("project_board").
179+
if _, err := db.GetEngine(ctx).Select("max(sorting) as max_sorting, count(*) as column_count").Table("project_board").
180180
Where("project_id=?", board.ProjectID).Get(&res); err != nil {
181181
return err
182182
}

Diff for: models/project/board_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ func Test_MoveColumnsOnProject(t *testing.T) {
8484
columns, err := project1.GetBoards(db.DefaultContext)
8585
assert.NoError(t, err)
8686
assert.Len(t, columns, 3)
87-
assert.EqualValues(t, 0, columns[0].Sorting)
88-
assert.EqualValues(t, 1, columns[1].Sorting)
89-
assert.EqualValues(t, 2, columns[2].Sorting)
87+
assert.EqualValues(t, 0, columns[0].Sorting) // even if there is no default sorting, the code should also work
88+
assert.EqualValues(t, 0, columns[1].Sorting)
89+
assert.EqualValues(t, 0, columns[2].Sorting)
9090

9191
err = MoveColumnsOnProject(db.DefaultContext, project1, map[int64]int64{
9292
0: columns[1].ID,
@@ -97,7 +97,7 @@ func Test_MoveColumnsOnProject(t *testing.T) {
9797

9898
columnsAfter, err := project1.GetBoards(db.DefaultContext)
9999
assert.NoError(t, err)
100-
assert.Len(t, columns, 3)
100+
assert.Len(t, columnsAfter, 3)
101101
assert.EqualValues(t, columns[1].ID, columnsAfter[0].ID)
102102
assert.EqualValues(t, columns[2].ID, columnsAfter[1].ID)
103103
assert.EqualValues(t, columns[0].ID, columnsAfter[2].ID)

Diff for: models/project/project.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ func (p *Project) IsRepositoryProject() bool {
161161
return p.Type == TypeRepository
162162
}
163163

164-
func (p *Project) CanBeAccessedByOwnerRepo(ownerID, repoID int64) bool {
164+
func (p *Project) CanBeAccessedByOwnerRepo(ownerID int64, repo *repo_model.Repository) bool {
165165
if p.Type == TypeRepository {
166-
return p.RepoID == repoID // if a project belongs to a repository, then its OwnerID is 0 and can be ignored
166+
return repo != nil && p.RepoID == repo.ID // if a project belongs to a repository, then its OwnerID is 0 and can be ignored
167167
}
168168
return p.OwnerID == ownerID && p.RepoID == 0
169169
}

Diff for: routers/web/shared/project/column.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ func MoveColumns(ctx *context.Context) {
1616
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
1717
return
1818
}
19-
if project.OwnerID > 0 && project.OwnerID != ctx.ContextUser.ID {
20-
ctx.NotFound("InvalidOwnerID", nil)
21-
return
22-
}
23-
if project.RepoID > 0 && project.RepoID != ctx.Repo.Repository.ID {
24-
ctx.NotFound("InvalidRepoID", nil)
19+
if !project.CanBeAccessedByOwnerRepo(ctx.ContextUser.ID, ctx.Repo.Repository) {
20+
ctx.NotFound("CanBeAccessedByOwnerRepo", nil)
2521
return
2622
}
2723

0 commit comments

Comments
 (0)