diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 3dfe88432..878f8a1d6 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1128,7 +1128,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, type AttrRemoveRatingProfile struct { Direction string - Tennat string + Tenant string Category string Subject string } @@ -1140,8 +1140,8 @@ func (arrp *AttrRemoveRatingProfile) GetId() (result string) { } else { return } - if arrp.Tennat != "" && arrp.Tennat != utils.ANY { - result += arrp.Tennat + if arrp.Tenant != "" && arrp.Tenant != utils.ANY { + result += arrp.Tenant result += utils.CONCATENATED_KEY_SEP } else { return @@ -1160,14 +1160,13 @@ func (arrp *AttrRemoveRatingProfile) GetId() (result string) { } func (self *ApierV1) RemoveRatingProfile(attr AttrRemoveRatingProfile, reply *string) error { - if attr.Subject != "" && attr.Category == "" { - return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "Category") + if attr.Direction == "" { + attr.Direction = utils.OUT } - if attr.Category != "" && attr.Tennat == "" { - return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "Tenant") - } - if attr.Tennat != "" && attr.Direction == "" { - return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "Direction") + if (attr.Subject != "" && utils.IsSliceMember([]string{attr.Direction, attr.Tenant, attr.Category}, "")) || + (attr.Category != "" && utils.IsSliceMember([]string{attr.Direction, attr.Tenant}, "")) || + attr.Tenant != "" && attr.Direction == "" { + return utils.ErrMandatoryIeMissing } _, err := engine.Guardian.Guard(func() (interface{}, error) { err := self.RatingDb.RemoveRatingProfile(attr.GetId()) diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 484151090..f3475060f 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -355,18 +355,18 @@ CREATE INDEX tpusers_idx ON tp_users (tpid,tenant,user_name); DROP TABLE IF EXISTS tp_aliases; CREATE TABLE tp_aliases ( - `id` SERIAL PRIMARY KEY, - `tpid` VARCHAR(64) NOT NULL, - `direction` VARCHAR(8) NOT NULL, - `tenant` VARCHAR(64) NOT NULL, - `category` VARCHAR(32) NOT NULL, - `account` VARCHAR(64) NOT NULL, - `subject` VARCHAR(64) NOT NULL, - `group` VARCHAR(64) NOT NULL, - `destionation_id` VARCHAR(64) NOT NULL, - `alias` VARCHAR(64) NOT NULL, - `weight` NUMERIC(8,2) NOT NULL, - `created_at` TIMESTAMP + "id" SERIAL PRIMARY KEY, + "tpid" VARCHAR(64) NOT NULL, + "direction" VARCHAR(8) NOT NULL, + "tenant" VARCHAR(64) NOT NULL, + "category" VARCHAR(32) NOT NULL, + "account" VARCHAR(64) NOT NULL, + "subject" VARCHAR(64) NOT NULL, + "group" VARCHAR(64) NOT NULL, + "destionation_id" VARCHAR(64) NOT NULL, + "alias" VARCHAR(64) NOT NULL, + "weight" NUMERIC(8,2) NOT NULL, + "created_at" TIMESTAMP ); CREATE INDEX tpaliases_tpid_idx ON tp_aliases (tpid); -CREATE INDEX tpaliases_idx ON tp_aliases (`tpid`,`direction`,`tenant,category`,`account`,`subject`,`group`); +CREATE INDEX tpaliases_idx ON tp_aliases ("tpid","direction","tenant","category","account","subject","group");