diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2017-06-26 07:14:10 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-06-28 10:17:13 +0300 |
commit | c1fcd730cc9dbee5b41ce2a6a12f8d84416b1a4a (patch) | |
tree | b3ae8410df1ef28e724ae04a3bb9445f3720f44c /app/services/access_token_validation_service.rb | |
parent | 4dbfa14e160e0d9bca11941adcf04b3d272aa1a2 (diff) |
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/services/access_token_validation_service.rb')
-rw-r--r-- | app/services/access_token_validation_service.rb | 4 |
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 |