-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository_policy.go
65 lines (55 loc) · 1.44 KB
/
repository_policy.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package goacl
import (
"context"
)
func (a *ACL) GetPolicyIDsByRoleID(ctx context.Context, roleID int64) ([]int64, error) {
var policyIDs []int64
err := a.DB.NewSelect().
Model((*Policy)(nil)).
Column("id").
Where("role_id = ?", roleID).
Scan(ctx, &policyIDs)
if err != nil {
return nil, err
}
return policyIDs, nil
}
func (a *ACL) GetPolicyIDsByFeatureID(ctx context.Context, featureID int64) ([]int64, error) {
var policyIDs []int64
err := a.DB.NewSelect().
Model((*Policy)(nil)).
Column("id").
Where("feature_id = ?", featureID).
Scan(ctx, &policyIDs)
if err != nil {
return nil, err
}
return policyIDs, nil
}
func (a *ACL) GetPolicyIDsByFeatureIDAndSubFeatureID(ctx context.Context, featureID, subFeatureID int64) ([]int64, error) {
var policyIDs []int64
err := a.DB.NewSelect().
Model((*Policy)(nil)).
Column("id").
Where("feature_id = ?", featureID).
Where("sub_feature_id = ?", subFeatureID).
Scan(ctx, &policyIDs)
if err != nil {
return nil, err
}
return policyIDs, nil
}
func (a *ACL) GetPoliciesByRoleAndSubFeature(ctx context.Context, roleID, subFeatureID int64) ([]Policy, error) {
// Prepare a slice to hold the policies
var policies []Policy
// Query the policies for the given role and sub-feature
err := a.DB.NewSelect().
Model(&policies).
Where("role_id = ?", roleID).
Where("sub_feature_id = ?", subFeatureID).
Scan(ctx)
if err != nil {
return nil, err
}
return policies, nil
}