Skip to content

Commit 352a67d

Browse files
emrebdrwolfogre
authored andcommitted
Fixes for unreachable project issues when transfer repository from organization (go-gitea#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 go-gitea#31538 Co-authored-by: Jason Song <[email protected]>
1 parent a3633b5 commit 352a67d

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

models/project/issue.go

+6
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ func (b *Board) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Board)
141141
return nil
142142
})
143143
}
144+
145+
// DeleteAllProjectIssueByIssueIDsAndProjectIDs delete all project's issues by issue's and project's ids
146+
func DeleteAllProjectIssueByIssueIDsAndProjectIDs(ctx context.Context, issueIDs, projectIDs []int64) error {
147+
_, err := db.GetEngine(ctx).In("project_id", projectIDs).In("issue_id", issueIDs).Delete(&ProjectIssue{})
148+
return err
149+
}

models/project/project.go

+6
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ func GetProjectForRepoByID(ctx context.Context, repoID, id int64) (*Project, err
319319
return p, nil
320320
}
321321

322+
// GetAllProjectsIDsByOwnerID returns the all projects ids it owns
323+
func GetAllProjectsIDsByOwnerIDAndType(ctx context.Context, ownerID int64, projectType Type) ([]int64, error) {
324+
projects := make([]int64, 0)
325+
return projects, db.GetEngine(ctx).Table(&Project{}).Where("owner_id=? AND type=?", ownerID, projectType).Cols("id").Find(&projects)
326+
}
327+
322328
// UpdateProject updates project properties
323329
func UpdateProject(ctx context.Context, p *Project) error {
324330
if !IsCardTypeValid(p.CardType) {

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,7 @@ settings.transfer_in_progress = There is currently an ongoing transfer. Please c
21732173
settings.transfer_notices_1 = - You will lose access to the repository if you transfer it to an individual user.
21742174
settings.transfer_notices_2 = - You will keep access to the repository if you transfer it to an organization that you (co-)own.
21752175
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).
2176+
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.
21762177
settings.transfer_owner = New Owner
21772178
settings.transfer_perform = Perform Transfer
21782179
settings.transfer_started = This repository has been marked for transfer and awaits confirmation from "%s"

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 {

templates/repo/settings/options.tmpl

+2-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,8 @@
950950
<div class="ui warning message">
951951
{{ctx.Locale.Tr "repo.settings.transfer_notices_1"}} <br>
952952
{{ctx.Locale.Tr "repo.settings.transfer_notices_2"}} <br>
953-
{{ctx.Locale.Tr "repo.settings.transfer_notices_3"}}
953+
{{ctx.Locale.Tr "repo.settings.transfer_notices_3"}} <br>
954+
{{ctx.Locale.Tr "repo.settings.transfer_notices_4"}}
954955
</div>
955956
<form class="ui form" action="{{.Link}}" method="post">
956957
{{.CsrfTokenHtml}}

0 commit comments

Comments
 (0)