BigW Consortium Gitlab

Commit 1a7d2aba by James Lopez

add created at filter logic to users finder and API

parent b08df253
......@@ -29,6 +29,7 @@ class UsersFinder
users = by_active(users)
users = by_external_identity(users)
users = by_external(users)
users = by_created_at(users)
users
end
......@@ -71,4 +72,16 @@ class UsersFinder
users.external
end
def by_created_at(users)
if params[:created_after].present?
users = users.where(users.klass.arel_table[:created_at].gteq(params[:created_after]))
end
if params[:created_before].present?
users = users.where(users.klass.arel_table[:created_at].lteq(params[:created_before]))
end
users
end
end
......@@ -48,6 +48,8 @@ module API
optional :active, type: Boolean, default: false, desc: 'Filters only active users'
optional :external, type: Boolean, default: false, desc: 'Filters only external users'
optional :blocked, type: Boolean, default: false, desc: 'Filters only blocked users'
optional :created_after, type: DateTime, desc: 'Return users created after the specified time'
optional :created_before, type: DateTime, desc: 'Return users created before the specified time'
all_or_none_of :extern_uid, :provider
use :pagination
......@@ -55,6 +57,10 @@ module API
get do
authenticated_as_admin! if params[:external].present? || (params[:extern_uid].present? && params[:provider].present?)
unless current_user.admin?
params.except!(:created_after, :created_before)
end
users = UsersFinder.new(current_user, params).execute
authorized = can?(current_user, :read_users_list)
......
......@@ -47,7 +47,9 @@ describe UsersFinder do
end
it 'filters by created_at' do
users = described_class.new(user, created_after: 2.days.ago, created_before: Time.now + 2.days).execute
users = described_class.new(user,
created_after: 2.days.ago,
created_before: Time.now + 2.days).execute
expect(users.count).to eq(4)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment