From 9e728c691ff408c39f72b2c124ded6cafab56bfc Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 23 Jun 2016 11:42:10 +0200 Subject: [PATCH 1/4] [feature] prevent unmerged accounts (soo imported) from being displayed in lists/searches --- app/controllers/api/members_controller.rb | 27 ++++++++++++++++++----- app/views/api/members/index.json.jbuilder | 2 +- app/views/api/members/list.json.jbuilder | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/members_controller.rb b/app/controllers/api/members_controller.rb index 4d3c99a6d..c808a256d 100644 --- a/app/controllers/api/members_controller.rb +++ b/app/controllers/api/members_controller.rb @@ -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 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 From 98edd345b1e8caa49d09dc89a61c98afeb1b3fec Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 23 Jun 2016 11:49:48 +0200 Subject: [PATCH 2/4] updated changelog for v2.2.2 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb3933408..4546ebd95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog Fab Manager +## 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" From a12c26e06c8f39e1160a9d29ac740280ebaf3658 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 27 Jun 2016 09:10:33 +0200 Subject: [PATCH 3/4] [bug] Unable to run if postgre unaccent was already active --- db/migrate/20160613093842_create_unaccent_function.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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$ From b08ab236dc9e0cf766026c83edb2994a14f5af0b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 27 Jun 2016 09:10:33 +0200 Subject: [PATCH 4/4] [bug] Unable to run migrations if postgre unaccent was already active --- db/migrate/20160613093842_create_unaccent_function.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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$