feat: Trivial default quota configuration
This adds a new configuration setting: `[quota.default].TOTAL`, which will be used if no groups are configured for a particular user. The new option makes it possible to entirely skip configuring quotas via the API if all that one wants is a total size. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
parent
190b5a3859
commit
3b70949651
4 changed files with 86 additions and 4 deletions
25
models/quota/default.go
Normal file
25
models/quota/default.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package quota
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
func EvaluateDefault(used Used, forSubject LimitSubject) bool {
|
||||
groups := GroupList{
|
||||
&Group{
|
||||
Name: "builtin-default-group",
|
||||
Rules: []Rule{
|
||||
{
|
||||
Name: "builtin-default-rule",
|
||||
Limit: setting.Quota.Default.Total,
|
||||
Subjects: LimitSubjects{LimitSubjectSizeAll},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return groups.Evaluate(used, forSubject)
|
||||
}
|
|
@ -230,9 +230,9 @@ func (g *Group) Evaluate(used Used, forSubject LimitSubject) (bool, bool) {
|
|||
}
|
||||
|
||||
func (gl *GroupList) Evaluate(used Used, forSubject LimitSubject) bool {
|
||||
// If there are no groups, default to success:
|
||||
// If there are no groups, use the configured defaults:
|
||||
if gl == nil || len(*gl) == 0 {
|
||||
return true
|
||||
return EvaluateDefault(used, forSubject)
|
||||
}
|
||||
|
||||
for _, group := range *gl {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue