mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
fix #764
This commit is contained in:
parent
b1e5570f85
commit
e1f56aaee3
@ -1169,13 +1169,9 @@ func (vh *VHostInfo) checkThrottle(cooldown time.Duration) (err error) {
|
|||||||
// callback type implementing the actual business logic of vhost operations
|
// callback type implementing the actual business logic of vhost operations
|
||||||
type vhostMunger func(input VHostInfo) (output VHostInfo, err error)
|
type vhostMunger func(input VHostInfo) (output VHostInfo, err error)
|
||||||
|
|
||||||
func (am *AccountManager) VHostSet(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
|
func (am *AccountManager) VHostSet(account string, vhost string) (result VHostInfo, err error) {
|
||||||
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
||||||
output = input
|
output = input
|
||||||
err = output.checkThrottle(cooldown)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
output.Enabled = true
|
output.Enabled = true
|
||||||
output.ApprovedVHost = vhost
|
output.ApprovedVHost = vhost
|
||||||
return
|
return
|
||||||
@ -1205,6 +1201,29 @@ func (am *AccountManager) VHostRequest(account string, vhost string, cooldown ti
|
|||||||
return am.performVHostChange(account, munger)
|
return am.performVHostChange(account, munger)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (am *AccountManager) VHostTake(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
|
||||||
|
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
||||||
|
output = input
|
||||||
|
|
||||||
|
// if you have a request pending, you can cancel it using take;
|
||||||
|
// otherwise, you're subject to the same throttling as if you were making a request
|
||||||
|
if output.RequestedVHost == "" {
|
||||||
|
err = output.checkThrottle(cooldown)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
output.ApprovedVHost = vhost
|
||||||
|
output.RequestedVHost = ""
|
||||||
|
output.RejectedVHost = ""
|
||||||
|
output.RejectionReason = ""
|
||||||
|
output.LastRequestTime = time.Now().UTC()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return am.performVHostChange(account, munger)
|
||||||
|
}
|
||||||
|
|
||||||
func (am *AccountManager) VHostApprove(account string) (result VHostInfo, err error) {
|
func (am *AccountManager) VHostApprove(account string) (result VHostInfo, err error) {
|
||||||
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
||||||
output = input
|
output = input
|
||||||
|
@ -298,7 +298,7 @@ func hsSetHandler(server *Server, client *Client, command string, params []strin
|
|||||||
}
|
}
|
||||||
// else: command == "del", vhost == ""
|
// else: command == "del", vhost == ""
|
||||||
|
|
||||||
_, err := server.accounts.VHostSet(user, vhost, 0)
|
_, err := server.accounts.VHostSet(user, vhost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
hsNotice(rb, client.t("An error occurred"))
|
hsNotice(rb, client.t("An error occurred"))
|
||||||
} else if vhost != "" {
|
} else if vhost != "" {
|
||||||
@ -404,7 +404,7 @@ func hsTakeHandler(server *Server, client *Client, command string, params []stri
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := server.accounts.VHostSet(client.Account(), vhost, config.Accounts.VHosts.UserRequests.Cooldown)
|
_, err := server.accounts.VHostTake(client.Account(), vhost, config.Accounts.VHosts.UserRequests.Cooldown)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if throttled, ok := err.(*vhostThrottleExceeded); ok {
|
if throttled, ok := err.(*vhostThrottleExceeded); ok {
|
||||||
hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))
|
hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))
|
||||||
|
Loading…
Reference in New Issue
Block a user