mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
@@ -1548,12 +1548,12 @@ func TestApierLocalGetAliases(t *testing.T) {
|
||||
}
|
||||
var alias engine.Alias
|
||||
//al.Direction, al.Tenant, al.Category, al.Account, al.Subject, al.Group
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_GROUP_RP, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil {
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_CONTEXT_RATING, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil {
|
||||
t.Error("Unexpected nil error received")
|
||||
} else if err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error("Unexpected error", err.Error())
|
||||
}
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_GROUP_ACC, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil {
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_CONTEXT_RATING, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil {
|
||||
t.Error("Unexpected nil error received")
|
||||
} else if err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error("Unexpected error", err.Error())
|
||||
@@ -1573,7 +1573,7 @@ func TestApierLocalAddRatingSubjectAliases(t *testing.T) {
|
||||
}
|
||||
var alias engine.Alias
|
||||
for _, als := range addRtSubjAliases.Aliases {
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_GROUP_RP, Direction: "*out", Tenant: addRtSubjAliases.Tenant, Category: addRtSubjAliases.Category,
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_CONTEXT_RATING, Direction: "*out", Tenant: addRtSubjAliases.Tenant, Category: addRtSubjAliases.Category,
|
||||
Account: als, Subject: als}, &alias); err != nil {
|
||||
t.Error("Unexpected error", err.Error())
|
||||
}
|
||||
@@ -1593,7 +1593,7 @@ func TestApierLocalRemRatingSubjectAliases(t *testing.T) {
|
||||
}
|
||||
var alias engine.Alias
|
||||
//al.Direction, al.Tenant, al.Category, al.Account, al.Subject, al.Group
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_GROUP_RP, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_CONTEXT_RATING, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Unexpected error %v, alias: %+v", err, alias)
|
||||
}
|
||||
}
|
||||
@@ -1611,7 +1611,7 @@ func TestApierLocalAddAccountAliases(t *testing.T) {
|
||||
}
|
||||
var alias engine.Alias
|
||||
for _, als := range addAcntAliases.Aliases {
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_GROUP_ACC, Direction: "*out", Tenant: addAcntAliases.Tenant, Category: addAcntAliases.Category,
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_CONTEXT_RATING, Direction: "*out", Tenant: addAcntAliases.Tenant, Category: addAcntAliases.Category,
|
||||
Account: als, Subject: als}, &alias); err != nil {
|
||||
t.Error("Unexpected error", err.Error())
|
||||
}
|
||||
@@ -1631,7 +1631,7 @@ func TestApierLocalRemAccountAliases(t *testing.T) {
|
||||
}
|
||||
var alias engine.Alias
|
||||
//al.Direction, al.Tenant, al.Category, al.Account, al.Subject, al.Group
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_GROUP_ACC, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
if err := rater.Call("AliasesV1.GetAlias", engine.Alias{Context: utils.ALIAS_CONTEXT_RATING, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "2001", Subject: "2001"}, &alias); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Unexpected error %v, alias: %+v", err, alias)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,10 @@ import (
|
||||
|
||||
// Returns MaxUsage (for calls in seconds), -1 for no limit
|
||||
func (self *ApierV1) GetMaxUsage(usageRecord engine.UsageRecord, maxUsage *float64) error {
|
||||
out, err := engine.LoadUserProfile(&usageRecord, "ExtraFields")
|
||||
err := engine.LoadUserProfile(&usageRecord, "ExtraFields")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
usageRecord = *(out.(*engine.UsageRecord))
|
||||
if usageRecord.TOR == "" {
|
||||
usageRecord.TOR = utils.VOICE
|
||||
}
|
||||
|
||||
@@ -27,12 +27,11 @@ func (self *ApierV1) DebitUsage(usageRecord engine.UsageRecord, reply *string) e
|
||||
if missing := utils.MissingStructFields(&usageRecord, []string{"Account", "Destination", "Usage"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
out, err := engine.LoadUserProfile(usageRecord, "")
|
||||
err := engine.LoadUserProfile(usageRecord, "")
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
return err
|
||||
}
|
||||
usageRecord = out.(engine.UsageRecord)
|
||||
if usageRecord.TOR == "" {
|
||||
usageRecord.TOR = utils.VOICE
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#Direction,Tenant,Category,Account,Subject,DestinationId,Context,Target,Original,Alias,Weight
|
||||
*out,cgrates.org,call,1006,1006,*any,*rating_profile,Subject,1006,1001,10
|
||||
*out,cgrates.org,call,1006,1006,*any,*account,Account,1006,1002,10
|
||||
*out,cgrates.org,call,1006,1006,*any,*rating,Subject,1006,1001,10
|
||||
*out,cgrates.org,call,1006,1006,*any,*rating,Account,1006,1002,10
|
||||
|
||||
|
@@ -1,3 +1,3 @@
|
||||
#Direction,Tenant,Category,Account,Subject,DestinationId,Context,Target,Original,Alias,Weight
|
||||
*out,cgrates.org,call,1006,1006,*any,*rating_profile,Subject,1006,1001,10
|
||||
*out,cgrates.org,call,1006,1006,*any,*account,Account,1006,1002,10
|
||||
*out,cgrates.org,call,1006,1006,*any,*rating,Subject,1006,1001,10
|
||||
*out,cgrates.org,call,1006,1006,*any,*rating,Account,1006,1002,10
|
||||
|
||||
|
@@ -316,7 +316,7 @@ func (am *AliasHandler) GetMatchingAlias(attr AttrMatchingAlias, result *string)
|
||||
dId := idId.(string)
|
||||
if value.DestinationId == utils.ANY || value.DestinationId == dId {
|
||||
if origAliasMap, ok := value.Pairs[attr.Target]; ok {
|
||||
if alias, ok := origAliasMap[attr.Original]; ok {
|
||||
if alias, ok := origAliasMap[attr.Original]; ok || attr.Original == "" || attr.Original == utils.ANY {
|
||||
*result = alias
|
||||
return nil
|
||||
}
|
||||
@@ -377,9 +377,9 @@ func (ps *ProxyAliasService) ReloadAliases(in string, reply *string) error {
|
||||
return ps.Client.Call("AliasesV1.ReloadAliases", in, reply)
|
||||
}
|
||||
|
||||
func LoadAlias(attr *AttrMatchingAlias, in interface{}, extraFields string) (interface{}, error) {
|
||||
func LoadAlias(attr *AttrMatchingAlias, in interface{}, extraFields string) error {
|
||||
if aliasService == nil { // no alias service => no fun
|
||||
return in, nil
|
||||
return nil
|
||||
}
|
||||
response := Alias{}
|
||||
if err := aliasService.GetAlias(Alias{
|
||||
@@ -390,7 +390,7 @@ func LoadAlias(attr *AttrMatchingAlias, in interface{}, extraFields string) (int
|
||||
Subject: attr.Subject,
|
||||
Context: attr.Context,
|
||||
}, &response); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
// sort according to weight
|
||||
@@ -440,7 +440,7 @@ func LoadAlias(attr *AttrMatchingAlias, in interface{}, extraFields string) (int
|
||||
field := v.FieldByName(target)
|
||||
if field.IsValid() {
|
||||
if field.Kind() == reflect.String {
|
||||
if field.String() == original && field.CanSet() {
|
||||
if field.CanSet() && (original == "" || original == utils.ANY || field.String() == original) {
|
||||
field.SetString(alias)
|
||||
}
|
||||
}
|
||||
@@ -451,7 +451,7 @@ func LoadAlias(attr *AttrMatchingAlias, in interface{}, extraFields string) (int
|
||||
keys := efField.MapKeys()
|
||||
for _, key := range keys {
|
||||
if key.Kind() == reflect.String && key.String() == target {
|
||||
if efField.MapIndex(key).String() == original {
|
||||
if original == "" || original == utils.ANY || efField.MapIndex(key).String() == original {
|
||||
efField.SetMapIndex(key, reflect.ValueOf(alias))
|
||||
}
|
||||
}
|
||||
@@ -461,5 +461,5 @@ func LoadAlias(attr *AttrMatchingAlias, in interface{}, extraFields string) (int
|
||||
}
|
||||
}
|
||||
}
|
||||
return in, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func TestAliasesGetAlias(t *testing.T) {
|
||||
Category: "call",
|
||||
Account: "dan",
|
||||
Subject: "dan",
|
||||
Context: "*rating_profile",
|
||||
Context: "*rating",
|
||||
}, &alias)
|
||||
if err != nil ||
|
||||
len(alias.Values) != 2 ||
|
||||
@@ -30,7 +30,7 @@ func TestAliasesGetMatchingAlias(t *testing.T) {
|
||||
Category: "call",
|
||||
Account: "dan",
|
||||
Subject: "dan",
|
||||
Context: "*rating_profile",
|
||||
Context: "*rating",
|
||||
Destination: "444",
|
||||
Target: "Subject",
|
||||
Original: "rif",
|
||||
@@ -54,24 +54,21 @@ func TestAliasesLoadAlias(t *testing.T) {
|
||||
"Other": "stuff",
|
||||
},
|
||||
}
|
||||
in, err := LoadAlias(
|
||||
err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Direction: "*out",
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
Account: "dan",
|
||||
Subject: "dan",
|
||||
Context: "*rating_profile",
|
||||
Context: "*rating",
|
||||
Destination: "444",
|
||||
}, cd, "ExtraFields")
|
||||
if err != nil || in == nil {
|
||||
if err != nil || cd == nil {
|
||||
t.Error("Error getting alias: ", err, response)
|
||||
}
|
||||
if in != nil {
|
||||
newCd := in.(*CallDescriptor)
|
||||
if newCd.Subject != "rif1" ||
|
||||
newCd.ExtraFields["Cli"] != "0724" {
|
||||
t.Errorf("Aliases failed to change interface: %+v", newCd)
|
||||
}
|
||||
if cd.Subject != "rif1" ||
|
||||
cd.ExtraFields["Cli"] != "0724" {
|
||||
t.Errorf("Aliases failed to change interface: %+v", cd)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,24 +303,6 @@ func (cd *CallDescriptor) addRatingInfos(ris RatingInfos) bool {
|
||||
// GetKey constructs the key for the storage lookup.
|
||||
// The prefixLen is limiting the length of the destination prefix.
|
||||
func (cd *CallDescriptor) GetKey(subject string) string {
|
||||
// check if subject is alias
|
||||
if aliasService != nil {
|
||||
var alias string
|
||||
if err := aliasService.GetMatchingAlias(AttrMatchingAlias{
|
||||
Destination: cd.Destination,
|
||||
Direction: cd.Direction,
|
||||
Tenant: cd.Tenant,
|
||||
Category: cd.Category,
|
||||
Account: cd.Account,
|
||||
Subject: cd.Subject,
|
||||
Context: utils.ALIAS_GROUP_RP,
|
||||
Target: "Subject",
|
||||
Original: cd.Subject,
|
||||
}, &alias); err == nil && alias != "" {
|
||||
subject = alias
|
||||
cd.Subject = alias
|
||||
}
|
||||
}
|
||||
return utils.ConcatenatedKey(cd.Direction, cd.Tenant, cd.Category, subject)
|
||||
}
|
||||
|
||||
@@ -328,25 +310,6 @@ func (cd *CallDescriptor) GetKey(subject string) string {
|
||||
func (cd *CallDescriptor) GetAccountKey() string {
|
||||
subj := cd.Subject
|
||||
if cd.Account != "" {
|
||||
// check if subject is alias
|
||||
if aliasService != nil {
|
||||
var alias string
|
||||
err := aliasService.GetMatchingAlias(
|
||||
AttrMatchingAlias{
|
||||
Destination: cd.Destination,
|
||||
Direction: cd.Direction,
|
||||
Tenant: cd.Tenant,
|
||||
Category: cd.Category,
|
||||
Account: cd.Account,
|
||||
Subject: cd.Subject,
|
||||
Context: utils.ALIAS_GROUP_ACC,
|
||||
Target: "Account",
|
||||
Original: cd.Account,
|
||||
}, &alias)
|
||||
if err == nil && alias != "" {
|
||||
cd.Account = alias
|
||||
}
|
||||
}
|
||||
subj = cd.Account
|
||||
}
|
||||
return utils.ConcatenatedKey(cd.Direction, cd.Tenant, subj)
|
||||
|
||||
@@ -627,6 +627,17 @@ func TestMaxSessionTimeWithAccountAlias(t *testing.T) {
|
||||
Account: "a1",
|
||||
Destination: "0723",
|
||||
}
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: cd.Destination,
|
||||
Direction: cd.Direction,
|
||||
Tenant: cd.Tenant,
|
||||
Category: cd.Category,
|
||||
Account: cd.Account,
|
||||
Subject: cd.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, cd, utils.EXTRA_FIELDS)
|
||||
|
||||
result, err := cd.GetMaxSessionDuration()
|
||||
expected := time.Minute
|
||||
if result != expected || err != nil {
|
||||
|
||||
@@ -167,11 +167,8 @@ func (self *CdrServer) processCdr(storedCdr *StoredCdr) (err error) {
|
||||
storedCdr.Subject = storedCdr.Account
|
||||
}
|
||||
|
||||
if upData, err := LoadUserProfile(storedCdr, "ExtraFields"); err != nil {
|
||||
if err := LoadUserProfile(storedCdr, "ExtraFields"); err != nil {
|
||||
return err
|
||||
} else {
|
||||
cdrRcv := upData.(*StoredCdr)
|
||||
*storedCdr = *cdrRcv
|
||||
}
|
||||
if storedCdr.ReqType == utils.META_NONE {
|
||||
return nil
|
||||
|
||||
@@ -222,14 +222,14 @@ cgrates.org,dan,another,value
|
||||
`
|
||||
aliases = `
|
||||
#Direction[0],Tenant[1],Category[2],Account[3],Subject[4],DestinationId[5],Group[6],Alias[7],Weight[8]
|
||||
*out,cgrates.org,call,dan,dan,EU_LANDLINE,*rating_profile,Subject,dan,dan1,10
|
||||
*out,cgrates.org,call,dan,dan,EU_LANDLINE,*rating_profile,Subject,rif,rif1,10
|
||||
*out,cgrates.org,call,dan,dan,EU_LANDLINE,*rating_profile,Cli,0723,0724,10
|
||||
*out,cgrates.org,call,dan,dan,GLOBAL1,*rating_profile,Subject,dan,dan2,20
|
||||
*any,*any,*any,*any,*any,*any,*rating_profile,Subject,*any,rif1,20
|
||||
*any,*any,*any,*any,*any,*any,*account,Account,*any,dan1,10
|
||||
*out,vdf,0,a1,a1,*any,*rating_profile,Subject,a1,minu,10
|
||||
*out,vdf,0,a1,a1,*any,*account,Account,a1,minu,10
|
||||
*out,cgrates.org,call,dan,dan,EU_LANDLINE,*rating,Subject,dan,dan1,10
|
||||
*out,cgrates.org,call,dan,dan,EU_LANDLINE,*rating,Subject,rif,rif1,10
|
||||
*out,cgrates.org,call,dan,dan,EU_LANDLINE,*rating,Cli,0723,0724,10
|
||||
*out,cgrates.org,call,dan,dan,GLOBAL1,*rating,Subject,dan,dan2,20
|
||||
*any,*any,*any,*any,*any,*any,*rating,Subject,*any,rif1,20
|
||||
*any,*any,*any,*any,*any,*any,*rating,Account,*any,dan1,10
|
||||
*out,vdf,0,a1,a1,*any,*rating,Subject,a1,minu,10
|
||||
*out,vdf,0,a1,a1,*any,*rating,Account,a1,minu,10
|
||||
`
|
||||
)
|
||||
|
||||
@@ -1132,8 +1132,8 @@ func TestLoadUsers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadAliases(t *testing.T) {
|
||||
if len(csvr.aliases) != 5 {
|
||||
t.Error("Failed to load aliases: ", csvr.aliases)
|
||||
if len(csvr.aliases) != 3 {
|
||||
t.Error("Failed to load aliases: ", len(csvr.aliases))
|
||||
}
|
||||
alias1 := &Alias{
|
||||
Direction: "*out",
|
||||
@@ -1141,7 +1141,7 @@ func TestLoadAliases(t *testing.T) {
|
||||
Category: "call",
|
||||
Account: "dan",
|
||||
Subject: "dan",
|
||||
Context: "*rating_profile",
|
||||
Context: "*rating",
|
||||
Values: AliasValues{
|
||||
&AliasValue{
|
||||
DestinationId: "EU_LANDLINE",
|
||||
|
||||
@@ -81,11 +81,20 @@ func (rs *Responder) GetCost(arg *CallDescriptor, reply *CallCost) (err error) {
|
||||
if arg.Subject == "" {
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(arg, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
Tenant: arg.Tenant,
|
||||
Category: arg.Category,
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*CallDescriptor)
|
||||
*arg = *udRcv
|
||||
}
|
||||
if rs.Bal != nil {
|
||||
r, e := rs.getCallCost(arg, "Responder.GetCost")
|
||||
@@ -107,11 +116,20 @@ func (rs *Responder) Debit(arg *CallDescriptor, reply *CallCost) (err error) {
|
||||
if arg.Subject == "" {
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(arg, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
Tenant: arg.Tenant,
|
||||
Category: arg.Category,
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*CallDescriptor)
|
||||
*arg = *udRcv
|
||||
}
|
||||
if rs.Bal != nil {
|
||||
r, e := rs.getCallCost(arg, "Responder.Debit")
|
||||
@@ -135,11 +153,20 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
|
||||
if arg.Subject == "" {
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(arg, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
Tenant: arg.Tenant,
|
||||
Category: arg.Category,
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*CallDescriptor)
|
||||
*arg = *udRcv
|
||||
}
|
||||
if rs.Bal != nil {
|
||||
r, e := rs.getCallCost(arg, "Responder.MaxDebit")
|
||||
@@ -170,11 +197,20 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
|
||||
if arg.Subject == "" {
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(arg, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
Tenant: arg.Tenant,
|
||||
Category: arg.Category,
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*CallDescriptor)
|
||||
*arg = *udRcv
|
||||
}
|
||||
if rs.Bal != nil {
|
||||
*reply, err = rs.callMethod(arg, "Responder.RefundIncrements")
|
||||
@@ -195,11 +231,20 @@ func (rs *Responder) GetMaxSessionTime(arg *CallDescriptor, reply *float64) (err
|
||||
if arg.Subject == "" {
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(arg, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
Tenant: arg.Tenant,
|
||||
Category: arg.Category,
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*CallDescriptor)
|
||||
*arg = *udRcv
|
||||
}
|
||||
if rs.Bal != nil {
|
||||
*reply, err = rs.callMethod(arg, "Responder.GetMaxSessionTime")
|
||||
@@ -218,11 +263,21 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *StoredCdr, reply *float64) err
|
||||
if ev.Subject == "" {
|
||||
ev.Subject = ev.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(ev, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: ev.Destination,
|
||||
Direction: ev.Direction,
|
||||
Tenant: ev.Tenant,
|
||||
Category: ev.Category,
|
||||
Account: ev.Account,
|
||||
Subject: ev.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, ev, utils.EXTRA_FIELDS)
|
||||
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*StoredCdr)
|
||||
*ev = *udRcv
|
||||
}
|
||||
maxCallDuration := -1.0
|
||||
attrsDC := &utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Category: ev.GetCategory(utils.META_DEFAULT), Direction: ev.GetDirection(utils.META_DEFAULT),
|
||||
@@ -296,11 +351,20 @@ func (rs *Responder) GetSessionRuns(ev *StoredCdr, sRuns *[]*SessionRun) error {
|
||||
if ev.Subject == "" {
|
||||
ev.Subject = ev.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(ev, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: ev.Destination,
|
||||
Direction: ev.Direction,
|
||||
Tenant: ev.Tenant,
|
||||
Category: ev.Category,
|
||||
Account: ev.Account,
|
||||
Subject: ev.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, ev, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*StoredCdr)
|
||||
*ev = *udRcv
|
||||
}
|
||||
attrsDC := &utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Category: ev.GetCategory(utils.META_DEFAULT), Direction: ev.GetDirection(utils.META_DEFAULT),
|
||||
Account: ev.GetAccount(utils.META_DEFAULT), Subject: ev.GetSubject(utils.META_DEFAULT)}
|
||||
@@ -357,11 +421,20 @@ func (rs *Responder) ProcessCdr(cdr *StoredCdr, reply *string) error {
|
||||
if rs.CdrSrv == nil {
|
||||
return errors.New("CDR_SERVER_NOT_RUNNING")
|
||||
}
|
||||
if upData, err := LoadUserProfile(cdr, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: cdr.Destination,
|
||||
Direction: cdr.Direction,
|
||||
Tenant: cdr.Tenant,
|
||||
Category: cdr.Category,
|
||||
Account: cdr.Account,
|
||||
Subject: cdr.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, cdr, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(cdr, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*StoredCdr)
|
||||
*cdr = *udRcv
|
||||
}
|
||||
if err := rs.CdrSrv.ProcessCdr(cdr); err != nil {
|
||||
return err
|
||||
@@ -399,11 +472,21 @@ func (rs *Responder) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
|
||||
if attrs.CallDescriptor.Subject == "" {
|
||||
attrs.CallDescriptor.Subject = attrs.CallDescriptor.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(attrs.CallDescriptor, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
cd := attrs.CallDescriptor
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: cd.Destination,
|
||||
Direction: cd.Direction,
|
||||
Tenant: cd.Tenant,
|
||||
Category: cd.Category,
|
||||
Account: cd.Account,
|
||||
Subject: cd.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, cd, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(attrs.CallDescriptor, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*CallDescriptor)
|
||||
*attrs.CallDescriptor = *udRcv
|
||||
}
|
||||
lcrCost, err := attrs.CallDescriptor.GetLCR(rs.Stats, attrs.Paginator)
|
||||
if err != nil {
|
||||
|
||||
@@ -118,7 +118,7 @@ func TestStorageGetAliases(t *testing.T) {
|
||||
Category: "0",
|
||||
Account: "b1",
|
||||
Subject: "b1",
|
||||
Context: utils.ALIAS_GROUP_RP,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
Values: AliasValues{
|
||||
&AliasValue{
|
||||
Pairs: AliasPairs{"Subject": map[string]string{"b1": "aaa"}},
|
||||
@@ -133,7 +133,7 @@ func TestStorageGetAliases(t *testing.T) {
|
||||
Category: "0",
|
||||
Account: "b1",
|
||||
Subject: "b1",
|
||||
Context: utils.ALIAS_GROUP_ACC,
|
||||
Context: "*other",
|
||||
Values: AliasValues{
|
||||
&AliasValue{
|
||||
Pairs: AliasPairs{"Account": map[string]string{"b1": "aaa"}},
|
||||
@@ -169,7 +169,7 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
|
||||
Category: "0",
|
||||
Account: "b1",
|
||||
Subject: "b1",
|
||||
Context: utils.ALIAS_GROUP_RP,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}
|
||||
alb := &Alias{
|
||||
Direction: "*out",
|
||||
@@ -177,9 +177,9 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
|
||||
Category: "0",
|
||||
Account: "b1",
|
||||
Subject: "b1",
|
||||
Context: utils.ALIAS_GROUP_ACC,
|
||||
Context: "*other",
|
||||
}
|
||||
if x, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Subject" + utils.ALIAS_GROUP_RP); err == nil {
|
||||
if x, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Subject" + utils.ALIAS_CONTEXT_RATING); err == nil {
|
||||
aliasKeys := x.(map[string]bool)
|
||||
_, found := aliasKeys[utils.ConcatenatedKey(ala.GetId(), utils.ANY)]
|
||||
if !found {
|
||||
@@ -188,7 +188,7 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
|
||||
} else {
|
||||
t.Error("Error getting reverse alias: ", err)
|
||||
}
|
||||
if x, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Account" + utils.ALIAS_GROUP_ACC); err == nil {
|
||||
if x, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Account" + "*other"); err == nil {
|
||||
aliasKeys := x.(map[string]bool)
|
||||
_, found := aliasKeys[utils.ConcatenatedKey(alb.GetId(), utils.ANY)]
|
||||
if !found {
|
||||
@@ -206,7 +206,7 @@ func TestStorageCacheRemoveCachedAliases(t *testing.T) {
|
||||
Category: "0",
|
||||
Account: "b1",
|
||||
Subject: "b1",
|
||||
Context: utils.ALIAS_GROUP_RP,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}
|
||||
alb := &Alias{
|
||||
Direction: "*out",
|
||||
@@ -214,7 +214,7 @@ func TestStorageCacheRemoveCachedAliases(t *testing.T) {
|
||||
Category: "0",
|
||||
Account: "b1",
|
||||
Subject: "b1",
|
||||
Context: utils.ALIAS_GROUP_ACC,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}
|
||||
accountingStorage.RemoveAlias(ala.GetId())
|
||||
accountingStorage.RemoveAlias(alb.GetId())
|
||||
@@ -226,10 +226,10 @@ func TestStorageCacheRemoveCachedAliases(t *testing.T) {
|
||||
t.Error("Error removing cached alias: ", err)
|
||||
}
|
||||
|
||||
if _, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_GROUP_RP); err == nil {
|
||||
if _, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); err == nil {
|
||||
t.Error("Error removing cached reverse alias: ", err)
|
||||
}
|
||||
if _, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_GROUP_ACC); err == nil {
|
||||
if _, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); err == nil {
|
||||
t.Error("Error removing cached reverse alias: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,9 +410,9 @@ func (ps *ProxyUserService) ReloadUsers(in string, reply *string) error {
|
||||
}
|
||||
|
||||
// extraFields - Field name in the interface containing extraFields information
|
||||
func LoadUserProfile(in interface{}, extraFields string) (interface{}, error) {
|
||||
func LoadUserProfile(in interface{}, extraFields string) error {
|
||||
if userService == nil { // no user service => no fun
|
||||
return in, nil
|
||||
return nil
|
||||
}
|
||||
m := utils.ToMapStringString(in)
|
||||
var needsUsers bool
|
||||
@@ -423,7 +423,7 @@ func LoadUserProfile(in interface{}, extraFields string) (interface{}, error) {
|
||||
}
|
||||
}
|
||||
if !needsUsers { // Do not process further if user profile is not needed
|
||||
return in, nil
|
||||
return nil
|
||||
}
|
||||
up := &UserProfile{
|
||||
Profile: make(map[string]string),
|
||||
@@ -451,7 +451,7 @@ func LoadUserProfile(in interface{}, extraFields string) (interface{}, error) {
|
||||
}
|
||||
ups := UserProfiles{}
|
||||
if err := userService.GetUsers(*up, &ups); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if len(ups) > 0 {
|
||||
up = ups[0]
|
||||
@@ -459,7 +459,7 @@ func LoadUserProfile(in interface{}, extraFields string) (interface{}, error) {
|
||||
m["Tenant"] = up.Tenant
|
||||
utils.FromMapStringString(m, in)
|
||||
utils.SetMapExtraFields(in, m, extraFields)
|
||||
return in, nil
|
||||
return nil
|
||||
}
|
||||
return nil, utils.ErrNotFound
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -546,7 +546,7 @@ func TestUsersUsageRecordGetLoadUserProfile(t *testing.T) {
|
||||
Usage: "13",
|
||||
}
|
||||
|
||||
out, err := LoadUserProfile(ur, "")
|
||||
err := LoadUserProfile(ur, "")
|
||||
if err != nil {
|
||||
t.Error("Error loading user profile: ", err)
|
||||
}
|
||||
@@ -563,7 +563,6 @@ func TestUsersUsageRecordGetLoadUserProfile(t *testing.T) {
|
||||
AnswerTime: "t4",
|
||||
Usage: "13",
|
||||
}
|
||||
ur = out.(*UsageRecord)
|
||||
if !reflect.DeepEqual(ur, expected) {
|
||||
t.Errorf("Expected: %+v got: %+v", expected, ur)
|
||||
}
|
||||
@@ -597,7 +596,7 @@ func TestUsersExternalCdrGetLoadUserProfileExtraFields(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
out, err := LoadUserProfile(ur, "ExtraFields")
|
||||
err := LoadUserProfile(ur, "ExtraFields")
|
||||
if err != nil {
|
||||
t.Error("Error loading user profile: ", err)
|
||||
}
|
||||
@@ -617,7 +616,6 @@ func TestUsersExternalCdrGetLoadUserProfileExtraFields(t *testing.T) {
|
||||
"Test": "1",
|
||||
},
|
||||
}
|
||||
ur = out.(*ExternalCdr)
|
||||
if !reflect.DeepEqual(ur, expected) {
|
||||
t.Errorf("Expected: %+v got: %+v", expected, ur)
|
||||
}
|
||||
@@ -651,7 +649,7 @@ func TestUsersExternalCdrGetLoadUserProfileExtraFieldsNotFound(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := LoadUserProfile(ur, "ExtraFields")
|
||||
err := LoadUserProfile(ur, "ExtraFields")
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error("Error detecting err in loading user profile: ", err)
|
||||
}
|
||||
@@ -686,7 +684,7 @@ func TestUsersExternalCdrGetLoadUserProfileExtraFieldsSet(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
out, err := LoadUserProfile(ur, "ExtraFields")
|
||||
err := LoadUserProfile(ur, "ExtraFields")
|
||||
if err != nil {
|
||||
t.Error("Error loading user profile: ", err)
|
||||
}
|
||||
@@ -707,7 +705,6 @@ func TestUsersExternalCdrGetLoadUserProfileExtraFieldsSet(t *testing.T) {
|
||||
"Best": "BestValue",
|
||||
},
|
||||
}
|
||||
ur = out.(*ExternalCdr)
|
||||
if !reflect.DeepEqual(ur, expected) {
|
||||
t.Errorf("Expected: %+v got: %+v", expected, ur)
|
||||
}
|
||||
@@ -745,13 +742,12 @@ func TestUsersCallDescLoadUserProfile(t *testing.T) {
|
||||
TimeEnd: startTime.Add(time.Duration(1) * time.Minute),
|
||||
ExtraFields: map[string]string{"Cli": "+4986517174963"},
|
||||
}
|
||||
out, err := LoadUserProfile(cd, "ExtraFields")
|
||||
err := LoadUserProfile(cd, "ExtraFields")
|
||||
if err != nil {
|
||||
t.Error("Error loading user profile: ", err)
|
||||
}
|
||||
cdRcv := out.(*CallDescriptor)
|
||||
if !reflect.DeepEqual(expected, cdRcv) {
|
||||
t.Errorf("Expected: %+v got: %+v", expected, cdRcv)
|
||||
if !reflect.DeepEqual(expected, cd) {
|
||||
t.Errorf("Expected: %+v got: %+v", expected, cd)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -791,12 +787,11 @@ func TestUsersStoredCdrLoadUserProfile(t *testing.T) {
|
||||
Usage: time.Duration(1) * time.Minute,
|
||||
ExtraFields: map[string]string{"Cli": "+4986517174963"},
|
||||
}
|
||||
out, err := LoadUserProfile(cdr, "ExtraFields")
|
||||
err := LoadUserProfile(cdr, "ExtraFields")
|
||||
if err != nil {
|
||||
t.Error("Error loading user profile: ", err)
|
||||
}
|
||||
cdRcv := out.(*StoredCdr)
|
||||
if !reflect.DeepEqual(expected, cdRcv) {
|
||||
t.Errorf("Expected: %+v got: %+v", expected, cdRcv)
|
||||
if !reflect.DeepEqual(expected, cdr) {
|
||||
t.Errorf("Expected: %+v got: %+v", expected, cdr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,10 +227,10 @@ const (
|
||||
REFUND_INCR_CACHE_PREFIX = "REFUND_INCR_"
|
||||
GET_SESS_RUNS_CACHE_PREFIX = "GET_SESS_RUNS_"
|
||||
LOG_CALL_COST_CACHE_PREFIX = "LOG_CALL_COSTS_"
|
||||
ALIAS_GROUP_RP = "*rating_profile"
|
||||
ALIAS_GROUP_ACC = "*account"
|
||||
ALIAS_CONTEXT_RATING = "*rating"
|
||||
NOT_AVAILABLE = "N/A"
|
||||
CALL = "call"
|
||||
EXTRA_FIELDS = "ExtraFields"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user