mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
Login: Fix failure to login a new user via an external provider if quota are enabled (#60015)
* Login: Fix failure to login a new user via an external provider if quota are enabled
This commit is contained in:
parent
6280780e0c
commit
341d7b01ee
@ -11,7 +11,9 @@ import (
|
||||
var ErrBadRequest = errutil.NewBase(errutil.StatusBadRequest, "quota.bad-request")
|
||||
var ErrInvalidTargetSrv = errutil.NewBase(errutil.StatusBadRequest, "quota.invalid-target")
|
||||
var ErrInvalidScope = errutil.NewBase(errutil.StatusBadRequest, "quota.invalid-scope")
|
||||
var ErrFailedToGetScope = errutil.NewBase(errutil.StatusInternal, "quota.failed-get-scope")
|
||||
var ErrInvalidTarget = errutil.NewBase(errutil.StatusInternal, "quota.invalid-target-table")
|
||||
var ErrUsageFoundForTarget = errutil.NewBase(errutil.StatusNotFound, "quota.missing-target-usage")
|
||||
var ErrTargetSrvConflict = errutil.NewBase(errutil.StatusBadRequest, "quota.target-srv-conflict")
|
||||
var ErrDisabled = errutil.NewBase(errutil.StatusForbidden, "quota.disabled", errutil.WithPublicMessage("Quotas not enabled"))
|
||||
var ErrInvalidTagFormat = errutil.NewBase(errutil.StatusInternal, "quota.invalid-invalid-tag-format")
|
||||
|
@ -2,7 +2,6 @@ package quotaimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
@ -205,9 +204,24 @@ func (s *service) CheckQuotaReached(ctx context.Context, targetSrv quota.TargetS
|
||||
case limit == 0:
|
||||
return true, nil
|
||||
default:
|
||||
scope, err := t.GetScope()
|
||||
if err != nil {
|
||||
return false, quota.ErrFailedToGetScope.Errorf("failed to get the scope for target: %s", t)
|
||||
}
|
||||
|
||||
// do not check user quota if the user information is not available (eg no user is signed in)
|
||||
if scope == quota.UserScope && (scopeParams == nil || scopeParams.UserID == 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
// do not check user quota if the org information is not available (eg no user is signed in)
|
||||
if scope == quota.OrgScope && (scopeParams == nil || scopeParams.OrgID == 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
u, ok := targetUsage.Get(t)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("no usage for target:%s", t)
|
||||
return false, quota.ErrUsageFoundForTarget.Errorf("no usage for target:%s", t)
|
||||
}
|
||||
if u >= limit {
|
||||
return true, nil
|
||||
|
Loading…
Reference in New Issue
Block a user