summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2017-06-26 04:14:10 +0000
committerTimothy Andrew <mail@timothyandrew.net>2017-06-28 07:17:13 +0000
commitc1fcd730cc9dbee5b41ce2a6a12f8d84416b1a4a (patch)
treeb3ae8410df1ef28e724ae04a3bb9445f3720f44c /app
parent4dbfa14e160e0d9bca11941adcf04b3d272aa1a2 (diff)
downloadgitlab-ce-c1fcd730cc9dbee5b41ce2a6a12f8d84416b1a4a.tar.gz
Implement review comments from @DouweM for !12300.
- Use a struct for scopes, so we can call `scope.if` instead of `scope[:if]` - Refactor the "remove scopes whose :if condition returns false" logic to use a `select` rather than a `reject`.
Diffstat (limited to 'app')
-rw-r--r--app/services/access_token_validation_service.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/app/services/access_token_validation_service.rb b/app/services/access_token_validation_service.rb
index 450e90d947d..ee2e93a0d63 100644
--- a/app/services/access_token_validation_service.rb
+++ b/app/services/access_token_validation_service.rb
@@ -33,10 +33,10 @@ class AccessTokenValidationService
true
else
# Remove any scopes whose `if` condition does not return `true`
- scopes = scopes.reject { |scope| scope[:if].presence && !scope[:if].call(request) }
+ scopes = scopes.select { |scope| scope.if.nil? || scope.if.call(request) }
# Check whether the token is allowed access to any of the required scopes.
- passed_scope_names = scopes.map { |scope| scope[:name].to_sym }
+ passed_scope_names = scopes.map { |scope| scope.name.to_sym }
token_scope_names = token.scopes.map(&:to_sym)
Set.new(passed_scope_names).intersection(Set.new(token_scope_names)).present?
end