diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/finders/personal_access_tokens_finder.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/finders/personal_access_tokens_finder.rb')
-rw-r--r-- | app/finders/personal_access_tokens_finder.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/app/finders/personal_access_tokens_finder.rb b/app/finders/personal_access_tokens_finder.rb index e3d5f2ae8de..93f8c520b63 100644 --- a/app/finders/personal_access_tokens_finder.rb +++ b/app/finders/personal_access_tokens_finder.rb @@ -5,12 +5,14 @@ class PersonalAccessTokensFinder delegate :build, :find, :find_by_id, :find_by_token, to: :execute - def initialize(params = {}) + def initialize(params = {}, current_user = nil) @params = params + @current_user = current_user end def execute tokens = PersonalAccessToken.all + tokens = by_current_user(tokens) tokens = by_user(tokens) tokens = by_impersonation(tokens) tokens = by_state(tokens) @@ -20,6 +22,15 @@ class PersonalAccessTokensFinder private + attr_reader :current_user + + def by_current_user(tokens) + return tokens if current_user.nil? || current_user.admin? + return PersonalAccessToken.none unless Ability.allowed?(current_user, :read_user_personal_access_tokens, params[:user]) + + tokens + end + def by_user(tokens) return tokens unless @params[:user] |