1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

[feature] prevent unmerged accounts (soo imported) from being displayed in lists/searches

This commit is contained in:
Sylvain 2016-06-23 11:42:10 +02:00
parent c90f4684b9
commit 9e728c691f
3 changed files with 24 additions and 7 deletions

View File

@ -5,15 +5,24 @@ class API::MembersController < API::ApiController
def index
@requested_attributes = params[:requested_attributes]
@members = policy_scope(User)
@query = policy_scope(User)
unless params[:page].nil? and params[:size].nil?
@members = @members.page(params[:page].to_i).per(params[:size].to_i)
@query = @query.page(params[:page].to_i).per(params[:size].to_i)
end
# remove unmerged profiles from list
@members = @query.to_a
@members.delete_if { |u| u.need_completion? }
end
def last_subscribed
@members = User.active.with_role(:member).includes(:profile).where('is_allow_contact = true AND confirmed_at IS NOT NULL').order('created_at desc').limit(params[:last])
@query = User.active.with_role(:member).includes(:profile).where('is_allow_contact = true AND confirmed_at IS NOT NULL').order('created_at desc').limit(params[:last])
# remove unmerged profiles from list
@members = @query.to_a
@members.delete_if { |u| u.need_completion? }
@requested_attributes = ['profile']
render :index
end
@ -169,7 +178,7 @@ class API::MembersController < API::ApiController
order_key = 'users.id'
end
@members = User.includes(:profile, :group)
@query = User.includes(:profile, :group)
.joins(:profile, :group, :roles, 'LEFT JOIN "subscriptions" ON "subscriptions"."user_id" = "users"."id" LEFT JOIN "plans" ON "plans"."id" = "subscriptions"."plan_id"')
.where("users.is_active = 'true' AND roles.name = 'member'")
.order("#{order_key} #{direction}")
@ -177,7 +186,11 @@ class API::MembersController < API::ApiController
.per(p[:size])
# ILIKE => PostgreSQL case-insensitive LIKE
@members = @members.where('profiles.first_name ILIKE :search OR profiles.last_name ILIKE :search OR profiles.phone ILIKE :search OR email ILIKE :search OR groups.name ILIKE :search OR plans.base_name ILIKE :search', search: "%#{p[:search]}%") if p[:search].size > 0
@query = @query.where('profiles.first_name ILIKE :search OR profiles.last_name ILIKE :search OR profiles.phone ILIKE :search OR email ILIKE :search OR groups.name ILIKE :search OR plans.base_name ILIKE :search', search: "%#{p[:search]}%") if p[:search].size > 0
# remove unmerged profiles from list
@members = @query.to_a
@members.delete_if { |u| u.need_completion? }
@members
@ -201,6 +214,10 @@ class API::MembersController < API::ApiController
end
end
# remove unmerged profiles from list
@members = @members.to_a
@members.delete_if { |u| u.need_completion? }
@members
end

View File

@ -1,5 +1,5 @@
user_is_admin = (current_user and current_user.is_admin?)
maxMembers = @members.except(:offset, :limit, :order).count
maxMembers = @query.except(:offset, :limit, :order).count
json.array!(@members) do |member|
json.maxMembers maxMembers

View File

@ -1,4 +1,4 @@
maxMembers = @members.except(:offset, :limit, :order).count
maxMembers = @query.except(:offset, :limit, :order).count
json.array!(@members) do |member|
json.maxMembers maxMembers