diff --git a/app/controllers/admin/hidden_users_controller.rb b/app/controllers/admin/hidden_users_controller.rb new file mode 100644 index 000000000..8237b7fd4 --- /dev/null +++ b/app/controllers/admin/hidden_users_controller.rb @@ -0,0 +1,33 @@ +class Admin::HiddenUsersController < Admin::BaseController + has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index + + before_action :load_user, only: [:confirm_hide, :restore] + + def index + @users = User.only_hidden.send(@current_filter).page(params[:page]) + end + + def show + @user = User.with_hidden.find(params[:id]) + @debates = @user.debates.with_hidden.page(params[:page]) + @comments = @user.comments.with_hidden.page(params[:page]) + end + + def confirm_hide + @user.confirm_hide + redirect_to request.query_parameters.merge(action: :index) + end + + def restore + @user.restore + Activity.log(current_user, :restore, @user) + redirect_to request.query_parameters.merge(action: :index) + end + + private + + def load_user + @user = User.with_hidden.find(params[:id]) + end + +end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 1e17e1c2d..d1dd1c79c 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,33 +1,16 @@ class Admin::UsersController < Admin::BaseController - has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index - - before_action :load_user, only: [:confirm_hide, :restore] + load_and_authorize_resource def index - @users = User.only_hidden.send(@current_filter).page(params[:page]) - end - - def show - @user = User.with_hidden.find(params[:id]) - @debates = @user.debates.with_hidden.page(params[:page]) - @comments = @user.comments.with_hidden.page(params[:page]) - end - - def confirm_hide - @user.confirm_hide - redirect_to request.query_parameters.merge(action: :index) - end - - def restore - @user.restore - Activity.log(current_user, :restore, @user) - redirect_to request.query_parameters.merge(action: :index) - end - - private - - def load_user - @user = User.with_hidden.find(params[:id]) + if params[:search] + s = params[:search] + @users = User.where("username ILIKE ? OR email ILIKE ? OR document_number ILIKE ?", "%#{s}%","%#{s}%","%#{s}%").page(params[:page]) + else + @users = @users.page(params[:page]) end - -end \ No newline at end of file + respond_to do |format| + format.html + format.js + end + end +end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 8ca439a1c..9fadfea39 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -17,7 +17,7 @@ module AdminHelper end def menu_moderated_content? - ["proposals", "debates", "comments", "users"].include? controller_name + ["proposals", "debates", "comments", "hidden_users"].include? controller_name end def menu_budget? @@ -29,7 +29,7 @@ module AdminHelper end def menu_profiles? - ["administrators", "organizations", "officials", "moderators", "valuators", "managers"].include? controller_name + ["administrators", "organizations", "officials", "moderators", "valuators", "managers", "users"].include? controller_name end def menu_banners? @@ -52,6 +52,22 @@ module AdminHelper resource.persisted? ? "edit" : "new" end + def user_roles(user) + roles = [] + roles << :admin if user.administrator? + roles << :moderator if user.moderator? + roles << :valuator if user.valuator? + roles << :manager if user.manager? + roles << :poll_officer if user.poll_officer? + roles << :official if user.official? + roles << :organization if user.organization? + roles + end + + def display_user_roles(user) + user_roles(user).join(", ") + end + private def namespace diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index af44066be..1aba9dd7c 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -38,6 +38,7 @@ module Abilities can [:search, :create, :index, :destroy], ::Moderator can [:search, :create, :index, :summary], ::Valuator can [:search, :create, :index, :destroy], ::Manager + can [:search, :index], ::User can :manage, Annotation diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 5d454fcd8..62638f3b7 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -33,8 +33,8 @@ <%= link_to t("admin.menu.hidden_comments"), admin_comments_path %> -
  • > - <%= link_to t("admin.menu.hidden_users"), admin_users_path %> +
  • > + <%= link_to t("admin.menu.hidden_users"), admin_hidden_users_path %>
  • @@ -118,6 +118,10 @@
  • > <%= link_to t('admin.menu.managers'), admin_managers_path %>
  • + +
  • > + <%= link_to t('admin.menu.users'), admin_users_path %> +
  • diff --git a/app/views/admin/budget_investments/_written_by_author.html.erb b/app/views/admin/budget_investments/_written_by_author.html.erb index b2c46c6f5..2ecfa2068 100644 --- a/app/views/admin/budget_investments/_written_by_author.html.erb +++ b/app/views/admin/budget_investments/_written_by_author.html.erb @@ -16,7 +16,7 @@

    <%= t("admin.budget_investments.show.by") %>: - <%= link_to @investment.author.name, admin_user_path(@investment.author) %> + <%= link_to @investment.author.name, admin_hidden_user_path(@investment.author) %>

    diff --git a/app/views/admin/hidden_users/index.html.erb b/app/views/admin/hidden_users/index.html.erb new file mode 100644 index 000000000..21bf016e4 --- /dev/null +++ b/app/views/admin/hidden_users/index.html.erb @@ -0,0 +1,33 @@ +

    <%= t("admin.hidden_users.index.title") %>

    + +<%= render 'shared/filter_subnav', i18n_namespace: "admin.hidden_users.index" %> + +

    <%= page_entries_info @users %>

    + + +<% @users.each do |user| %> + + + + + +<% end %> +
    +

    <%= link_to user.name, admin_hidden_user_path(user) %>

    +
    + <%= link_to t("admin.actions.restore"), + restore_admin_hidden_user_path(user, request.query_parameters), + method: :put, + data: { confirm: t("admin.actions.confirm") }, + class: "button hollow on-hover" %> + <% unless user.confirmed_hide? %> + <%= link_to t("admin.actions.confirm_hide"), + confirm_hide_admin_hidden_user_path(user, request.query_parameters), + method: :put, + class: "button hollow warning on-hover" %> + <% end %> +
    + +<%= paginate @users %> + + diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/hidden_users/show.html.erb similarity index 64% rename from app/views/admin/users/show.html.erb rename to app/views/admin/hidden_users/show.html.erb index 1a6ab9795..9fe69ef44 100644 --- a/app/views/admin/users/show.html.erb +++ b/app/views/admin/hidden_users/show.html.erb @@ -1,11 +1,11 @@ <%= render 'shared/back_link' %> -

    <%= t("admin.users.show.title", user: @user.name) %>

    +

    <%= t("admin.hidden_users.show.title", user: @user.name) %>

    - <%= t("admin.users.show.email") %> <%= @user.email %> | - <%= t("admin.users.show.registered_at") %> <%= @user.confirmed_at %> | - <%= t("admin.users.show.hidden_at") %> <%= @user.hidden_at %> + <%= t("admin.hidden_users.show.email") %> <%= @user.email %> | + <%= t("admin.hidden_users.show.registered_at") %> <%= @user.confirmed_at %> | + <%= t("admin.hidden_users.show.hidden_at") %> <%= @user.hidden_at %>

    <% if @debates.present? %> diff --git a/app/views/admin/spending_proposals/_written_by_author.html.erb b/app/views/admin/spending_proposals/_written_by_author.html.erb index 8440666e5..acb7db69c 100644 --- a/app/views/admin/spending_proposals/_written_by_author.html.erb +++ b/app/views/admin/spending_proposals/_written_by_author.html.erb @@ -16,7 +16,7 @@

    <%= t("admin.spending_proposals.show.by") %>: - <%= link_to @spending_proposal.author.name, admin_user_path(@spending_proposal.author) %> + <%= link_to @spending_proposal.author.name, admin_hidden_user_path(@spending_proposal.author) %>

    diff --git a/app/views/admin/users/_users.html.erb b/app/views/admin/users/_users.html.erb new file mode 100644 index 000000000..f3c6af0fa --- /dev/null +++ b/app/views/admin/users/_users.html.erb @@ -0,0 +1,24 @@ +

    <%= page_entries_info @users %>

    + + + + + + + + + + + + <% @users.each do |user| %> + + + + + + + + <% end %> +
    <%= t('admin.users.columns.name') %><%= t('admin.users.columns.email') %><%= t('admin.users.columns.document_number') %><%= t('admin.users.columns.roles') %><%= t('admin.users.columns.verification_level') %>
    <%= user.name %><%= user.email %><%= user.document_number %><%= display_user_roles(user) %><%= user.user_type %>
    + +<%= paginate @users %> diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 336443055..2713399ed 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -1,33 +1,16 @@

    <%= t("admin.users.index.title") %>

    -<%= render 'shared/filter_subnav', i18n_namespace: "admin.users.index" %> - -

    <%= page_entries_info @users %>

    - - -<% @users.each do |user| %> - - - - - -<% end %> -
    -

    <%= link_to user.name, admin_user_path(user) %>

    -
    - <%= link_to t("admin.actions.restore"), - restore_admin_user_path(user, request.query_parameters), - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow on-hover" %> - <% unless user.confirmed_hide? %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_user_path(user, request.query_parameters), - method: :put, - class: "button hollow warning on-hover" %> - <% end %> -
    - -<%= paginate @users %> - +
    + <%= form_tag admin_users_path, method: :get, remote: true do %> +
    + <%= text_field_tag :search, '', placeholder: t('admin.users.search.placeholder') %> +
    +
    + <%= submit_tag t('admin.users.search.search'), class: 'button' %> +
    + <% end %> +
    +
    + <%= render "users" %> +
    diff --git a/app/views/admin/users/index.js.erb b/app/views/admin/users/index.js.erb new file mode 100644 index 000000000..021407a23 --- /dev/null +++ b/app/views/admin/users/index.js.erb @@ -0,0 +1 @@ +$("#users").html("<%= j render 'users' %>"); diff --git a/app/views/admin/verifications/index.html.erb b/app/views/admin/verifications/index.html.erb index 97cca3a4e..c8b2c6ade 100644 --- a/app/views/admin/verifications/index.html.erb +++ b/app/views/admin/verifications/index.html.erb @@ -8,7 +8,7 @@ <% @users.each do |user| %> - <%= link_to user.name, admin_user_path(user) %> + <%= link_to user.name, admin_hidden_user_path(user) %> <%= render "pending_step", user: user %> @@ -17,4 +17,4 @@ <% end %> -<%= paginate @users %> \ No newline at end of file +<%= paginate @users %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 56cc52a78..7ef52a670 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -126,7 +126,7 @@ ignore_unused: - 'admin.budget_investments.index.filter*' - 'admin.spending_proposals.index.filter*' - 'admin.organizations.index.filter*' - - 'admin.users.index.filter*' + - 'admin.hidden_users.index.filter*' - 'admin.activity.show.filter*' - 'admin.legislation.processes.index.filter*' - 'admin.legislation.processes.*.submit_button' diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 1f7eef0a5..3385d3178 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -181,6 +181,19 @@ en: with_confirmed_hide: Confirmed without_confirmed_hide: Pending title: Hidden debates + hidden_users: + index: + filter: Filter + filters: + all: All + with_confirmed_hide: Confirmed + without_confirmed_hide: Pending + title: Hidden users + show: + email: 'Email:' + hidden_at: 'Hidden at:' + registered_at: 'Registered at:' + title: Activity of user (%{user}) legislation: processes: create: @@ -367,6 +380,7 @@ en: title_banners: Banners title_site_customization: Site customization legislation: Collaborative Legislation + users: Users administrators: index: title: Administrators @@ -804,18 +818,17 @@ en: placeholder: Type the name of the topic update: Update Topic users: + columns: + name: Name + email: Email + document_number: Document number + roles: Roles + verification_level: Verification level index: - filter: Filter - filters: - all: All - with_confirmed_hide: Confirmed - without_confirmed_hide: Pending - title: Hidden users - show: - email: 'Email:' - hidden_at: 'Hidden at:' - registered_at: 'Registered at:' - title: Activity of user (%{user}) + title: User + search: + placeholder: Search user by email, name or document number + search: Search verifications: index: phone_not_given: Phone not given diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index bdcfa2e6e..3aefaa20c 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -181,6 +181,19 @@ es: with_confirmed_hide: Confirmados without_confirmed_hide: Pendientes title: Debates ocultos + hidden_users: + index: + filter: Filtro + filters: + all: Todos + with_confirmed_hide: Confirmados + without_confirmed_hide: Pendientes + title: Usuarios bloqueados + show: + email: 'Email:' + hidden_at: 'Bloqueado:' + registered_at: 'Fecha de alta:' + title: Actividad del usuario (%{user}) legislation: processes: create: @@ -378,6 +391,7 @@ es: title_banners: Banners title_site_customization: Personalizar sitio legislation: Legislación colaborativa + users: Usuarios moderators: index: title: Moderadores @@ -804,18 +818,17 @@ es: placeholder: Escribe el nombre del tema update: Actualizar Tema users: + columns: + name: Nombre + email: Correo electrónico + document_number: DNI/Pasaporte/Tarjeta de residencia + roles: Roles + verification_level: Nivel de verficación index: - filter: Filtro - filters: - all: Todos - with_confirmed_hide: Confirmados - without_confirmed_hide: Pendientes - title: Usuarios bloqueados - show: - email: 'Email:' - hidden_at: 'Bloqueado:' - registered_at: 'Fecha de alta:' - title: Actividad del usuario (%{user}) + title: Usuarios + search: + placeholder: Buscar usuario por email, nombre o DNI + search: Buscar verifications: index: phone_not_given: No ha dado su teléfono diff --git a/config/routes.rb b/config/routes.rb index 355a4da3f..e0cb9c632 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -161,7 +161,7 @@ Rails.application.routes.draw do end end - resources :users, only: [:index, :show] do + resources :hidden_users, only: [:index, :show] do member do put :restore put :confirm_hide @@ -238,6 +238,8 @@ Rails.application.routes.draw do get :search, on: :collection end + resources :users, only: [:index, :show] + scope module: :poll do resources :polls do get :search_questions, on: :member diff --git a/spec/features/admin/activity_spec.rb b/spec/features/admin/activity_spec.rb index 0bc1d7b6b..9a1f8aaf8 100644 --- a/spec/features/admin/activity_spec.rb +++ b/spec/features/admin/activity_spec.rb @@ -314,7 +314,7 @@ feature 'Admin activity' do scenario "Shows admin restores" do user = create(:user, :hidden) - visit admin_users_path + visit admin_hidden_users_path within("#user_#{user.id}") do click_on "Restore" @@ -331,4 +331,4 @@ feature 'Admin activity' do end end -end \ No newline at end of file +end diff --git a/spec/features/admin/hidden_users_spec.rb b/spec/features/admin/hidden_users_spec.rb new file mode 100644 index 000000000..f229bd833 --- /dev/null +++ b/spec/features/admin/hidden_users_spec.rb @@ -0,0 +1,97 @@ +require 'rails_helper' + +feature 'Admin hidden users' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + scenario 'Show user activity' do + user = create(:user, :hidden) + + debate1 = create(:debate, :hidden, author: user) + debate2 = create(:debate, author: user) + comment1 = create(:comment, :hidden, user: user, commentable: debate2, body: "You have the manners of a beggar") + comment2 = create(:comment, user: user, commentable: debate2, body: 'Not Spam') + + visit admin_hidden_user_path(user) + + expect(page).to have_content(debate1.title) + expect(page).to have_content(debate2.title) + expect(page).to have_content(comment1.body) + expect(page).to have_content(comment2.body) + end + + scenario 'Restore' do + user = create(:user, :hidden) + visit admin_hidden_users_path + + click_link 'Restore' + + expect(page).to_not have_content(user.username) + + expect(user.reload).to_not be_hidden + end + + scenario 'Confirm hide' do + user = create(:user, :hidden) + visit admin_hidden_users_path + + click_link 'Confirm' + + expect(page).to_not have_content(user.username) + click_link('Confirmed') + expect(page).to have_content(user.username) + + expect(user.reload).to be_confirmed_hide + end + + scenario "Current filter is properly highlighted" do + visit admin_hidden_users_path + expect(page).to_not have_link('Pending') + expect(page).to have_link('All') + expect(page).to have_link('Confirmed') + + visit admin_hidden_users_path(filter: 'Pending') + expect(page).to_not have_link('Pending') + expect(page).to have_link('All') + expect(page).to have_link('Confirmed') + + visit admin_hidden_users_path(filter: 'all') + expect(page).to have_link('Pending') + expect(page).to_not have_link('All') + expect(page).to have_link('Confirmed') + + visit admin_hidden_users_path(filter: 'with_confirmed_hide') + expect(page).to have_link('All') + expect(page).to have_link('Pending') + expect(page).to_not have_link('Confirmed') + end + + scenario "Filtering users" do + create(:user, :hidden, username: "Unconfirmed") + create(:user, :hidden, :with_confirmed_hide, username: "Confirmed user") + + visit admin_hidden_users_path(filter: 'all') + expect(page).to have_content('Unconfirmed') + expect(page).to have_content('Confirmed user') + + visit admin_hidden_users_path(filter: 'with_confirmed_hide') + expect(page).to_not have_content('Unconfirmed') + expect(page).to have_content('Confirmed user') + end + + scenario "Action links remember the pagination setting and the filter" do + per_page = Kaminari.config.default_per_page + (per_page + 2).times { create(:user, :hidden, :with_confirmed_hide) } + + visit admin_hidden_users_path(filter: 'with_confirmed_hide', page: 2) + + click_on('Restore', match: :first, exact: true) + + expect(current_url).to include('filter=with_confirmed_hide') + expect(current_url).to include('page=2') + end + +end diff --git a/spec/features/admin/users_spec.rb b/spec/features/admin/users_spec.rb index 0bd999ff1..4a62a75d0 100644 --- a/spec/features/admin/users_spec.rb +++ b/spec/features/admin/users_spec.rb @@ -1,97 +1,28 @@ require 'rails_helper' feature 'Admin users' do - background do - admin = create(:administrator) - login_as(admin.user) - end - - scenario 'Show user activity' do - user = create(:user, :hidden) - - debate1 = create(:debate, :hidden, author: user) - debate2 = create(:debate, author: user) - comment1 = create(:comment, :hidden, user: user, commentable: debate2, body: "You have the manners of a beggar") - comment2 = create(:comment, user: user, commentable: debate2, body: 'Not Spam') - - visit admin_user_path(user) - - expect(page).to have_content(debate1.title) - expect(page).to have_content(debate2.title) - expect(page).to have_content(comment1.body) - expect(page).to have_content(comment2.body) - end - - scenario 'Restore' do - user = create(:user, :hidden) + @admin = create(:administrator) + @user = create(:user, username: 'Jose Luis Balbin') + login_as(@admin.user) visit admin_users_path - - click_link 'Restore' - - expect(page).to_not have_content(user.username) - - expect(user.reload).to_not be_hidden end - scenario 'Confirm hide' do - user = create(:user, :hidden) - visit admin_users_path - - click_link 'Confirm' - - expect(page).to_not have_content(user.username) - click_link('Confirmed') - expect(page).to have_content(user.username) - - expect(user.reload).to be_confirmed_hide + scenario 'Index' do + expect(page).to have_content @user.name + expect(page).to have_content @user.email + expect(page).to have_content @admin.name + expect(page).to have_content @admin.email end - scenario "Current filter is properly highlighted" do - visit admin_users_path - expect(page).to_not have_link('Pending') - expect(page).to have_link('All') - expect(page).to have_link('Confirmed') + scenario 'Search' do + fill_in :search, with: "Luis" + click_button 'Search' - visit admin_users_path(filter: 'Pending') - expect(page).to_not have_link('Pending') - expect(page).to have_link('All') - expect(page).to have_link('Confirmed') - - visit admin_users_path(filter: 'all') - expect(page).to have_link('Pending') - expect(page).to_not have_link('All') - expect(page).to have_link('Confirmed') - - visit admin_users_path(filter: 'with_confirmed_hide') - expect(page).to have_link('All') - expect(page).to have_link('Pending') - expect(page).to_not have_link('Confirmed') + expect(page).to have_content @user.name + expect(page).to have_content @user.email + expect(page).to_not have_content @admin.name + expect(page).to_not have_content @admin.email end - - scenario "Filtering users" do - create(:user, :hidden, username: "Unconfirmed") - create(:user, :hidden, :with_confirmed_hide, username: "Confirmed user") - - visit admin_users_path(filter: 'all') - expect(page).to have_content('Unconfirmed') - expect(page).to have_content('Confirmed user') - - visit admin_users_path(filter: 'with_confirmed_hide') - expect(page).to_not have_content('Unconfirmed') - expect(page).to have_content('Confirmed user') - end - - scenario "Action links remember the pagination setting and the filter" do - per_page = Kaminari.config.default_per_page - (per_page + 2).times { create(:user, :hidden, :with_confirmed_hide) } - - visit admin_users_path(filter: 'with_confirmed_hide', page: 2) - - click_on('Restore', match: :first, exact: true) - - expect(current_url).to include('filter=with_confirmed_hide') - expect(current_url).to include('page=2') - end - end +