debian-mirror-gitlab/app/finders/personal_access_tokens_finder.rb

51 lines
934 B
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class PersonalAccessTokensFinder
attr_accessor :params
2018-12-13 13:39:08 +05:30
delegate :build, :find, :find_by_id, :find_by_token, to: :execute
2017-08-17 22:00:37 +05:30
def initialize(params = {})
@params = params
end
def execute
tokens = PersonalAccessToken.all
tokens = by_user(tokens)
tokens = by_impersonation(tokens)
by_state(tokens)
end
private
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
def by_user(tokens)
return tokens unless @params[:user]
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
tokens.where(user: @params[:user])
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
def by_impersonation(tokens)
case @params[:impersonation]
when true
tokens.with_impersonation
when false
tokens.without_impersonation
else
tokens
end
end
def by_state(tokens)
case @params[:state]
when 'active'
tokens.active
when 'inactive'
tokens.inactive
else
tokens
end
end
end