Skip to content

Commit a4dac59

Browse files
emrebdrwolfogre
andauthored
Fixes for unreachable project issues when transfer repository from organization (#31770)
When transferring repositories that have issues linked to a project board to another organization, the issues remain associated with the original project board. This causes the columns in the project board to become bugged, making it difficult to move other issues in or out of the affected columns. As a solution, I removed the issue relations since the other organization does not have this project table. Fix for #31538 Co-authored-by: Jason Song <[email protected]>
1 parent 5bcab0b commit a4dac59

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

Diff for: models/project/issue.go

+6
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,9 @@ func (c *Column) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Colum
117117
return nil
118118
})
119119
}
120+
121+
// DeleteAllProjectIssueByIssueIDsAndProjectIDs delete all project's issues by issue's and project's ids
122+
func DeleteAllProjectIssueByIssueIDsAndProjectIDs(ctx context.Context, issueIDs, projectIDs []int64) error {
123+
_, err := db.GetEngine(ctx).In("project_id", projectIDs).In("issue_id", issueIDs).Delete(&ProjectIssue{})
124+
return err
125+
}

Diff for: models/project/project.go

+6
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ func GetProjectForRepoByID(ctx context.Context, repoID, id int64) (*Project, err
296296
return p, nil
297297
}
298298

299+
// GetAllProjectsIDsByOwnerID returns the all projects ids it owns
300+
func GetAllProjectsIDsByOwnerIDAndType(ctx context.Context, ownerID int64, projectType Type) ([]int64, error) {
301+
projects := make([]int64, 0)
302+
return projects, db.GetEngine(ctx).Table(&Project{}).Where("owner_id=? AND type=?", ownerID, projectType).Cols("id").Find(&projects)
303+
}
304+
299305
// UpdateProject updates project properties
300306
func UpdateProject(ctx context.Context, p *Project) error {
301307
if !IsCardTypeValid(p.CardType) {

Diff for: options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,7 @@ settings.transfer_in_progress = There is currently an ongoing transfer. Please c
21862186
settings.transfer_notices_1 = - You will lose access to the repository if you transfer it to an individual user.
21872187
settings.transfer_notices_2 = - You will keep access to the repository if you transfer it to an organization that you (co-)own.
21882188
settings.transfer_notices_3 = - If the repository is private and is transferred to an individual user, this action makes sure that the user does have at least read permission (and changes permissions if necessary).
2189+
settings.transfer_notices_4 = - If the repository belongs to an organization, and you transfer it to another organization or individual, you will lose the links between the repository's issues and the organization's project board.
21892190
settings.transfer_owner = New Owner
21902191
settings.transfer_perform = Perform Transfer
21912192
settings.transfer_started = This repository has been marked for transfer and awaits confirmation from "%s"

Diff for: services/repository/transfer.go

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/models/organization"
1616
"code.gitea.io/gitea/models/perm"
1717
access_model "code.gitea.io/gitea/models/perm/access"
18+
project_model "code.gitea.io/gitea/models/project"
1819
repo_model "code.gitea.io/gitea/models/repo"
1920
user_model "code.gitea.io/gitea/models/user"
2021
"code.gitea.io/gitea/modules/log"
@@ -177,6 +178,22 @@ func transferOwnership(ctx context.Context, doer *user_model.User, newOwnerName
177178
}
178179
}
179180

181+
// Remove project's issues that belong to old organization's projects
182+
if oldOwner.IsOrganization() {
183+
projects, err := project_model.GetAllProjectsIDsByOwnerIDAndType(ctx, oldOwner.ID, project_model.TypeOrganization)
184+
if err != nil {
185+
return fmt.Errorf("Unable to find old org projects: %w", err)
186+
}
187+
issues, err := issues_model.GetIssueIDsByRepoID(ctx, repo.ID)
188+
if err != nil {
189+
return fmt.Errorf("Unable to find repo's issues: %w", err)
190+
}
191+
err = project_model.DeleteAllProjectIssueByIssueIDsAndProjectIDs(ctx, issues, projects)
192+
if err != nil {
193+
return fmt.Errorf("Unable to delete project's issues: %w", err)
194+
}
195+
}
196+
180197
if newOwner.IsOrganization() {
181198
teams, err := organization.FindOrgTeams(ctx, newOwner.ID)
182199
if err != nil {

Diff for: templates/repo/settings/options.tmpl

+2-1
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@
957957
<div class="ui warning message">
958958
{{ctx.Locale.Tr "repo.settings.transfer_notices_1"}} <br>
959959
{{ctx.Locale.Tr "repo.settings.transfer_notices_2"}} <br>
960-
{{ctx.Locale.Tr "repo.settings.transfer_notices_3"}}
960+
{{ctx.Locale.Tr "repo.settings.transfer_notices_3"}} <br>
961+
{{ctx.Locale.Tr "repo.settings.transfer_notices_4"}}
961962
</div>
962963
<form class="ui form" action="{{.Link}}" method="post">
963964
{{.CsrfTokenHtml}}

0 commit comments

Comments
 (0)