Skip to content

Commit

Permalink
fix!: Rename p-type column to ptype & PType to Ptype (#54)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename `p-type` column in the database to `ptype` and  Filter.PType to Filter.Ptype
  • Loading branch information
JalinWang authored Aug 9, 2022
1 parent 7a90dd8 commit 84f074b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (the *CasbinRule) TableName() string {

// CasbinRule .
type CasbinRule struct {
PType string `xorm:"varchar(100) index not null default ''"`
Ptype string `xorm:"varchar(100) index not null default ''"`
V0 string `xorm:"varchar(100) index not null default ''"`
V1 string `xorm:"varchar(100) index not null default ''"`
V2 string `xorm:"varchar(100) index not null default ''"`
Expand All @@ -60,7 +60,7 @@ type Adapter struct {

// Filter .
type Filter struct {
PType []string
Ptype []string
V0 []string
V1 []string
V2 []string
Expand Down Expand Up @@ -249,7 +249,7 @@ func (a *Adapter) dropTable() error {
}

func loadPolicyLine(line *CasbinRule, model model.Model) {
var p = []string{line.PType,
var p = []string{line.Ptype,
line.V0, line.V1, line.V2, line.V3, line.V4, line.V5}
var lineText string
if line.V5 != "" {
Expand Down Expand Up @@ -285,7 +285,7 @@ func (a *Adapter) LoadPolicy(model model.Model) error {
}

func (a *Adapter) genPolicyLine(ptype string, rule []string) *CasbinRule {
line := CasbinRule{PType: ptype, tableName: a.getFullTableName()}
line := CasbinRule{Ptype: ptype, tableName: a.getFullTableName()}

l := len(rule)
if l > 0 {
Expand Down Expand Up @@ -393,7 +393,7 @@ func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) err

// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error {
line := CasbinRule{PType: ptype, tableName: a.getFullTableName()}
line := CasbinRule{Ptype: ptype, tableName: a.getFullTableName()}

idx := fieldIndex + len(fieldValues)
if fieldIndex <= 0 && idx > 0 {
Expand Down Expand Up @@ -448,7 +448,7 @@ func (a *Adapter) filterQuery(session *xorm.Session, filter Filter) *xorm.Sessio
col string
val []string
}{
{"p_type", filter.PType},
{"ptype", filter.Ptype},
{"v0", filter.V0},
{"v1", filter.V1},
{"v2", filter.V2},
Expand Down Expand Up @@ -501,7 +501,7 @@ func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [
// UpdateFilteredPolicies deletes old rules and adds new rules.
line := &CasbinRule{}

line.PType = ptype
line.Ptype = ptype
if fieldIndex <= 0 && 0 < fieldIndex+len(fieldValues) {
line.V0 = fieldValues[0-fieldIndex]
}
Expand Down Expand Up @@ -557,8 +557,8 @@ func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [

func (c *CasbinRule) toStringPolicy() []string {
policy := make([]string, 0)
if c.PType != "" {
policy = append(policy, c.PType)
if c.Ptype != "" {
policy = append(policy, c.Ptype)
}
if c.V0 != "" {
policy = append(policy, c.V0)
Expand All @@ -582,9 +582,9 @@ func (c *CasbinRule) toStringPolicy() []string {
}

func (c *CasbinRule) queryString() (interface{}, []interface{}) {
queryArgs := []interface{}{c.PType}
queryArgs := []interface{}{c.Ptype}

queryStr := "p_type = ?"
queryStr := "ptype = ?"
if c.V0 != "" {
queryStr += " and v0 = ?"
queryArgs = append(queryArgs, c.V0)
Expand Down

0 comments on commit 84f074b

Please sign in to comment.