mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-01 17:38:33 +00:00
feat(ui): add quota overview (#6602)
Add UI to the quota feature to see what quotas applies to you and if you're exceeding any quota, it's designed to be a general size overview although it's exclusively filled with quota features for now. There's also no UI to see what item is actually taking in the most size. Purely an quota overview. Screenshots:   With inspiration from concept by 0ko:  Co-authored-by: Otto Richter <git@otto.splvs.net> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6602 Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
6dad457552
commit
77a1af5ab8
24 changed files with 348 additions and 33 deletions
|
@ -5,6 +5,7 @@ package quota
|
|||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
@ -199,15 +200,20 @@ var affectsMap = map[LimitSubject]LimitSubjects{
|
|||
},
|
||||
}
|
||||
|
||||
func (g *Group) Evaluate(used Used, forSubject LimitSubject) (bool, bool) {
|
||||
// Evaluate returns whether the size used is acceptable for the topic if a rule
|
||||
// was found, and returns the smallest limit of all applicable rules or the
|
||||
// first limit found to be unacceptable for the size used.
|
||||
func (g *Group) Evaluate(used Used, forSubject LimitSubject) (bool, bool, int64) {
|
||||
var found bool
|
||||
foundLimit := int64(math.MaxInt64)
|
||||
for _, rule := range g.Rules {
|
||||
ok, has := rule.Evaluate(used, forSubject)
|
||||
if has {
|
||||
found = true
|
||||
if !ok {
|
||||
return false, true
|
||||
return false, true, rule.Limit
|
||||
}
|
||||
found = true
|
||||
foundLimit = min(foundLimit, rule.Limit)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,32 +222,35 @@ func (g *Group) Evaluate(used Used, forSubject LimitSubject) (bool, bool) {
|
|||
// subjects below
|
||||
|
||||
for _, subject := range affectsMap[forSubject] {
|
||||
ok, has := g.Evaluate(used, subject)
|
||||
ok, has, limit := g.Evaluate(used, subject)
|
||||
if has {
|
||||
found = true
|
||||
if !ok {
|
||||
return false, true
|
||||
return false, true, limit
|
||||
}
|
||||
found = true
|
||||
foundLimit = min(foundLimit, limit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, found
|
||||
return true, found, foundLimit
|
||||
}
|
||||
|
||||
func (gl *GroupList) Evaluate(used Used, forSubject LimitSubject) bool {
|
||||
// Evaluate returns if the used size is acceptable for the subject and the
|
||||
// lowest limit that is acceptable for the subject.
|
||||
func (gl *GroupList) Evaluate(used Used, forSubject LimitSubject) (bool, int64) {
|
||||
// If there are no groups, use the configured defaults:
|
||||
if gl == nil || len(*gl) == 0 {
|
||||
return EvaluateDefault(used, forSubject)
|
||||
}
|
||||
|
||||
for _, group := range *gl {
|
||||
ok, has := group.Evaluate(used, forSubject)
|
||||
ok, has, limit := group.Evaluate(used, forSubject)
|
||||
if has && ok {
|
||||
return true
|
||||
return true, limit
|
||||
}
|
||||
}
|
||||
return false
|
||||
return false, 0
|
||||
}
|
||||
|
||||
func GetGroupByName(ctx context.Context, name string) (*Group, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue