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