mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-15 00:22:44 +01:00
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>
37 lines
750 B
Go
37 lines
750 B
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package quota
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
)
|
|
|
|
func init() {
|
|
db.RegisterModel(new(Rule))
|
|
db.RegisterModel(new(Group))
|
|
db.RegisterModel(new(GroupRuleMapping))
|
|
db.RegisterModel(new(GroupMapping))
|
|
}
|
|
|
|
func EvaluateForUser(ctx context.Context, userID int64, subject LimitSubject) (bool, error) {
|
|
if !setting.Quota.Enabled {
|
|
return true, nil
|
|
}
|
|
|
|
groups, err := GetGroupsForUser(ctx, userID)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
used, err := GetUsedForUser(ctx, userID)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
acceptable, _ := groups.Evaluate(*used, subject)
|
|
return acceptable, nil
|
|
}
|