2017-02-23 12:47:06 -05:00
|
|
|
class PersonalAccessTokensFinder
|
2017-02-27 13:56:54 -05:00
|
|
|
attr_accessor :params
|
|
|
|
|
2017-03-01 11:59:03 -05:00
|
|
|
delegate :build, :find, :find_by, to: :execute
|
|
|
|
|
2017-02-27 13:56:54 -05:00
|
|
|
def initialize(params = {})
|
2017-02-23 12:47:06 -05:00
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
2017-03-01 11:59:03 -05:00
|
|
|
def execute
|
|
|
|
tokens = PersonalAccessToken.all
|
|
|
|
tokens = by_user(tokens)
|
|
|
|
tokens = by_impersonation(tokens)
|
|
|
|
by_state(tokens)
|
2017-02-23 12:47:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-03-01 11:59:03 -05:00
|
|
|
def by_user(tokens)
|
|
|
|
return tokens unless @params[:user]
|
|
|
|
tokens.where(user: @params[:user])
|
2017-02-23 12:47:06 -05:00
|
|
|
end
|
|
|
|
|
2017-03-01 11:59:03 -05:00
|
|
|
def by_impersonation(tokens)
|
2017-02-27 13:56:54 -05:00
|
|
|
case @params[:impersonation]
|
|
|
|
when true
|
2017-03-01 11:59:03 -05:00
|
|
|
tokens.with_impersonation
|
2017-02-27 13:56:54 -05:00
|
|
|
when false
|
2017-03-01 11:59:03 -05:00
|
|
|
tokens.without_impersonation
|
2017-02-27 13:56:54 -05:00
|
|
|
else
|
2017-03-01 11:59:03 -05:00
|
|
|
tokens
|
2017-02-27 13:56:54 -05:00
|
|
|
end
|
2017-02-23 12:47:06 -05:00
|
|
|
end
|
|
|
|
|
2017-02-27 13:56:54 -05:00
|
|
|
def by_state(tokens)
|
|
|
|
case @params[:state]
|
|
|
|
when 'active'
|
|
|
|
tokens.active
|
|
|
|
when 'inactive'
|
|
|
|
tokens.inactive
|
|
|
|
else
|
|
|
|
tokens
|
|
|
|
end
|
2017-02-23 12:47:06 -05:00
|
|
|
end
|
|
|
|
end
|