diff --git a/CHANGELOG.md b/CHANGELOG.md index e22b0ba93..74382bd7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ - add json cache for machines, events, trainings - optimise sql query, avoid to N+1 +## v2.2.2 2016 June 23 +- Fix some bugs: users with uncompleted account (sso imported) won't appear in statistics, in listings and in searches. Moreover, they won't block statistics generation +- Fix a bug: unable to display next results in statistics tables +- Admin: Category is mandatory when creating a course/workshop (event) + ## v2.2.1 2016 June 22 - Fix a bug: field User.merged_at should not be allowed to be mapped in SSO - Fix a bug: integration test "user reservation without plan" diff --git a/app/controllers/api/members_controller.rb b/app/controllers/api/members_controller.rb index 197cc1958..5cc24f65b 100644 --- a/app/controllers/api/members_controller.rb +++ b/app/controllers/api/members_controller.rb @@ -5,15 +5,28 @@ 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 +<<<<<<< HEAD @members = User.active.with_role(:member).includes(profile: [:user_avatar]).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? } + +>>>>>>> 9ab28c1df60ab3b3a06b76025dba26d6151aa0ba @requested_attributes = ['profile'] render :index end @@ -169,7 +182,7 @@ class API::MembersController < API::ApiController order_key = 'users.id' end - @members = User.includes(:profile, :group, :subscriptions) + @query = User.includes(:profile, :group, :subscriptions) .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 +190,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 +218,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 diff --git a/app/views/api/members/index.json.jbuilder b/app/views/api/members/index.json.jbuilder index 92eec1788..89167ffe2 100644 --- a/app/views/api/members/index.json.jbuilder +++ b/app/views/api/members/index.json.jbuilder @@ -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 diff --git a/app/views/api/members/list.json.jbuilder b/app/views/api/members/list.json.jbuilder index 4ae467ce6..15ab9a462 100644 --- a/app/views/api/members/list.json.jbuilder +++ b/app/views/api/members/list.json.jbuilder @@ -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 diff --git a/db/migrate/20160613093842_create_unaccent_function.rb b/db/migrate/20160613093842_create_unaccent_function.rb index 2c6ed05dd..750f71734 100644 --- a/db/migrate/20160613093842_create_unaccent_function.rb +++ b/db/migrate/20160613093842_create_unaccent_function.rb @@ -2,8 +2,8 @@ class CreateUnaccentFunction < ActiveRecord::Migration # PostgreSQL only def up - execute 'CREATE EXTENSION unaccent;' - execute 'CREATE EXTENSION pg_trgm;' + execute 'CREATE EXTENSION IF NOT EXISTS unaccent;' + execute 'CREATE EXTENSION IF NOT EXISTS pg_trgm;' execute "CREATE OR REPLACE FUNCTION f_unaccent(text) RETURNS text AS $func$