Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-11-24 10:37:22 +0300
committerTimothy Andrew <mail@timothyandrew.net>2016-12-16 13:59:31 +0300
commit4d6da770de94f4bf140507cdf43461b67269ce28 (patch)
treed637ccdf6af0475af83b01e9f8371c5f06f6f880 /lib
parentac9835c602f1c9b5a35ef40df079faf1d4b91f7b (diff)
Implement minor changes from @dbalexandre's review.
- Mainly whitespace changes. - Require the migration adding the `scope` column to the `personal_access_tokens` table to have downtime, since API calls will fail if the new code is in place, but the migration hasn't run. - Minor refactoring - load `@scopes` in a `before_action`, since we're doing it in three different places.
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api_guard.rb26
-rw-r--r--lib/gitlab/auth.rb1
2 files changed, 15 insertions, 12 deletions
diff --git a/lib/api/api_guard.rb b/lib/api/api_guard.rb
index cd266669b1e..563224a580f 100644
--- a/lib/api/api_guard.rb
+++ b/lib/api/api_guard.rb
@@ -44,17 +44,21 @@ module API
# Defaults to empty array.
#
def doorkeeper_guard(scopes: [])
- if access_token = find_access_token
- case AccessTokenValidationService.validate(access_token, scopes: scopes)
- when AccessTokenValidationService::INSUFFICIENT_SCOPE
- raise InsufficientScopeError.new(scopes)
- when AccessTokenValidationService::EXPIRED
- raise ExpiredError
- when AccessTokenValidationService::REVOKED
- raise RevokedError
- when AccessTokenValidationService::VALID
- @current_user = User.find(access_token.resource_owner_id)
- end
+ access_token = find_access_token
+ return nil unless access_token
+
+ case AccessTokenValidationService.validate(access_token, scopes: scopes)
+ when AccessTokenValidationService::INSUFFICIENT_SCOPE
+ raise InsufficientScopeError.new(scopes)
+
+ when AccessTokenValidationService::EXPIRED
+ raise ExpiredError
+
+ when AccessTokenValidationService::REVOKED
+ raise RevokedError
+
+ when AccessTokenValidationService::VALID
+ @current_user = User.find(access_token.resource_owner_id)
end
end
diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb
index c6a23aa2bdf..c425702fd75 100644
--- a/lib/gitlab/auth.rb
+++ b/lib/gitlab/auth.rb
@@ -107,7 +107,6 @@ module Gitlab
if token && token.user == validation && token_has_scope?(token)
Gitlab::Auth::Result.new(validation, nil, :personal_token, full_authentication_abilities)
end
-
end
end