Merge pull request '[BUG] Load `AllUnitsEnabled` when necessary' (#2420) from gusted/forgejo-add-more into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2420 Reviewed-by: Otto <otto@codeberg.org> Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
726ce5e3f9
|
@ -439,6 +439,31 @@ func (repo *Repository) GetUnit(ctx context.Context, tp unit.Type) (*RepoUnit, e
|
||||||
return nil, ErrUnitTypeNotExist{tp}
|
return nil, ErrUnitTypeNotExist{tp}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllUnitsEnabled returns true if all units are enabled for the repo.
|
||||||
|
func (repo *Repository) AllUnitsEnabled(ctx context.Context) bool {
|
||||||
|
hasAnyUnitEnabled := func(unitGroup []unit.Type) bool {
|
||||||
|
// Loop over the group of units
|
||||||
|
for _, unit := range unitGroup {
|
||||||
|
// If *any* of them is enabled, return true.
|
||||||
|
if repo.UnitEnabled(ctx, unit) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If none are enabled, return false.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, unitGroup := range unit.AllowedRepoUnitGroups {
|
||||||
|
// If any disabled unit is found, return false immediately.
|
||||||
|
if !hasAnyUnitEnabled(unitGroup) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// LoadOwner loads owner user
|
// LoadOwner loads owner user
|
||||||
func (repo *Repository) LoadOwner(ctx context.Context) (err error) {
|
func (repo *Repository) LoadOwner(ctx context.Context) (err error) {
|
||||||
if repo.Owner != nil {
|
if repo.Owner != nil {
|
||||||
|
|
|
@ -82,31 +82,6 @@ func (r *Repository) CanCreateBranch() bool {
|
||||||
return r.Permission.CanWrite(unit_model.TypeCode) && r.Repository.CanCreateBranch()
|
return r.Permission.CanWrite(unit_model.TypeCode) && r.Repository.CanCreateBranch()
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllUnitsEnabled returns true if all units are enabled for the repo.
|
|
||||||
func (r *Repository) AllUnitsEnabled(ctx context.Context) bool {
|
|
||||||
hasAnyUnitEnabled := func(unitGroup []unit_model.Type) bool {
|
|
||||||
// Loop over the group of units
|
|
||||||
for _, unit := range unitGroup {
|
|
||||||
// If *any* of them is enabled, return true.
|
|
||||||
if r.Repository.UnitEnabled(ctx, unit) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If none are enabled, return false.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, unitGroup := range unit_model.AllowedRepoUnitGroups {
|
|
||||||
// If any disabled unit is found, return false immediately.
|
|
||||||
if !hasAnyUnitEnabled(unitGroup) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// RepoMustNotBeArchived checks if a repo is archived
|
// RepoMustNotBeArchived checks if a repo is archived
|
||||||
func RepoMustNotBeArchived() func(ctx *Context) {
|
func RepoMustNotBeArchived() func(ctx *Context) {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
|
@ -1079,7 +1054,6 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag
|
ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag
|
||||||
ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit
|
ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit
|
||||||
ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch()
|
ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch()
|
||||||
ctx.Data["AllUnitsEnabled"] = ctx.Repo.AllUnitsEnabled(ctx)
|
|
||||||
|
|
||||||
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
|
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -219,7 +219,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .Permission.IsAdmin}}
|
{{if .Permission.IsAdmin}}
|
||||||
{{if not .AllUnitsEnabled}}
|
{{if not (.Repository.AllUnitsEnabled ctx)}}
|
||||||
<a class="{{if .PageIsRepoSettingsUnits}}active {{end}}item" href="{{.RepoLink}}/settings/units">
|
<a class="{{if .PageIsRepoSettingsUnits}}active {{end}}item" href="{{.RepoLink}}/settings/units">
|
||||||
{{svg "octicon-diff-added"}} {{ctx.Locale.Tr "repo.settings.units.add_more"}}
|
{{svg "octicon-diff-added"}} {{ctx.Locale.Tr "repo.settings.units.add_more"}}
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in New Issue