From a5fad89574bd124f64ea0a809cc90be900133d97 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 28 Jan 2014 12:22:50 +0200 Subject: [PATCH] added disabling facility for user accounts --- engine/action_timing.go | 9 +++++++-- engine/action_trigger.go | 3 +++ engine/calldesc.go | 3 +++ engine/userbalance.go | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/engine/action_timing.go b/engine/action_timing.go index b5d362ea1..63aacc5a3 100644 --- a/engine/action_timing.go +++ b/engine/action_timing.go @@ -20,11 +20,12 @@ package engine import ( "fmt" - "github.com/cgrates/cgrates/utils" "sort" "strconv" "strings" "time" + + "github.com/cgrates/cgrates/utils" ) const ( @@ -231,8 +232,11 @@ func (at *ActionTiming) Execute() (err error) { return } for _, ubId := range at.UserBalanceIds { - AccLock.Guard(ubId, func() (float64, error) { + _, err := AccLock.Guard(ubId, func() (float64, error) { ub, err := accountingStorage.GetUserBalance(ubId) + if ub.Disabled { + return 0, fmt.Errorf("User %s is disabled", ubId) + } if err != nil { Logger.Warning(fmt.Sprintf("Could not get user balances for this id: %s. Skipping!", ubId)) return 0, err @@ -243,6 +247,7 @@ func (at *ActionTiming) Execute() (err error) { accountingStorage.SetUserBalance(ub) return 0, nil }) + Logger.Warning(fmt.Sprintf("Error executing action timing: %s", err)) } } storageLogger.LogActionTiming(SCHED_SOURCE, at, aac) diff --git a/engine/action_trigger.go b/engine/action_trigger.go index 5ae816ff8..3187fc5f1 100644 --- a/engine/action_trigger.go +++ b/engine/action_trigger.go @@ -39,6 +39,9 @@ type ActionTrigger struct { } func (at *ActionTrigger) Execute(ub *UserBalance) (err error) { + if ub.Disabled { + return fmt.Errorf("User %s is disabled", ub.Id) + } // does NOT need to Lock() because it is triggered from a method that took the Lock var aac Actions aac, err = accountingStorage.GetActions(at.ActionsId, false) diff --git a/engine/calldesc.go b/engine/calldesc.go index 817b3ce86..bc98fd80c 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -145,6 +145,9 @@ func (cd *CallDescriptor) getUserBalance() (ub *UserBalance, err error) { if cd.userBalance == nil { cd.userBalance, err = accountingStorage.GetUserBalance(cd.GetUserBalanceKey()) } + if cd.userBalance != nil && cd.userBalance.Disabled { + return nil, fmt.Errorf("User %s is disabled", ub.Id) + } return cd.userBalance, err } diff --git a/engine/userbalance.go b/engine/userbalance.go index 04e15d730..a135f5b27 100644 --- a/engine/userbalance.go +++ b/engine/userbalance.go @@ -69,7 +69,8 @@ type UserBalance struct { ActionTriggers ActionTriggerPriotityList Groups GroupLinks // user info about groups // group information - UserIds []string // group info about users + UserIds []string // group info about users + Disabled bool } // Returns user's available minutes for the specified destination