diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2017-06-26 04:14:10 +0000 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-06-28 07:17:13 +0000 |
commit | c1fcd730cc9dbee5b41ce2a6a12f8d84416b1a4a (patch) | |
tree | b3ae8410df1ef28e724ae04a3bb9445f3720f44c /lib/gitlab/auth.rb | |
parent | 4dbfa14e160e0d9bca11941adcf04b3d272aa1a2 (diff) | |
download | gitlab-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 'lib/gitlab/auth.rb')
-rw-r--r-- | lib/gitlab/auth.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb index 37ac8ecc2f0..ec73255b20a 100644 --- a/lib/gitlab/auth.rb +++ b/lib/gitlab/auth.rb @@ -130,16 +130,17 @@ module Gitlab token = PersonalAccessTokensFinder.new(state: 'active').find_by(token: password) - if token && valid_scoped_token?(token, AVAILABLE_SCOPES.map { |scope| { name: scope.to_s }}) + if token && valid_scoped_token?(token, AVAILABLE_SCOPES) Gitlab::Auth::Result.new(token.user, nil, :personal_token, abilities_for_scope(token.scopes)) end end def valid_oauth_token?(token) - token && token.accessible? && valid_scoped_token?(token, [{ name: "api" }]) + token && token.accessible? && valid_scoped_token?(token, ['api']) end def valid_scoped_token?(token, scopes) + scopes = scopes.map { |scope| OpenStruct.new(name: scope) } AccessTokenValidationService.new(token).include_any_scope?(scopes) end |