Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 500 when sorting the default project board #29870

Closed
wants to merge 1 commit into from

Conversation

lng2020
Copy link
Member

@lng2020 lng2020 commented Mar 17, 2024

fix #29853
The problem is that checkProjectBoardChangePermission didn't check if the project board id == 0, which is the default project board.
BTW, I think the code about this default project board trick is a little redundant. It required every function to check whether the project board id == 0. I will clean it up afterward.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 17, 2024
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 17, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Mar 17, 2024
@lng2020 lng2020 added type/bug backport/v1.21 This PR should be backported to Gitea 1.21 labels Mar 17, 2024
Comment on lines +579 to +598
if ctx.ParamsInt64(":boardID") == 0 {
board = &project_model.Board{
ID: 0,
ProjectID: project.ID,
Title: ctx.Locale.TrString("repo.projects.type.uncategorized"),
}
} else {
board, err = project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
if err != nil {
if project_model.IsErrProjectBoardNotExist(err) {
ctx.NotFound("ProjectBoardNotExist", nil)
} else {
ctx.ServerError("GetProjectBoard", err)
}
return nil, nil
}
if board.ProjectID != project.ID {
ctx.NotFound("BoardNotInProject", nil)
return nil, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we extract this into one func getContextBoard(ctx context, projectID int64) (project_model.Board, error)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will clean it up afterward

That's what I mean in the PR description. I rather keep this PR focus on the fix. What do you think?

@silverwind
Copy link
Member

silverwind commented Mar 17, 2024

Found this interesting comment:

<div class="ui cards {{if and $canWriteProject (ne .ID 0)}}{{/* ID 0 is default column which cannot be moved */}}tw-cursor-grab{{end}}" data-url="{{$.Link}}/{{.ID}}" data-project="{{$.Project.ID}}" data-board="{{.ID}}" id="board_{{.ID}}">

So it seems column 0 was at least initially never meant to be moved. I do agree we should allow it.

@silverwind
Copy link
Member

silverwind commented Mar 17, 2024

It seems that the default column can indeed not be dragged itself, but another column can be dragged into its place, so the restriction is kind of pointless currently.

I think we should unrestrict column entirely either in this PR or a followup, removing the JS restriction that currently forbids the default column from being dragged.

@denyskon
Copy link
Member

@silverwind The default column doesn't really exist, it's dynamically generated if there are no columns in a project. See #29874

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 18, 2024
@lng2020
Copy link
Member Author

lng2020 commented Mar 18, 2024

I think we should unrestrict column entirely either in this PR or a followup, removing the JS restriction that currently forbids the default column from being dragged.

The backend uses the sorting field to indicate the column location. As denyskon explained above, the backend didn't store the uncategorized column, so even if users are allowed to drag the uncategorized column, the uncategorized column will still be in the leftmost as long as the page refreshes.
This PR only fixes the 500 error. It won't resolve the problem that the changing uncategorized column position won't have any effect.

@silverwind
Copy link
Member

@silverwind The default column doesn't really exist, it's dynamically generated if there are no columns in a project. See #29874

I still don't get it. Why is that board different from others and why can't it be sortable?

@lng2020
Copy link
Member Author

lng2020 commented Mar 18, 2024

@silverwind

if ctx.ParamsInt64(":boardID") == 0 {
board = &project_model.Board{
ID: 0,
ProjectID: project.ID,
Title: ctx.Locale.TrString("repo.projects.type.uncategorized"),
}
} else {
board, err = project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
if err != nil {
if project_model.IsErrProjectBoardNotExist(err) {
ctx.NotFound("ProjectBoardNotExist", nil)
} else {
ctx.ServerError("GetProjectBoard", err)
}
return
}

the DB didn't store the column. The backend checks it first and returns a mock one. Therefore, the sorting field, which is used for sorting, always defaults to value 0.
If we want to sort this column, we need to redesign the backend logic.

@silverwind
Copy link
Member

silverwind commented Mar 18, 2024

So if we can't make it sortable on backend, we should just prevent dropping anything in place of the default column, should be possible in the JS.

Long term, it should be made sortable, just like it is on GitHub.

@lng2020
Copy link
Member Author

lng2020 commented Mar 18, 2024

should be possible in the JS.

The JS solution could replace this PR because no more requests about boardID=0 can be made so the backend can skip this check. Would you like to take over?

Long term, it should be made sortable, just like it is on GitHub.

After #29874, when projects are created, the default board can be treated like a normal board. The Uncategorized column, which is a pseudo-board with boardID=0, appears only when the default board is intentionally deleted. This Uncategorized column can not be sorted. Do you think the Uncategorized column should be sortable too?

@denyskon
Copy link
Member

Well what we could do in #29874 is adding a migration to create the new default column retroactively, then disallow for a project to have less than one board (the last one cannot be deleted). Then we could get rid of board 0 completely.

@silverwind
Copy link
Member

I think we should actually follow GitHub and make it possible to have multiple default columns, GitHub seems to have various template and the first one has thee columns "Todo", "In Progress", "Done". I think that'd be good set of default columns.

@denyskon
Copy link
Member

That's another point, we already have project templates. Currently however we're taking about default columns for issues added to a project, which is currently either set manually or generated dynamically when the backend notices that the project doesn't have a default column. The proposal is to just add one if the project is empty and not to allow deleting all columns, then we would not have the need for dynamically generating this non-editable pseudo-column.

silverwind added a commit to silverwind/gitea that referenced this pull request Mar 18, 2024
@silverwind
Copy link
Member

should be possible in the JS.

The JS solution could replace this PR because no more requests about boardID=0 can be made so the backend can skip this check. Would you like to take over?

#29892 does that, making this PR obsolete I guess.

@denyskon
Copy link
Member

Closing in favor of the proper fix in #29874 removing boardID 0 completely

@denyskon denyskon closed this Mar 18, 2024
@lunny lunny removed the backport/v1.21 This PR should be backported to Gitea 1.21 label Mar 25, 2024
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Moving project panels results in 500 GetProjectBoard: project board does not exist
6 participants