diff --git a/migrator/user.go b/migrator/user.go index 36cd60349..1c8a19b59 100644 --- a/migrator/user.go +++ b/migrator/user.go @@ -66,6 +66,15 @@ func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributePr attr.FilterIDs = append(attr.FilterIDs, fmt.Sprintf("*string:%s:%s", fieldname, substitute)) continue } + if fieldname == utils.Tenant { + attr.Attributes = append(attr.Attributes, &engine.Attribute{ + FieldName: utils.MetaTenant, + Initial: utils.META_ANY, + Substitute: config.NewRSRParsersMustCompile(substitute, true, utils.INFIELD_SEP), + Append: true, + }) + continue + } attr.Attributes = append(attr.Attributes, &engine.Attribute{ FieldName: fieldname, Initial: utils.META_ANY, diff --git a/migrator/user_test.go b/migrator/user_test.go index 82c2768cd..a69c8fed3 100644 --- a/migrator/user_test.go +++ b/migrator/user_test.go @@ -19,7 +19,6 @@ along with this program. If not, see package migrator import ( - "path" "reflect" "sort" "testing" @@ -30,11 +29,7 @@ import ( ) func TestUserProfile2attributeProfile(t *testing.T) { - inPath := path.Join("/usr/share/cgrates", "samples", "tutmongo") - usrCfgIn, err := config.NewCGRConfigFromFolder(inPath) - if err != nil { - t.Fatal(err) - } + usrCfgIn := config.CgrConfig() usrCfgIn.MigratorCgrCfg().UsersFilters = []string{"Account"} config.SetCgrConfig(usrCfgIn) users := map[int]*v1UserProfile{ @@ -66,6 +61,17 @@ func TestUserProfile2attributeProfile(t *testing.T) { }, Weight: 10, }, + 3: &v1UserProfile{ + Tenant: defaultTenant, + UserName: "1001", + Masked: false, + Profile: map[string]string{ + "Account": "1002", + "ReqType": "*prepaid", + utils.Tenant: "cgrates2.org", + }, + Weight: 10, + }, } expected := map[int]*engine.AttributeProfile{ 0: { @@ -118,6 +124,29 @@ func TestUserProfile2attributeProfile(t *testing.T) { Blocker: false, Weight: 10, }, + 3: { + Tenant: defaultTenant, + ID: "1001", + Contexts: []string{utils.META_ANY}, + FilterIDs: []string{"*string:Account:1002"}, + ActivationInterval: nil, + Attributes: []*engine.Attribute{ + { + FieldName: utils.MetaTenant, + Initial: utils.META_ANY, + Substitute: config.NewRSRParsersMustCompile("cgrates2.org", true, utils.INFIELD_SEP), + Append: true, + }, + { + FieldName: "ReqType", + Initial: utils.META_ANY, + Substitute: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), + Append: true, + }, + }, + Blocker: false, + Weight: 10, + }, } for i := range expected { rply := userProfile2attributeProfile(users[i])