mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-18 11:28:39 +08:00
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>
This commit is contained in:
parent
594db7fb43
commit
94f60e199b
@ -1454,7 +1454,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
|
|||||||
return fmt.Errorf("getRepositoriesByForkID: %v", err)
|
return fmt.Errorf("getRepositoriesByForkID: %v", err)
|
||||||
}
|
}
|
||||||
for i := range forkRepos {
|
for i := range forkRepos {
|
||||||
forkRepos[i].IsPrivate = repo.IsPrivate
|
forkRepos[i].IsPrivate = repo.IsPrivate || repo.Owner.Visibility == api.VisibleTypePrivate
|
||||||
if err = updateRepository(e, forkRepos[i], true); err != nil {
|
if err = updateRepository(e, forkRepos[i], true); err != nil {
|
||||||
return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
|
return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ForkRepository forks a repository
|
// ForkRepository forks a repository
|
||||||
@ -36,7 +37,7 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
|
|||||||
LowerName: strings.ToLower(name),
|
LowerName: strings.ToLower(name),
|
||||||
Description: desc,
|
Description: desc,
|
||||||
DefaultBranch: oldRepo.DefaultBranch,
|
DefaultBranch: oldRepo.DefaultBranch,
|
||||||
IsPrivate: oldRepo.IsPrivate,
|
IsPrivate: oldRepo.IsPrivate || oldRepo.Owner.Visibility == structs.VisibleTypePrivate,
|
||||||
IsEmpty: oldRepo.IsEmpty,
|
IsEmpty: oldRepo.IsEmpty,
|
||||||
IsFork: true,
|
IsFork: true,
|
||||||
ForkID: oldRepo.ID,
|
ForkID: oldRepo.ID,
|
||||||
|
@ -85,12 +85,30 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
|
|||||||
org.Description = form.Description
|
org.Description = form.Description
|
||||||
org.Website = form.Website
|
org.Website = form.Website
|
||||||
org.Location = form.Location
|
org.Location = form.Location
|
||||||
org.Visibility = form.Visibility
|
|
||||||
org.RepoAdminChangeTeamAccess = form.RepoAdminChangeTeamAccess
|
org.RepoAdminChangeTeamAccess = form.RepoAdminChangeTeamAccess
|
||||||
|
|
||||||
|
visibilityChanged := form.Visibility != org.Visibility
|
||||||
|
org.Visibility = form.Visibility
|
||||||
|
|
||||||
if err := models.UpdateUser(org); err != nil {
|
if err := models.UpdateUser(org); err != nil {
|
||||||
ctx.ServerError("UpdateUser", err)
|
ctx.ServerError("UpdateUser", err)
|
||||||
return
|
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)
|
log.Trace("Organization setting updated: %s", org.Name)
|
||||||
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
|
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
|
||||||
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/repofiles"
|
"code.gitea.io/gitea/modules/repofiles"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/utils"
|
"code.gitea.io/gitea/routers/utils"
|
||||||
"code.gitea.io/gitea/services/gitdiff"
|
"code.gitea.io/gitea/services/gitdiff"
|
||||||
@ -95,15 +96,16 @@ func getForkRepository(ctx *context.Context) *models.Repository {
|
|||||||
return nil
|
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 {
|
if err := forkRepo.GetOwner(); err != nil {
|
||||||
ctx.ServerError("GetOwner", err)
|
ctx.ServerError("GetOwner", err)
|
||||||
return nil
|
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["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
|
||||||
ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
|
ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
|
|||||||
|
|
||||||
// Visibility of forked repository is forced sync with base repository.
|
// Visibility of forked repository is forced sync with base repository.
|
||||||
if repo.IsFork {
|
if repo.IsFork {
|
||||||
form.Private = repo.BaseRepo.IsPrivate
|
form.Private = repo.BaseRepo.IsPrivate || repo.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate
|
||||||
}
|
}
|
||||||
|
|
||||||
visibilityChanged := repo.IsPrivate != form.Private
|
visibilityChanged := repo.IsPrivate != form.Private
|
||||||
|
Loading…
Reference in New Issue
Block a user