-
Notifications
You must be signed in to change notification settings - Fork 40
/
permission.go
51 lines (41 loc) · 1.9 KB
/
permission.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
package database
import (
"context"
"github.com/forbole/juno/v4/common"
"github.com/forbole/juno/v4/models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
func (db *DB) SavePermission(ctx context.Context, permission *models.Permission) error {
return nil
}
func (db *DB) UpdatePermission(ctx context.Context, permission *models.Permission) error {
return nil
}
func (db *DB) MultiSaveStatement(ctx context.Context, statements []*models.Statements) error {
return nil
}
func (db *DB) RemoveStatements(ctx context.Context, policyID common.Hash) error {
return nil
}
func (db *DB) SavePermissionToSQL(ctx context.Context, permission *models.Permission) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Permission{}).TableName()).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "principal_type"}, {Name: "principal_value"}, {Name: "resource_type"}, {Name: "resource_id"}},
UpdateAll: true,
}).Create(permission).Statement
return stat.SQL.String(), stat.Vars
}
func (db *DB) UpdatePermissionToSQL(ctx context.Context, permission *models.Permission) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Permission{}).TableName()).Where("policy_id = ?", permission.PolicyID).Updates(permission).Statement
return stat.SQL.String(), stat.Vars
}
func (db *DB) MultiSaveStatementToSQL(ctx context.Context, statements []*models.Statements) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{
DryRun: true,
}).Table((&models.Statements{}).TableName()).Create(statements).Statement
return stat.SQL.String(), stat.Vars
}
func (db *DB) RemoveStatementsToSQL(ctx context.Context, policyID common.Hash) (string, []interface{}) {
stat := db.Db.Session(&gorm.Session{DryRun: true}).Table((&models.Statements{}).TableName()).Where("policy_id = ?", policyID).Update("removed", true).Statement
return stat.SQL.String(), stat.Vars
}