mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-15 14:45:18 +02:00
- EditProject: wrap field updates and ChangeProjectStatus in db.WithTx so a status-change failure doesn't leave a partially applied PATCH. - Validate EditProjectOption.State against open/closed; 422 on other values instead of silently treating them as open. - Align missing-issue status to 404 (the URL targets a missing resource); update existing test that was asserting the old 422. - RemoveIssueFromProjectColumn: verify the project_issue row matches the URL column before clearing the issue's project assignment, since IssueAssignOrRemoveProject(projectID=0) detaches the issue from any project regardless of column. Returns 404 if the issue isn't in this column. New test covers the cross-column case. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package project
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
project_model "code.gitea.io/gitea/models/project"
|
|
"code.gitea.io/gitea/modules/optional"
|
|
)
|
|
|
|
// UpdateProjectOptions represents updatable project fields. Fields with no value are left unchanged.
|
|
type UpdateProjectOptions struct {
|
|
Title optional.Option[string]
|
|
Description optional.Option[string]
|
|
CardType optional.Option[project_model.CardType]
|
|
IsClosed optional.Option[bool]
|
|
}
|
|
|
|
// UpdateProject applies the provided options to the project atomically.
|
|
func UpdateProject(ctx context.Context, project *project_model.Project, opts UpdateProjectOptions) error {
|
|
return db.WithTx(ctx, func(ctx context.Context) error {
|
|
if opts.Title.Has() {
|
|
project.Title = opts.Title.Value()
|
|
}
|
|
if opts.Description.Has() {
|
|
project.Description = opts.Description.Value()
|
|
}
|
|
if opts.CardType.Has() {
|
|
project.CardType = opts.CardType.Value()
|
|
}
|
|
if err := project_model.UpdateProject(ctx, project); err != nil {
|
|
return err
|
|
}
|
|
if opts.IsClosed.Has() && opts.IsClosed.Value() != project.IsClosed {
|
|
if err := project_model.ChangeProjectStatus(ctx, project, opts.IsClosed.Value()); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|