summaryrefslogtreecommitdiffstats
path: root/models/quota/quota.go
blob: d38bfab3cc4f55f59d8b9ee63ba35567a89ee31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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
	}

	return groups.Evaluate(*used, subject), nil
}