summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2017-02-23 17:47:06 +0000
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-02-28 22:15:40 +0000
commit9f2e4742e354f5548b4956060f1bfa5ee3bd6657 (patch)
tree45067268ebbcfb48d51c627ef13c2820cad2ad1f /app/finders
parentf0ea7130f7bf0e7a3702d863b4d246f524b6c14a (diff)
downloadgitlab-ce-9f2e4742e354f5548b4956060f1bfa5ee3bd6657.tar.gz
applies relevant changes to the code and code structure
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/personal_access_tokens_finder.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/finders/personal_access_tokens_finder.rb b/app/finders/personal_access_tokens_finder.rb
new file mode 100644
index 00000000000..ad3f7f4a437
--- /dev/null
+++ b/app/finders/personal_access_tokens_finder.rb
@@ -0,0 +1,41 @@
+class PersonalAccessTokensFinder
+ def initialize(user, params = {})
+ @user = user
+ @params = params
+ end
+
+ def execute
+ pat_id = token_id?
+ personal_access_tokens = @user.personal_access_tokens
+ personal_access_tokens = personal_access_tokens.impersonation if impersonation?
+
+ return find_token_by_id(personal_access_tokens, pat_id) if pat_id
+
+ case state?
+ when 'active'
+ personal_access_tokens.active
+ when 'inactive'
+ personal_access_tokens.inactive
+ else
+ personal_access_tokens
+ end
+ end
+
+ private
+
+ def state?
+ @params[:state].presence
+ end
+
+ def impersonation?
+ @params[:impersonation].presence
+ end
+
+ def token_id?
+ @params[:personal_access_token_id].presence
+ end
+
+ def find_token_by_id(personal_access_tokens, pat_id)
+ personal_access_tokens.find_by(id: pat_id)
+ end
+end