Skip to content

Commit 94f60e1

Browse files
CirnoTlunnyzeripathtechknowlogick
authored
Fix visibility of forked public repos from private orgs (#11717)
* Fix visibility of forked public repos from private orgs * update forks visibility when org visibility is changed Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 594db7f commit 94f60e1

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
14541454
return fmt.Errorf("getRepositoriesByForkID: %v", err)
14551455
}
14561456
for i := range forkRepos {
1457-
forkRepos[i].IsPrivate = repo.IsPrivate
1457+
forkRepos[i].IsPrivate = repo.IsPrivate || repo.Owner.Visibility == api.VisibleTypePrivate
14581458
if err = updateRepository(e, forkRepos[i], true); err != nil {
14591459
return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
14601460
}

modules/repository/fork.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/git"
1414
"code.gitea.io/gitea/modules/log"
15+
"code.gitea.io/gitea/modules/structs"
1516
)
1617

1718
// ForkRepository forks a repository
@@ -36,7 +37,7 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
3637
LowerName: strings.ToLower(name),
3738
Description: desc,
3839
DefaultBranch: oldRepo.DefaultBranch,
39-
IsPrivate: oldRepo.IsPrivate,
40+
IsPrivate: oldRepo.IsPrivate || oldRepo.Owner.Visibility == structs.VisibleTypePrivate,
4041
IsEmpty: oldRepo.IsEmpty,
4142
IsFork: true,
4243
ForkID: oldRepo.ID,

routers/org/setting.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,30 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
8585
org.Description = form.Description
8686
org.Website = form.Website
8787
org.Location = form.Location
88-
org.Visibility = form.Visibility
8988
org.RepoAdminChangeTeamAccess = form.RepoAdminChangeTeamAccess
89+
90+
visibilityChanged := form.Visibility != org.Visibility
91+
org.Visibility = form.Visibility
92+
9093
if err := models.UpdateUser(org); err != nil {
9194
ctx.ServerError("UpdateUser", err)
9295
return
9396
}
97+
98+
// update forks visibility
99+
if visibilityChanged {
100+
if err := org.GetRepositories(models.ListOptions{Page: 1, PageSize: org.NumRepos}); err != nil {
101+
ctx.ServerError("GetRepositories", err)
102+
return
103+
}
104+
for _, repo := range org.Repos {
105+
if err := models.UpdateRepository(repo, true); err != nil {
106+
ctx.ServerError("UpdateRepository", err)
107+
return
108+
}
109+
}
110+
}
111+
94112
log.Trace("Organization setting updated: %s", org.Name)
95113
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
96114
ctx.Redirect(ctx.Org.OrgLink + "/settings")

routers/repo/pull.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"code.gitea.io/gitea/modules/notification"
2525
"code.gitea.io/gitea/modules/repofiles"
2626
"code.gitea.io/gitea/modules/setting"
27+
"code.gitea.io/gitea/modules/structs"
2728
"code.gitea.io/gitea/modules/util"
2829
"code.gitea.io/gitea/routers/utils"
2930
"code.gitea.io/gitea/services/gitdiff"
@@ -95,15 +96,16 @@ func getForkRepository(ctx *context.Context) *models.Repository {
9596
return nil
9697
}
9798

98-
ctx.Data["repo_name"] = forkRepo.Name
99-
ctx.Data["description"] = forkRepo.Description
100-
ctx.Data["IsPrivate"] = forkRepo.IsPrivate
101-
canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
102-
10399
if err := forkRepo.GetOwner(); err != nil {
104100
ctx.ServerError("GetOwner", err)
105101
return nil
106102
}
103+
104+
ctx.Data["repo_name"] = forkRepo.Name
105+
ctx.Data["description"] = forkRepo.Description
106+
ctx.Data["IsPrivate"] = forkRepo.IsPrivate || forkRepo.Owner.Visibility == structs.VisibleTypePrivate
107+
canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
108+
107109
ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
108110
ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
109111

routers/repo/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
102102

103103
// Visibility of forked repository is forced sync with base repository.
104104
if repo.IsFork {
105-
form.Private = repo.BaseRepo.IsPrivate
105+
form.Private = repo.BaseRepo.IsPrivate || repo.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate
106106
}
107107

108108
visibilityChanged := repo.IsPrivate != form.Private

0 commit comments

Comments
 (0)