From 59530e475827136042fb51ae4de29bca5bd40f95 Mon Sep 17 00:00:00 2001 From: Leonard Gram Date: Thu, 6 Feb 2020 07:49:58 +0100 Subject: [PATCH] Quota: Makes sure we provide the request context to the quota service (#21949) It was missing for ldap_login which means that the first signup failed for users with LDAP+quota enabled. There's also potential cases where we can't provide a request context (background jobs) which is also covered, but needs a refactoring. --- pkg/api/ldap_debug.go | 1 + pkg/login/ldap_login.go | 1 + pkg/services/quota/quota.go | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/api/ldap_debug.go b/pkg/api/ldap_debug.go index 44e194e8d6b..e78bfafd664 100644 --- a/pkg/api/ldap_debug.go +++ b/pkg/api/ldap_debug.go @@ -216,6 +216,7 @@ func (server *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) Response { } upsertCmd := &models.UpsertUserCommand{ + ReqContext: c, ExternalUser: user, SignupAllowed: setting.LDAPAllowSignup, } diff --git a/pkg/login/ldap_login.go b/pkg/login/ldap_login.go index 76bb7be2cbb..3e865b96232 100644 --- a/pkg/login/ldap_login.go +++ b/pkg/login/ldap_login.go @@ -51,6 +51,7 @@ var loginUsingLDAP = func(query *models.LoginUserQuery) (bool, error) { } upsert := &models.UpsertUserCommand{ + ReqContext: query.ReqContext, ExternalUser: externalUser, SignupAllowed: setting.LDAPAllowSignup, } diff --git a/pkg/services/quota/quota.go b/pkg/services/quota/quota.go index 7e1e62fc52a..9d541e3e11e 100644 --- a/pkg/services/quota/quota.go +++ b/pkg/services/quota/quota.go @@ -23,7 +23,12 @@ func (qs *QuotaService) QuotaReached(c *m.ReqContext, target string) (bool, erro if !setting.Quota.Enabled { return false, nil } - + // No request context means this is a background service, like LDAP Background Sync. + // TODO: we should replace the req context with a more limited interface or struct, + // something that we could easily provide from background jobs. + if c == nil { + return false, nil + } // get the list of scopes that this target is valid for. Org, User, Global scopes, err := m.GetQuotaScopes(target) if err != nil {