From c7ff4311600ada379b8b3cd58882562778d023bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 7 Sep 2015 17:56:19 +0200 Subject: [PATCH 1/3] configures routes for moderation/users --- config/routes.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 98c88894d..9ee4e4a10 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,8 +96,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 From af6cb16e9b92c9e2fcc696e5fa613c7e8031f8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 7 Sep 2015 17:56:53 +0200 Subject: [PATCH 2/3] adds banned users section to moderation zone --- .../moderation/users_controller.rb | 29 ++++++++++++----- app/views/moderation/users/index.html.erb | 32 +++++++++++++++++++ config/locales/moderation.en.yml | 8 +++++ config/locales/moderation.es.yml | 8 +++++ spec/features/moderation/users_spec.rb | 24 ++++++++++++++ 5 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 app/views/moderation/users/index.html.erb 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/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..4213ffd62 100644 --- a/config/locales/moderation.en.yml +++ b/config/locales/moderation.en.yml @@ -40,3 +40,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..8ee1613ef 100644 --- a/config/locales/moderation.es.yml +++ b/config/locales/moderation.es.yml @@ -40,3 +40,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/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 From f2426e09faaa25512f9f1ce63afea6ef4b565c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 7 Sep 2015 17:57:08 +0200 Subject: [PATCH 3/3] adds users to moderator's menu --- app/views/moderation/_menu.html.erb | 7 +++++++ config/locales/moderation.en.yml | 1 + config/locales/moderation.es.yml | 1 + 3 files changed, 9 insertions(+) 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/config/locales/moderation.en.yml b/config/locales/moderation.en.yml index 4213ffd62..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 diff --git a/config/locales/moderation.es.yml b/config/locales/moderation.es.yml index 8ee1613ef..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