From 7b53d35a7a2882ec2c455d510ef7818fe9f8635f Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 21 Sep 2015 16:29:58 +0300 Subject: [PATCH] added alownegative,disabled to accountactions also started maked for users --- .../mysql/create_tariffplan_tables.sql | 3 ++ .../postgres/create_tariffplan_tables.sql | 3 ++ .../prepaid1centpsec/AccountActions.csv | 12 +++--- data/tariffplans/prepaid1centpsec/Users.csv | 38 +++++++++---------- data/tariffplans/tutorial/AccountActions.csv | 12 +++--- data/tariffplans/tutorial/Users.csv | 38 +++++++++---------- engine/loader_csv_test.go | 30 ++++++++------- engine/model_helpers.go | 5 +++ engine/model_helpers_test.go | 2 +- engine/models.go | 7 +++- engine/storage_test.go | 10 +++++ engine/tp_reader.go | 2 + engine/users.go | 1 + general_tests/acntacts_test.go | 2 +- general_tests/auth_test.go | 2 +- general_tests/ddazmbl1_test.go | 2 +- general_tests/ddazmbl2_test.go | 2 +- general_tests/ddazmbl3_test.go | 2 +- utils/apitpdata.go | 3 ++ 19 files changed, 104 insertions(+), 72 deletions(-) diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 0678da19a..d03242600 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -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, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 004a53e36..06cfbb9f0 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -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 diff --git a/data/tariffplans/prepaid1centpsec/AccountActions.csv b/data/tariffplans/prepaid1centpsec/AccountActions.csv index dd63c2299..7f23f8664 100644 --- a/data/tariffplans/prepaid1centpsec/AccountActions.csv +++ b/data/tariffplans/prepaid1centpsec/AccountActions.csv @@ -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,, diff --git a/data/tariffplans/prepaid1centpsec/Users.csv b/data/tariffplans/prepaid1centpsec/Users.csv index 357d629a4..7c2ca95ed 100644 --- a/data/tariffplans/prepaid1centpsec/Users.csv +++ b/data/tariffplans/prepaid1centpsec/Users.csv @@ -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 diff --git a/data/tariffplans/tutorial/AccountActions.csv b/data/tariffplans/tutorial/AccountActions.csv index 77a4648fa..c3c6a8689 100644 --- a/data/tariffplans/tutorial/AccountActions.csv +++ b/data/tariffplans/tutorial/AccountActions.csv @@ -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,, diff --git a/data/tariffplans/tutorial/Users.csv b/data/tariffplans/tutorial/Users.csv index 357d629a4..24cc9575e 100644 --- a/data/tariffplans/tutorial/Users.csv +++ b/data/tariffplans/tutorial/Users.csv @@ -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 diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index ed1b3d657..8c8ae09f2 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -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{ diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 5b2b5a609..c6bce8970 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -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, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index a9f191d07..c2becfef6 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -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 diff --git a/engine/models.go b/engine/models.go index ba897438f..c8570e85c 100644 --- a/engine/models.go +++ b/engine/models.go @@ -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 { diff --git a/engine/storage_test.go b/engine/storage_test.go index 4061c5ca3..dc3a46022 100644 --- a/engine/storage_test.go +++ b/engine/storage_test.go @@ -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) diff --git a/engine/tp_reader.go b/engine/tp_reader.go index 3d47d141b..53ea336e0 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -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] diff --git a/engine/users.go b/engine/users.go index 8195f2129..676c9e5fd 100644 --- a/engine/users.go +++ b/engine/users.go @@ -13,6 +13,7 @@ import ( type UserProfile struct { Tenant string UserName string + Masked bool Profile map[string]string ponder int } diff --git a/general_tests/acntacts_test.go b/general_tests/acntacts_test.go index 78714a102..e4348e98e 100644 --- a/general_tests/acntacts_test.go +++ b/general_tests/acntacts_test.go @@ -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 := `` diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index f7ad7e739..def8b9aa5 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -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 := `` diff --git a/general_tests/ddazmbl1_test.go b/general_tests/ddazmbl1_test.go index 4ee259183..759feebf0 100644 --- a/general_tests/ddazmbl1_test.go +++ b/general_tests/ddazmbl1_test.go @@ -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 := `` diff --git a/general_tests/ddazmbl2_test.go b/general_tests/ddazmbl2_test.go index 711cffae3..f2382960e 100644 --- a/general_tests/ddazmbl2_test.go +++ b/general_tests/ddazmbl2_test.go @@ -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 := `` diff --git a/general_tests/ddazmbl3_test.go b/general_tests/ddazmbl3_test.go index 2bd14036b..e5d405744 100644 --- a/general_tests/ddazmbl3_test.go +++ b/general_tests/ddazmbl3_test.go @@ -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 := `` diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 328c86322..dac063e27 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -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)