Add soft block button in moderation user view
This commit is contained in:
committed by
Javi Martín
parent
4c8dfb6695
commit
49edd6a9b1
@@ -7,4 +7,12 @@
|
||||
.table-actions {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.soft-block-link {
|
||||
@include hollow-button($color-warning);
|
||||
}
|
||||
|
||||
.hide-link {
|
||||
@include hollow-button($alert-color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@ class Moderation::UsersController < Moderation::BaseController
|
||||
def index
|
||||
end
|
||||
|
||||
def soft_block
|
||||
soft_block_user
|
||||
|
||||
redirect_with_query_params_to({ action: :index }, { notice: I18n.t("moderation.users.notice_soft_hide") })
|
||||
end
|
||||
|
||||
def hide
|
||||
block_user
|
||||
|
||||
@@ -18,6 +24,11 @@ class Moderation::UsersController < Moderation::BaseController
|
||||
@users = User.with_hidden.search(params[:search]).page(params[:page]).for_render
|
||||
end
|
||||
|
||||
def soft_block_user
|
||||
@user.hide
|
||||
Activity.log(current_user, :soft_block, @user)
|
||||
end
|
||||
|
||||
def block_user
|
||||
@user.block
|
||||
Activity.log(current_user, :block, @user)
|
||||
|
||||
@@ -47,6 +47,9 @@ module Abilities
|
||||
can :hide, User
|
||||
cannot :hide, User, id: user.id
|
||||
|
||||
can :soft_block, User
|
||||
cannot :soft_block, User, id: user.id
|
||||
|
||||
can :block, User
|
||||
cannot :block, User, id: user.id
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ class Activity < ApplicationRecord
|
||||
belongs_to :actionable, -> { with_hidden }, polymorphic: true
|
||||
belongs_to :user, -> { with_hidden }, inverse_of: :activities
|
||||
|
||||
VALID_ACTIONS = %w[hide block restore valuate email].freeze
|
||||
VALID_ACTIONS = %w[hide soft_block block restore valuate email].freeze
|
||||
|
||||
validates :action, inclusion: { in: VALID_ACTIONS }
|
||||
|
||||
|
||||
@@ -22,12 +22,8 @@
|
||||
<%= t("moderation.users.index.hidden") %>
|
||||
<% else %>
|
||||
<%= render Admin::TableActionsComponent.new(user, actions: []) do |actions| %>
|
||||
<%= actions.action(
|
||||
:hide,
|
||||
text: t("moderation.users.index.hide"),
|
||||
method: :put,
|
||||
class: "button hollow alert"
|
||||
) %>
|
||||
<%= actions.action(:soft_block, text: t("moderation.users.index.soft_hide"), method: :put) %>
|
||||
<%= actions.action(:hide, text: t("moderation.users.index.hide"), method: :put) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
@@ -104,5 +104,7 @@ en:
|
||||
hidden: Blocked
|
||||
hide: Block
|
||||
search_placeholder: email or name of user
|
||||
soft_hide: Soft Block
|
||||
title: Block users
|
||||
notice_hide: User blocked. All of this user's debates and comments have been hidden.
|
||||
notice_soft_hide: User blocked. All ot this user's debates and comments are still available.
|
||||
|
||||
@@ -104,5 +104,7 @@ es:
|
||||
hidden: Bloqueado
|
||||
hide: Bloquear
|
||||
search_placeholder: email o nombre de usuario
|
||||
soft_hide: Ocultar
|
||||
title: Bloquear usuarios
|
||||
notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
||||
notice_soft_hide: Usuario bloqueado. Todos sus debates y comentarios siguen disponibles.
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace :moderation do
|
||||
resources :users, only: :index do
|
||||
member do
|
||||
put :hide
|
||||
put :soft_block
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -30,4 +30,14 @@ describe Moderation::UsersController do
|
||||
expect(response).to redirect_to budget_investments_path(investment.budget)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT soft_block" do
|
||||
it "keeps query parameters while using protected redirects" do
|
||||
user = create(:user, email: "user@consul.dev")
|
||||
|
||||
get :soft_block, params: { id: user, name_or_email: "user@consul.dev", host: "evil.dev" }
|
||||
|
||||
expect(response).to redirect_to "/moderation/users?name_or_email=user%40consul.dev"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,6 +90,9 @@ describe Abilities::Moderator do
|
||||
it { should_not be_able_to(:hide, user) }
|
||||
it { should be_able_to(:hide, other_user) }
|
||||
|
||||
it { should_not be_able_to(:soft_block, user) }
|
||||
it { should be_able_to(:soft_block, other_user) }
|
||||
|
||||
it { should_not be_able_to(:block, user) }
|
||||
it { should be_able_to(:block, other_user) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user