added disabling facility for user accounts

This commit is contained in:
Radu Ioan Fericean
2014-01-28 12:22:50 +02:00
parent 6a251c2b2c
commit a5fad89574
4 changed files with 15 additions and 3 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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