mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-26 22:06:51 +00:00
Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (#37324)
A quick fix #37317 --- The current behavior for forks when an organization or repository is changed to private differs from GitHub. On GitHub, when a parent repository becomes private, the fork relationship is removed, which keeps the behavior simple and avoids visibility conflicts. I think we need a similar solution to handle cases where the parent repository becomes private while a fork remains public and the fork relationship is still preserved. --------- Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
@@ -102,10 +102,14 @@ func DeleteOrganization(ctx context.Context, org *org_model.Organization, purge
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateOrgRepoForVisibilityChanged(ctx context.Context, repo *repo_model.Repository, makePrivate bool) error {
|
||||
func updateRepoForVisibilityChanged(ctx context.Context, repo *repo_model.Repository, makePrivate bool) error {
|
||||
if err := repo.LoadOwner(ctx); err != nil {
|
||||
return fmt.Errorf("LoadOwner: %w", err)
|
||||
}
|
||||
|
||||
// Organization repository need to recalculate access table when visibility is changed.
|
||||
if err := access_model.RecalculateTeamAccesses(ctx, repo, 0); err != nil {
|
||||
return fmt.Errorf("recalculateTeamAccesses: %w", err)
|
||||
if err := access_model.RecalculateAccesses(ctx, repo); err != nil {
|
||||
return fmt.Errorf("RecalculateAccesses: %w", err)
|
||||
}
|
||||
|
||||
if makePrivate {
|
||||
@@ -135,7 +139,7 @@ func updateOrgRepoForVisibilityChanged(ctx context.Context, repo *repo_model.Rep
|
||||
return fmt.Errorf("getRepositoriesByForkID: %w", err)
|
||||
}
|
||||
for i := range forkRepos {
|
||||
if err := updateOrgRepoForVisibilityChanged(ctx, forkRepos[i], makePrivate); err != nil {
|
||||
if err := updateRepoForVisibilityChanged(ctx, forkRepos[i], makePrivate); err != nil {
|
||||
return fmt.Errorf("updateRepoForVisibilityChanged[%s]: %w", forkRepos[i].FullName(), err)
|
||||
}
|
||||
}
|
||||
@@ -161,8 +165,8 @@ func ChangeOrganizationVisibility(ctx context.Context, org *org_model.Organizati
|
||||
return err
|
||||
}
|
||||
for _, repo := range repos {
|
||||
if err := updateOrgRepoForVisibilityChanged(ctx, repo, visibility == structs.VisibleTypePrivate); err != nil {
|
||||
return fmt.Errorf("updateOrgRepoForVisibilityChanged: %w", err)
|
||||
if err := updateRepoForVisibilityChanged(ctx, repo, visibility == structs.VisibleTypePrivate); err != nil {
|
||||
return fmt.Errorf("updateRepoForVisibilityChanged: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -60,4 +61,11 @@ func TestOrg(t *testing.T) {
|
||||
assert.Error(t, DeleteOrganization(t.Context(), user, false))
|
||||
unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
|
||||
})
|
||||
|
||||
t.Run("ChangeVisibilityWithUserFork", func(t *testing.T) {
|
||||
// org 19 has a repository 27 which has a forked repository 29 by user 20
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 19})
|
||||
require.NoError(t, ChangeOrganizationVisibility(t.Context(), org, structs.VisibleTypePrivate))
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: org.ID, Visibility: structs.VisibleTypePrivate})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user