Skip to content

Commit

Permalink
correction in users admin dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecuer committed May 7, 2019
1 parent 7f22753 commit 17e9c90
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
26 changes: 16 additions & 10 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,32 +88,38 @@ 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
from users
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
from users
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
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Address collecting information related to users activity (shared folders & unreg
<tr>
<th><%= sortable "id" %></th>
<th><%= sortable "email", MAIN["mail"] %></th>
<th><%= MAIN["has_shared_folders_from_others?"] %></th>
<th><%= MAIN["shared_folders?"] %></th>
<th><%= sortable "statut", MAIN["status"] %></th>
<th></th>
<th></th>
Expand All @@ -24,7 +24,7 @@ Address collecting information related to users activity (shared folders & unreg
<tr>
<td><%= u.id %></td>
<td><%= link_to u.email, become_path(u.id) %></td>
<td><%= u.has_shares %></td>
<td><%= u.has_shares %>&nbsp;<%= u.is_sharing %></td>
<td>
<%= form_tag(user_path(u), method: "patch") do %>
<%= select_tag :statut, options_for_select(["public", "private", "admin" ], { selected: u.statut })%>
Expand Down
2 changes: 1 addition & 1 deletion config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17e9c90

Please sign in to comment.