From 25b379af201155e5d9e2c1843c2f660fcdf92d3d Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 21 Feb 2019 15:28:08 +0100 Subject: [PATCH] Migrator for user updated with *tenant --- migrator/user.go | 17 +++++++---------- migrator/user_test.go | 32 +++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/migrator/user.go b/migrator/user.go index 1c8a19b59..e68c3bb2a 100644 --- a/migrator/user.go +++ b/migrator/user.go @@ -52,7 +52,7 @@ func (ud *v1UserProfile) SetId(id string) error { func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributeProfile) { usrFltr := config.CgrConfig().MigratorCgrCfg().UsersFilters attr = &engine.AttributeProfile{ - Tenant: user.Tenant, + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: user.UserName, Contexts: []string{utils.META_ANY}, FilterIDs: make([]string, 0), @@ -61,20 +61,17 @@ func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributePr Blocker: false, Weight: user.Weight, } + attr.Attributes = append(attr.Attributes, &engine.Attribute{ + FieldName: utils.MetaTenant, + Initial: utils.META_ANY, + Substitute: config.NewRSRParsersMustCompile(user.Tenant, true, utils.INFIELD_SEP), + Append: true, + }) for fieldname, substitute := range user.Profile { if utils.IsSliceMember(usrFltr, fieldname) { 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 a69c8fed3..7c6113ead 100644 --- a/migrator/user_test.go +++ b/migrator/user_test.go @@ -66,9 +66,8 @@ func TestUserProfile2attributeProfile(t *testing.T) { UserName: "1001", Masked: false, Profile: map[string]string{ - "Account": "1002", - "ReqType": "*prepaid", - utils.Tenant: "cgrates2.org", + "Account": "1002", + "ReqType": "*prepaid", }, Weight: 10, }, @@ -80,9 +79,16 @@ func TestUserProfile2attributeProfile(t *testing.T) { Contexts: []string{utils.META_ANY}, FilterIDs: make([]string, 0), ActivationInterval: nil, - Attributes: make([]*engine.Attribute, 0), - Blocker: false, - Weight: 10, + Attributes: []*engine.Attribute{ + { + FieldName: utils.MetaTenant, + Initial: utils.META_ANY, + Substitute: config.NewRSRParsersMustCompile(defaultTenant, true, utils.INFIELD_SEP), + Append: true, + }, + }, + Blocker: false, + Weight: 10, }, 1: { Tenant: defaultTenant, @@ -91,6 +97,12 @@ func TestUserProfile2attributeProfile(t *testing.T) { FilterIDs: []string{"*string:Account:1002"}, ActivationInterval: nil, Attributes: []*engine.Attribute{ + { + FieldName: utils.MetaTenant, + Initial: utils.META_ANY, + Substitute: config.NewRSRParsersMustCompile(defaultTenant, true, utils.INFIELD_SEP), + Append: true, + }, { FieldName: "Subject", Initial: utils.META_ANY, @@ -108,6 +120,12 @@ func TestUserProfile2attributeProfile(t *testing.T) { FilterIDs: []string{"*string:Account:1002"}, ActivationInterval: nil, Attributes: []*engine.Attribute{ + { + FieldName: utils.MetaTenant, + Initial: utils.META_ANY, + Substitute: config.NewRSRParsersMustCompile(defaultTenant, true, utils.INFIELD_SEP), + Append: true, + }, { FieldName: "ReqType", Initial: utils.META_ANY, @@ -134,7 +152,7 @@ func TestUserProfile2attributeProfile(t *testing.T) { { FieldName: utils.MetaTenant, Initial: utils.META_ANY, - Substitute: config.NewRSRParsersMustCompile("cgrates2.org", true, utils.INFIELD_SEP), + Substitute: config.NewRSRParsersMustCompile(defaultTenant, true, utils.INFIELD_SEP), Append: true, }, {