From 17e9c90d595835ffcb0057a05d90e8ddf2dbde8b Mon Sep 17 00:00:00 2001 From: Alexandre CUER Date: Tue, 7 May 2019 21:58:10 +0200 Subject: [PATCH] correction in users admin dashboard --- app/controllers/users_controller.rb | 26 ++++++++++++++++---------- app/models/user.rb | 4 ++++ app/views/users/index.html.erb | 4 ++-- config/config.yml | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 44a27d9..9faa35a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -32,7 +32,7 @@ def update if change_statut == 1 @user.statut = params[:statut] if @user.save - flash[:notice] = "#{@user.email} (#{@user.id.to_s}) #{USERS_MSG["new_status"]} #{@user.statut}" + flash[:notice] = "#{@user.email} (#{@user.id}) #{USERS_MSG["new_status"]} #{@user.statut}" else flash[:notice] = USERS_MSG["error_changing_status"] end @@ -88,7 +88,7 @@ def index flash[:notice] = USERS_MSG["user_managing_forbidden"] redirect_to root_url else - @users=User.select("users.*, NULL as is_sharing, NULL as has_shares").order(sort_column + " " + sort_direction) + @users=User.order(sort_column + " " + sort_direction) #SHARING USERS sql = <<-SQL SELECT distinct users.id @@ -96,8 +96,11 @@ def index INNER JOIN shared_folders on users.id = shared_folders.user_id; SQL - sharing_users=User.find_by_sql(sql) - sharing_users_ids = "#{sharing_users.as_json}" + sharing_users=[] + User.find_by_sql(sql).each do |u| + sharing_users.push(u.id) + end + puts("sharing users: #{sharing_users}") #USERS BEING GRANTED SHARES sql = <<-SQL SELECT distinct users.id @@ -105,15 +108,18 @@ def index INNER JOIN shared_folders on users.id = shared_folders.share_user_id; SQL - users_with_shares=User.find_by_sql(sql) - users_with_shares_ids = "#{users_with_shares.as_json}" + users_with_shares=[] + User.find_by_sql(sql).each do |u| + users_with_shares.push(u.id) + end + puts("users being granted shares: #{users_with_shares}") #LOOP on USERS ACTIVE RECORDS @users.each do |u| - if /#{u.id}/.match(sharing_users_ids) - u.is_sharing='true' + if sharing_users.include?(u.id) + u.is_sharing='offre' end - if /#{u.id}/.match(users_with_shares_ids) - u.has_shares='true' + if users_with_shares.include?(u.id) + u.has_shares='reçoit' end end end diff --git a/app/models/user.rb b/app/models/user.rb index 7e8bc36..2f39a77 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,6 +23,10 @@ class User < ApplicationRecord has_many :surveys + attr_accessor :is_sharing + + attr_accessor :has_shares + # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 7d6d1fa..76acf4a 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -15,7 +15,7 @@ Address collecting information related to users activity (shared folders & unreg <%= sortable "id" %> <%= sortable "email", MAIN["mail"] %> - <%= MAIN["has_shared_folders_from_others?"] %> + <%= MAIN["shared_folders?"] %> <%= sortable "statut", MAIN["status"] %> @@ -24,7 +24,7 @@ Address collecting information related to users activity (shared folders & unreg <%= u.id %> <%= link_to u.email, become_path(u.id) %> - <%= u.has_shares %> + <%= u.has_shares %> <%= u.is_sharing %> <%= form_tag(user_path(u), method: "patch") do %> <%= select_tag :statut, options_for_select(["public", "private", "admin" ], { selected: u.statut })%> diff --git a/config/config.yml b/config/config.yml index c13b245..af2f4e5 100644 --- a/config/config.yml +++ b/config/config.yml @@ -24,7 +24,7 @@ main: # for views\home\list.html.erb users_list: "Liste des utilisateurs" - has_shared_folders_from_others?: "bénéficie de dossiers partagés?" + shared_folders?: "dossiers partagés?" process_to_status_mod: "Modifier le status" # for views\polls\_form.html.erb