added alownegative,disabled to accountactions

also started maked for users
This commit is contained in:
Radu Ioan Fericean
2015-09-21 16:29:58 +03:00
parent ec5edea780
commit 7b53d35a7a
19 changed files with 104 additions and 72 deletions

View File

@@ -234,6 +234,8 @@ CREATE TABLE `tp_account_actions` (
`direction` varchar(8) NOT NULL,
`action_plan_tag` varchar(64),
`action_triggers_tag` varchar(64),
`allow_negative` BOOLEAN NOT NULL,
`disabled` BOOLEAN NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
@@ -347,6 +349,7 @@ CREATE TABLE tp_users (
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`user_name` varchar(64) NOT NULL,
`masked` BOOLEAN NOT NULL,
`attribute_name` varchar(64) NOT NULL,
`attribute_value` varchar(64) NOT NULL,
`created_at` TIMESTAMP,

View File

@@ -229,6 +229,8 @@ CREATE TABLE tp_account_actions (
direction VARCHAR(8) NOT NULL,
action_plan_tag VARCHAR(64),
action_triggers_tag VARCHAR(64),
allow_negative BOOLEAN NOT NULL,
disabled BOOLEAN NOT NULL,
created_at TIMESTAMP,
UNIQUE (tpid, loadid, tenant, account, direction)
);
@@ -342,6 +344,7 @@ CREATE TABLE tp_users (
tpid VARCHAR(64) NOT NULL,
tenant VARCHAR(64) NOT NULL,
user_name VARCHAR(64) NOT NULL,
masked BOOLEAN NOT NULL,
attribute_name VARCHAR(64) NOT NULL,
attribute_value VARCHAR(64) NOT NULL,
created_at TIMESTAMP

View File

@@ -1,6 +1,6 @@
#Tenant,Account,Direction,ActionPlanId,ActionTriggersId
cgrates.org,1001,*out,PREPAID_10,STANDARD_TRIGGERS
cgrates.org,1002,*out,PREPAID_10,STANDARD_TRIGGERS
cgrates.org,1003,*out,PREPAID_10,STANDARD_TRIGGERS
cgrates.org,1004,*out,PREPAID_10,STANDARD_TRIGGERS
cgrates.org,1005,*out,PREPAID_10,STANDARD_TRIGGERS
#Tenant,Account,Direction,ActionPlanId,ActionTriggersId,AllowNegative,Disabled
cgrates.org,1001,*out,PREPAID_10,STANDARD_TRIGGERS,,
cgrates.org,1002,*out,PREPAID_10,STANDARD_TRIGGERS,,
cgrates.org,1003,*out,PREPAID_10,STANDARD_TRIGGERS,,
cgrates.org,1004,*out,PREPAID_10,STANDARD_TRIGGERS,,
cgrates.org,1005,*out,PREPAID_10,STANDARD_TRIGGERS,,
1 #Tenant Account Direction ActionPlanId ActionTriggersId AllowNegative Disabled
2 cgrates.org 1001 *out PREPAID_10 STANDARD_TRIGGERS
3 cgrates.org 1002 *out PREPAID_10 STANDARD_TRIGGERS
4 cgrates.org 1003 *out PREPAID_10 STANDARD_TRIGGERS
5 cgrates.org 1004 *out PREPAID_10 STANDARD_TRIGGERS
6 cgrates.org 1005 *out PREPAID_10 STANDARD_TRIGGERS

View File

@@ -1,19 +1,19 @@
#Tenant[0],UserName[1],AttributeName[2],AttributeValue[3]
cgrates.org,1001,SysUserName,danb
cgrates.org,1001,SysPassword,hisPass321
cgrates.org,1001,Cli,+4986517174963
cgrates.org,1001,Account,1001
cgrates.org,1001,Subject,1001
cgrates.org,1001,Uuid,388539dfd4f5cefee8f488b78c6c244b9e19138e
cgrates.org,1001,ReqType,*prepaid
cgrates.org,1002,SysUserName,rif
cgrates.org,1002,RifAttr,RifVal
cgrates.org,1002,Account,1002
cgrates.org,1002,Subject,1002
cgrates.org,1002,Uuid,27f37edec0670fa34cf79076b80ef5021e39c5b5
cgrates.org,1004,SysUserName,danb4
cgrates.org,1004,SysPassword,hisPass321
cgrates.org,1004,Cli,+4986517174964
cgrates.org,1004,Account,1004
cgrates.org,1004,Subject,1004
cgrates.org,1004,ReqType,*rated
#Tenant[0],UserName[1],Maksed[2],AttributeName[3],AttributeValue[4]
cgrates.org,1001,,SysUserName,danb
cgrates.org,1001,,SysPassword,hisPass321
cgrates.org,1001,,Cli,+4986517174963
cgrates.org,1001,,Account,1001
cgrates.org,1001,,Subject,1001
cgrates.org,1001,,Uuid,388539dfd4f5cefee8f488b78c6c244b9e19138e
cgrates.org,1001,,ReqType,*prepaid
cgrates.org,1002,,SysUserName,rif
cgrates.org,1002,,RifAttr,RifVal
cgrates.org,1002,,Account,1002
cgrates.org,1002,,Subject,1002
cgrates.org,1002,,Uuid,27f37edec0670fa34cf79076b80ef5021e39c5b5
cgrates.org,1004,,SysUserName,danb4
cgrates.org,1004,,SysPassword,hisPass321
cgrates.org,1004,,Cli,+4986517174964
cgrates.org,1004,,Account,1004
cgrates.org,1004,,Subject,1004
cgrates.org,1004,,ReqType,*rated
1 #Tenant[0] UserName[1] Maksed[2] AttributeName[2] AttributeName[3] AttributeValue[3] AttributeValue[4]
2 cgrates.org 1001 SysUserName danb
3 cgrates.org 1001 SysPassword hisPass321
4 cgrates.org 1001 Cli +4986517174963
5 cgrates.org 1001 Account 1001
6 cgrates.org 1001 Subject 1001
7 cgrates.org 1001 Uuid 388539dfd4f5cefee8f488b78c6c244b9e19138e
8 cgrates.org 1001 ReqType *prepaid
9 cgrates.org 1002 SysUserName rif
10 cgrates.org 1002 RifAttr RifVal
11 cgrates.org 1002 Account 1002
12 cgrates.org 1002 Subject 1002
13 cgrates.org 1002 Uuid 27f37edec0670fa34cf79076b80ef5021e39c5b5
14 cgrates.org 1004 SysUserName danb4
15 cgrates.org 1004 SysPassword hisPass321
16 cgrates.org 1004 Cli +4986517174964
17 cgrates.org 1004 Account 1004
18 cgrates.org 1004 Subject 1004
19 cgrates.org 1004 ReqType *rated

View File

@@ -1,6 +1,6 @@
#Tenant,Account,Direction,ActionPlanTag,ActionTriggersTag
cgrates.org,1001,*out,PACKAGE_1001,STANDARD_TRIGGERS
cgrates.org,1002,*out,PACKAGE_10,STANDARD_TRIGGERS
cgrates.org,1003,*out,PACKAGE_10,STANDARD_TRIGGERS
cgrates.org,1004,*out,PACKAGE_10,STANDARD_TRIGGERS
cgrates.org,1007,*out,USE_SHARED_A,STANDARD_TRIGGERS
#Tenant,Account,Direction,ActionPlanTag,ActionTriggersTag,AllowNegative,Disabled
cgrates.org,1001,*out,PACKAGE_1001,STANDARD_TRIGGERS,,
cgrates.org,1002,*out,PACKAGE_10,STANDARD_TRIGGERS,,
cgrates.org,1003,*out,PACKAGE_10,STANDARD_TRIGGERS,,
cgrates.org,1004,*out,PACKAGE_10,STANDARD_TRIGGERS,,
cgrates.org,1007,*out,USE_SHARED_A,STANDARD_TRIGGERS,,
1 #Tenant Account Direction ActionPlanTag ActionTriggersTag AllowNegative Disabled
2 cgrates.org 1001 *out PACKAGE_1001 STANDARD_TRIGGERS
3 cgrates.org 1002 *out PACKAGE_10 STANDARD_TRIGGERS
4 cgrates.org 1003 *out PACKAGE_10 STANDARD_TRIGGERS
5 cgrates.org 1004 *out PACKAGE_10 STANDARD_TRIGGERS
6 cgrates.org 1007 *out USE_SHARED_A STANDARD_TRIGGERS

View File

@@ -1,19 +1,19 @@
#Tenant[0],UserName[1],AttributeName[2],AttributeValue[3]
cgrates.org,1001,SysUserName,danb
cgrates.org,1001,SysPassword,hisPass321
cgrates.org,1001,Cli,+4986517174963
cgrates.org,1001,Account,1001
cgrates.org,1001,Subject,1001
cgrates.org,1001,Uuid,388539dfd4f5cefee8f488b78c6c244b9e19138e
cgrates.org,1001,ReqType,*prepaid
cgrates.org,1002,SysUserName,rif
cgrates.org,1002,RifAttr,RifVal
cgrates.org,1002,Account,1002
cgrates.org,1002,Subject,1002
cgrates.org,1002,Uuid,27f37edec0670fa34cf79076b80ef5021e39c5b5
cgrates.org,1004,SysUserName,danb4
cgrates.org,1004,SysPassword,hisPass321
cgrates.org,1004,Cli,+4986517174964
cgrates.org,1004,Account,1004
cgrates.org,1004,Subject,1004
cgrates.org,1004,ReqType,*rated
#Tenant[0],UserName[1],Masked[2],AttributeName[3],AttributeValue[4]
cgrates.org,1001,,SysUserName,danb
cgrates.org,1001,,SysPassword,hisPass321
cgrates.org,1001,,Cli,+4986517174963
cgrates.org,1001,,Account,1001
cgrates.org,1001,,Subject,1001
cgrates.org,1001,,Uuid,388539dfd4f5cefee8f488b78c6c244b9e19138e
cgrates.org,1001,,ReqType,*prepaid
cgrates.org,1002,,SysUserName,rif
cgrates.org,1002,,RifAttr,RifVal
cgrates.org,1002,,Account,1002
cgrates.org,1002,,Subject,1002
cgrates.org,1002,,Uuid,27f37edec0670fa34cf79076b80ef5021e39c5b5
cgrates.org,1004,,SysUserName,danb4
cgrates.org,1004,,SysPassword,hisPass321
cgrates.org,1004,,Cli,+4986517174964
cgrates.org,1004,,Account,1004
cgrates.org,1004,,Subject,1004
cgrates.org,1004,,ReqType,*rated
1 #Tenant[0] UserName[1] Masked[2] AttributeName[2] AttributeName[3] AttributeValue[3] AttributeValue[4]
2 cgrates.org 1001 SysUserName danb
3 cgrates.org 1001 SysPassword hisPass321
4 cgrates.org 1001 Cli +4986517174963
5 cgrates.org 1001 Account 1001
6 cgrates.org 1001 Subject 1001
7 cgrates.org 1001 Uuid 388539dfd4f5cefee8f488b78c6c244b9e19138e
8 cgrates.org 1001 ReqType *prepaid
9 cgrates.org 1002 SysUserName rif
10 cgrates.org 1002 RifAttr RifVal
11 cgrates.org 1002 Account 1002
12 cgrates.org 1002 Subject 1002
13 cgrates.org 1002 Uuid 27f37edec0670fa34cf79076b80ef5021e39c5b5
14 cgrates.org 1004 SysUserName danb4
15 cgrates.org 1004 SysPassword hisPass321
16 cgrates.org 1004 Cli +4986517174964
17 cgrates.org 1004 Account 1004
18 cgrates.org 1004 Subject 1004
19 cgrates.org 1004 ReqType *rated

View File

@@ -190,15 +190,16 @@ CDRST2_WARN_ASR,,*min_asr,30,true,0,,,,,,,,,,,5,CDRST_WARN_HTTP,10
CDRST2_WARN_ACD,,*min_acd,3,true,0,,,,,,,,,,,5,CDRST_WARN_HTTP,10
`
accountActions = `
vdf,minitsboy,*out,MORE_MINUTES,STANDARD_TRIGGER
cgrates.org,12345,*out,TOPUP10_AT,STANDARD_TRIGGERS
cgrates.org,123456,*out,TOPUP10_AT,STANDARD_TRIGGERS
cgrates.org,remo,*out,TOPUP10_AT,
vdf,empty0,*out,TOPUP_SHARED0_AT,
vdf,empty10,*out,TOPUP_SHARED10_AT,
vdf,emptyX,*out,TOPUP_EMPTY_AT,
vdf,emptyY,*out,TOPUP_EMPTY_AT,
vdf,post,*out,POST_AT,
vdf,minitsboy,*out,MORE_MINUTES,STANDARD_TRIGGER,,
cgrates.org,12345,*out,TOPUP10_AT,STANDARD_TRIGGERS,,
cgrates.org,123456,*out,TOPUP10_AT,STANDARD_TRIGGERS,,
cgrates.org,remo,*out,TOPUP10_AT,,,
vdf,empty0,*out,TOPUP_SHARED0_AT,,,
vdf,empty10,*out,TOPUP_SHARED10_AT,,,
vdf,emptyX,*out,TOPUP_EMPTY_AT,,,
vdf,emptyY,*out,TOPUP_EMPTY_AT,,,
vdf,post,*out,POST_AT,,,
cgrates.org,alodis,*out,TOPUP_EMPTY_AT,,true,true
`
derivedCharges = `
@@ -217,9 +218,10 @@ CDRST2,,,,ACD,,,,,,,,,,,,,,,,,,,,
`
users = `
#Tenant[0],UserName[1],AttributeName[2],AttributeValue[3]
cgrates.org,rif,test0,val0
cgrates.org,rif,test1,val1
cgrates.org,dan,another,value
cgrates.org,rif,false,test0,val0
cgrates.org,rif,,test1,val1
cgrates.org,dan,,another,value
cgrates.org,mas,true,another,value
`
aliases = `
#Direction[0],Tenant[1],Category[2],Account[3],Subject[4],DestinationId[5],Group[6],Alias[7],Weight[8]
@@ -1021,7 +1023,7 @@ func TestLoadActionTriggers(t *testing.T) {
}
func TestLoadAccountActions(t *testing.T) {
if len(csvr.accountActions) != 9 {
if len(csvr.accountActions) != 10 {
t.Error("Failed to load account actions: ", len(csvr.accountActions))
}
aa := csvr.accountActions["*out:vdf:minitsboy"]
@@ -1117,7 +1119,7 @@ func TestLoadCdrStats(t *testing.T) {
}
func TestLoadUsers(t *testing.T) {
if len(csvr.users) != 2 {
if len(csvr.users) != 3 {
t.Error("Failed to load users: ", csvr.users)
}
user1 := &UserProfile{

View File

@@ -458,6 +458,8 @@ func (tps TpAccountActions) GetAccountActions() (map[string]*utils.TPAccountActi
Direction: tpAa.Direction,
ActionPlanId: tpAa.ActionPlanTag,
ActionTriggersId: tpAa.ActionTriggersTag,
AllowNegative: tpAa.AllowNegative,
Disabled: tpAa.Disabled,
}
aas[aacts.KeyId()] = aacts
}
@@ -729,6 +731,9 @@ func (tps TpUsers) GetUsers() (map[string]*utils.TPUsers, error) {
}
users[tp.GetId()] = user
}
if tp.Masked == true {
user.Masked = true
}
user.Profile = append(user.Profile,
&utils.TPUserProfile{
AttrName: tp.AttributeName,

View File

@@ -613,7 +613,7 @@ func TestTPAccountActionsAsExportSlice(t *testing.T) {
ActionTriggersId: "STANDARD_TRIGGERS",
}
expectedSlc := [][]string{
[]string{"cgrates.org", "1001", "*out", "PACKAGE_10_SHARED_A_5", "STANDARD_TRIGGERS"},
[]string{"cgrates.org", "1001", "*out", "PACKAGE_10_SHARED_A_5", "STANDARD_TRIGGERS", "false", "false"},
}
ms := APItoModelAccountAction(aa)
var slc [][]string

View File

@@ -216,6 +216,8 @@ type TpAccountAction struct {
Direction string `index:"2" re:"\*out\s*"`
ActionPlanTag string `index:"3" re:"\w+\s*"`
ActionTriggersTag string `index:"4" re:"\w+\s*"`
AllowNegative bool `index:"5" re:""`
Disabled bool `index:"6" re:""`
CreatedAt time.Time
}
@@ -330,8 +332,9 @@ type TpUser struct {
Tpid string
Tenant string `index:"0" re:""`
UserName string `index:"1" re:""`
AttributeName string `index:"2" re:""`
AttributeValue string `index:"3" re:""`
Masked bool `index:"2" re:""`
AttributeName string `index:"3" re:""`
AttributeValue string `index:"4" re:""`
}
func (tu *TpUser) GetId() string {

View File

@@ -234,6 +234,16 @@ func TestStorageCacheRemoveCachedAliases(t *testing.T) {
}
}
func TestStorageDisabledAccount(t *testing.T) {
acc, err := accountingStorage.GetAccount("*out:cgrates.org:alodis")
if err != nil || acc == nil {
t.Error("Error loading disabled user account: ", err, acc)
}
if acc.Disabled != true || acc.AllowNegative != true {
t.Errorf("Error loading user account properties: %+v", acc)
}
}
// Install fails to detect them and starting server will panic, these tests will fix this
func TestStoreInterfaces(t *testing.T) {
rds := new(RedisStorage)

View File

@@ -862,6 +862,8 @@ func (tpr *TpReader) LoadAccountActions() (err error) {
ub := &Account{
Id: aa.KeyId(),
ActionTriggers: aTriggers.Clone(),
AllowNegative: aa.AllowNegative,
Disabled: aa.Disabled,
}
tpr.accountActions[aa.KeyId()] = ub
aTimings, exists := tpr.actionPlans[aa.ActionPlanId]

View File

@@ -13,6 +13,7 @@ import (
type UserProfile struct {
Tenant string
UserName string
Masked bool
Profile map[string]string
ponder int
}

View File

@@ -49,7 +49,7 @@ DISABLE_ACNT,*disable_account,,,,,,,,,,,,,false,10
ENABLE_ACNT,*enable_account,,,,,,,,,,,,,false,10`
actionPlans := `TOPUP10_AT,TOPUP10_AC,ASAP,10`
actionTriggers := ``
accountActions := `cgrates.org,1,*out,TOPUP10_AT,`
accountActions := `cgrates.org,1,*out,TOPUP10_AT,,,`
derivedCharges := ``
cdrStats := ``
users := ``

View File

@@ -59,7 +59,7 @@ RP_ANY,DR_ANY_1CNT,*any,10`
actions := `TOPUP10_AC,*topup_reset,,,*monetary,*out,,*any,,,*unlimited,,0,10,false,10`
actionPlans := `TOPUP10_AT,TOPUP10_AC,*asap,10`
actionTriggers := ``
accountActions := `cgrates.org,testauthpostpaid1,*out,TOPUP10_AT,`
accountActions := `cgrates.org,testauthpostpaid1,*out,TOPUP10_AT,,,`
derivedCharges := ``
cdrStats := ``
users := ``

View File

@@ -58,7 +58,7 @@ TOPUP10_AC1,*topup_reset,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*
actionPlans := `TOPUP10_AT,TOPUP10_AC,ASAP,10
TOPUP10_AT,TOPUP10_AC1,ASAP,10`
actionTriggers := ``
accountActions := `cgrates.org,12344,*out,TOPUP10_AT,`
accountActions := `cgrates.org,12344,*out,TOPUP10_AT,,,`
derivedCharges := ``
cdrStats := ``
users := ``

View File

@@ -58,7 +58,7 @@ TOPUP10_AC1,*topup_reset,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*
actionPlans := `TOPUP10_AT,TOPUP10_AC,ASAP,10
TOPUP10_AT,TOPUP10_AC1,ASAP,10`
actionTriggers := ``
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,`
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,,,`
derivedCharges := ``
cdrStats := ``
users := ``

View File

@@ -56,7 +56,7 @@ RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10`
actions := `TOPUP10_AC1,*topup_reset,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40,10,false,10`
actionPlans := `TOPUP10_AT,TOPUP10_AC1,ASAP,10`
actionTriggers := ``
accountActions := `cgrates.org,12346,*out,TOPUP10_AT,`
accountActions := `cgrates.org,12346,*out,TOPUP10_AT,,,`
derivedCharges := ``
cdrStats := ``
users := ``

View File

@@ -342,6 +342,7 @@ type TPAliasValue struct {
type TPUsers struct {
TPid string
Tenant string
Masked bool
UserName string
Profile []*TPUserProfile
}
@@ -506,6 +507,8 @@ type TPAccountActions struct {
Direction string // Traffic direction
ActionPlanId string // Id of ActionPlan profile to use
ActionTriggersId string // Id of ActionTriggers profile to use
AllowNegative bool
Disabled bool
}
// Returns the id used in some nosql dbs (eg: redis)