diff --git a/app/controllers/moderation/users_controller.rb b/app/controllers/moderation/users_controller.rb index 5dc2178a6..9e38a79bf 100644 --- a/app/controllers/moderation/users_controller.rb +++ b/app/controllers/moderation/users_controller.rb @@ -1,15 +1,28 @@ class Moderation::UsersController < Moderation::BaseController + def index + @users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render + end + + def hide_in_moderation_screen + hide_user + redirect_to request.query_parameters.merge(action: :index), notice: I18n.t('moderation.users.notice_hide') + end + def hide - user = User.find(params[:id]) - debates_ids = Debate.where(author_id: user.id).pluck(:id) - comments_ids = Comment.where(user_id: user.id).pluck(:id) - - user.hide - Debate.hide_all debates_ids - Comment.hide_all comments_ids - + hide_user redirect_to debates_path end + private + def hide_user + user = User.find(params[:id]) + debates_ids = Debate.where(author_id: user.id).pluck(:id) + comments_ids = Comment.where(user_id: user.id).pluck(:id) + + user.hide + Debate.hide_all debates_ids + Comment.hide_all comments_ids + end + end \ No newline at end of file diff --git a/app/views/moderation/_menu.html.erb b/app/views/moderation/_menu.html.erb index ab2674ebb..2b5f938bd 100644 --- a/app/views/moderation/_menu.html.erb +++ b/app/views/moderation/_menu.html.erb @@ -17,5 +17,12 @@ <%= t("moderation.menu.flagged_comments") %> <% end %> + +
  • > + <%= link_to moderation_users_path do %> + + <%= t("moderation.menu.users") %> + <% end %> +
  • diff --git a/app/views/moderation/users/index.html.erb b/app/views/moderation/users/index.html.erb new file mode 100644 index 000000000..5a49c16d1 --- /dev/null +++ b/app/views/moderation/users/index.html.erb @@ -0,0 +1,32 @@ +

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

    + +<%= form_for(User.new, url: moderation_users_path, as: :user, method: :get) do |f| %> +
    +
    + <%= text_field_tag :name_or_email, "", placeholder: t("moderation.users.index.search_placeholder") %> +
    +
    + <%= f.submit t("moderation.users.index.search"), class: "button radius success" %> +
    +
    +<% end %> + +<% if @users.present? %> +

    <%= page_entries_info @users %>

    +<% end %> + + + +<%= paginate @users %> diff --git a/config/locales/moderation.en.yml b/config/locales/moderation.en.yml index 6e04e8765..21db348a7 100644 --- a/config/locales/moderation.en.yml +++ b/config/locales/moderation.en.yml @@ -3,6 +3,7 @@ en: menu: flagged_debates: Debates flagged_comments: Comments + users: Ban users dashboard: index: title: Moderation @@ -40,3 +41,11 @@ en: all: All pending_flag_review: Pending with_ignored_flag: Ignored + users: + notice_hide: User banned. + index: + title: User search and banning + search_placeholder: email or username + search: Search + hide: Ban + hidden: Banned diff --git a/config/locales/moderation.es.yml b/config/locales/moderation.es.yml index 04889d214..2c397c4de 100644 --- a/config/locales/moderation.es.yml +++ b/config/locales/moderation.es.yml @@ -3,6 +3,7 @@ es: menu: flagged_debates: Debates flagged_comments: Comentarios + users: Bloquear usuarios dashboard: index: title: Moderación @@ -40,3 +41,11 @@ es: all: Todos pending_flag_review: Pendientes with_ignored_flag: Ignorados + users: + notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios. + index: + title: Bloquear usuarios + search_placeholder: email o nombre de usuario + search: Buscar + hide: Bloquear + hidden: Bloqueado diff --git a/config/routes.rb b/config/routes.rb index d363b62b4..f7748fad4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -97,8 +97,11 @@ Rails.application.routes.draw do namespace :moderation do root to: "dashboard#index" - resources :users, only: [] do - member { put :hide } + resources :users, only: :index do + member do + put :hide + put :hide_in_moderation_screen + end end resources :debates, only: :index do diff --git a/spec/features/moderation/users_spec.rb b/spec/features/moderation/users_spec.rb index aeea5c088..c30623ee5 100644 --- a/spec/features/moderation/users_spec.rb +++ b/spec/features/moderation/users_spec.rb @@ -48,4 +48,28 @@ feature 'Moderate users' do expect(current_path).to eq(new_user_session_path) end + scenario 'Search and ban users' do + citizen = create(:user, username: 'Wanda Maximoff') + moderator = create(:moderator) + + login_as(moderator.user) + + visit moderation_users_path + + expect(page).not_to have_content citizen.name + fill_in 'name_or_email', with: 'Wanda' + click_button 'Search' + + within(".admin-list") do + expect(page).to have_content citizen.name + expect(page).not_to have_content "Banned" + click_link 'Ban' + end + + within(".admin-list") do + expect(page).to have_content citizen.name + expect(page).to have_content "Banned" + end + end + end \ No newline at end of file