Enable/disable owner and repo projects independently (#28805)
Part of #23318
Add menu in repo settings to allow for repo admin to decide not just if
projects are enabled or disabled per repo, but also which kind of
projects (repo-level/owner-level) are enabled. If repo projects
disabled, don't show the projects tab.

---------
Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
parent
8553b4600e
commit
fe6792dff3
16 changed files with 212 additions and 63 deletions
|
@ -944,13 +944,33 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
}
|
||||
}
|
||||
|
||||
if opts.HasProjects != nil && !unit_model.TypeProjects.UnitGlobalDisabled() {
|
||||
if *opts.HasProjects {
|
||||
currHasProjects := repo.UnitEnabled(ctx, unit_model.TypeProjects)
|
||||
newHasProjects := currHasProjects
|
||||
if opts.HasProjects != nil {
|
||||
newHasProjects = *opts.HasProjects
|
||||
}
|
||||
if currHasProjects || newHasProjects {
|
||||
if newHasProjects && !unit_model.TypeProjects.UnitGlobalDisabled() {
|
||||
unit, err := repo.GetUnit(ctx, unit_model.TypeProjects)
|
||||
var config *repo_model.ProjectsConfig
|
||||
if err != nil {
|
||||
config = &repo_model.ProjectsConfig{
|
||||
ProjectsMode: repo_model.ProjectsModeAll,
|
||||
}
|
||||
} else {
|
||||
config = unit.ProjectsConfig()
|
||||
}
|
||||
|
||||
if opts.ProjectsMode != nil {
|
||||
config.ProjectsMode = repo_model.ProjectsMode(*opts.ProjectsMode)
|
||||
}
|
||||
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypeProjects,
|
||||
Config: config,
|
||||
})
|
||||
} else {
|
||||
} else if !newHasProjects && !unit_model.TypeProjects.UnitGlobalDisabled() {
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeProjects)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue