summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorCirno the Strongest <1447794+CirnoT@users.noreply.github.com>2020-06-07 02:45:12 +0200
committerGitHub <noreply@github.com>2020-06-06 20:45:12 -0400
commit94f60e199bc504c6cfb7b853889e3ceb2a837adc (patch)
tree4bfcb10071d6b8356863f11370d91b91b19894bc /routers
parent594db7fb433a386603c09676542bb0ec2e700935 (diff)
downloadgitea-94f60e199bc504c6cfb7b853889e3ceb2a837adc.tar.gz
gitea-94f60e199bc504c6cfb7b853889e3ceb2a837adc.zip
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 <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers')
-rw-r--r--routers/org/setting.go20
-rw-r--r--routers/repo/pull.go12
-rw-r--r--routers/repo/setting.go2
3 files changed, 27 insertions, 7 deletions
diff --git a/routers/org/setting.go b/routers/org/setting.go
index 348d8cc8d8..79a99295a8 100644
--- a/routers/org/setting.go
+++ b/routers/org/setting.go
@@ -85,12 +85,30 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
org.Description = form.Description
org.Website = form.Website
org.Location = form.Location
- org.Visibility = form.Visibility
org.RepoAdminChangeTeamAccess = form.RepoAdminChangeTeamAccess
+
+ visibilityChanged := form.Visibility != org.Visibility
+ org.Visibility = form.Visibility
+
if err := models.UpdateUser(org); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
+
+ // update forks visibility
+ if visibilityChanged {
+ if err := org.GetRepositories(models.ListOptions{Page: 1, PageSize: org.NumRepos}); err != nil {
+ ctx.ServerError("GetRepositories", err)
+ return
+ }
+ for _, repo := range org.Repos {
+ if err := models.UpdateRepository(repo, true); err != nil {
+ ctx.ServerError("UpdateRepository", err)
+ return
+ }
+ }
+ }
+
log.Trace("Organization setting updated: %s", org.Name)
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
ctx.Redirect(ctx.Org.OrgLink + "/settings")
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index d4c99e2769..30913e4766 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/repofiles"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/utils"
"code.gitea.io/gitea/services/gitdiff"
@@ -95,15 +96,16 @@ func getForkRepository(ctx *context.Context) *models.Repository {
return nil
}
- ctx.Data["repo_name"] = forkRepo.Name
- ctx.Data["description"] = forkRepo.Description
- ctx.Data["IsPrivate"] = forkRepo.IsPrivate
- canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
-
if err := forkRepo.GetOwner(); err != nil {
ctx.ServerError("GetOwner", err)
return nil
}
+
+ ctx.Data["repo_name"] = forkRepo.Name
+ ctx.Data["description"] = forkRepo.Description
+ ctx.Data["IsPrivate"] = forkRepo.IsPrivate || forkRepo.Owner.Visibility == structs.VisibleTypePrivate
+ canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
+
ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index dff13ff5b3..1433bedb3b 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -102,7 +102,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
// Visibility of forked repository is forced sync with base repository.
if repo.IsFork {
- form.Private = repo.BaseRepo.IsPrivate
+ form.Private = repo.BaseRepo.IsPrivate || repo.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate
}
visibilityChanged := repo.IsPrivate != form.Private