Merge pull request 'Repository settings refactor' (#2221) from algernon/forgejo:repo-units/ui-refactor into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2221
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-02-14 13:29:04 +00:00
commit 05eaf1cf3e
15 changed files with 791 additions and 510 deletions

View file

@ -81,6 +81,31 @@ func (r *Repository) CanCreateBranch() bool {
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
func RepoMustNotBeArchived() func(ctx *Context) {
return func(ctx *Context) {
@ -1053,6 +1078,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag
ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit
ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch()
ctx.Data["AllUnitsEnabled"] = ctx.Repo.AllUnitsEnabled(ctx)
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
if err != nil {