mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' into shared_balances
This commit is contained in:
@@ -23,13 +23,14 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"net/http"
|
||||
"net/smtp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -58,6 +59,8 @@ const (
|
||||
DEBIT = "*debit"
|
||||
RESET_COUNTER = "*reset_counter"
|
||||
RESET_COUNTERS = "*reset_counters"
|
||||
ENABLE_USER = "*enable_user"
|
||||
DISABLE_USER = "*disable_user"
|
||||
CALL_URL = "*call_url"
|
||||
CALL_URL_ASYNC = "*call_url_async"
|
||||
MAIL_ASYNC = "*mail_async"
|
||||
@@ -90,6 +93,10 @@ func getActionFunc(typ string) (actionTypeFunc, bool) {
|
||||
return resetCounterAction, true
|
||||
case RESET_COUNTERS:
|
||||
return resetCountersAction, true
|
||||
case ENABLE_USER:
|
||||
return enableUserAction, true
|
||||
case DISABLE_USER:
|
||||
return disableUserAction, true
|
||||
case CALL_URL:
|
||||
return callUrl, true
|
||||
case CALL_URL_ASYNC:
|
||||
@@ -181,6 +188,16 @@ func genericDebit(ub *UserBalance, a *Action) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func enableUserAction(ub *UserBalance, a *Action) (err error) {
|
||||
ub.Disabled = false
|
||||
return
|
||||
}
|
||||
|
||||
func disableUserAction(ub *UserBalance, a *Action) (err error) {
|
||||
ub.Disabled = true
|
||||
return
|
||||
}
|
||||
|
||||
func genericReset(ub *UserBalance) {
|
||||
for k, _ := range ub.BalanceMap {
|
||||
ub.BalanceMap[k] = BalanceChain{&Balance{Value: 0}}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,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