mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added disabling facility for user accounts
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user