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 {
|
.table-actions {
|
||||||
justify-content: flex-end;
|
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
|
def index
|
||||||
end
|
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
|
def hide
|
||||||
block_user
|
block_user
|
||||||
|
|
||||||
@@ -18,6 +24,11 @@ class Moderation::UsersController < Moderation::BaseController
|
|||||||
@users = User.with_hidden.search(params[:search]).page(params[:page]).for_render
|
@users = User.with_hidden.search(params[:search]).page(params[:page]).for_render
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def soft_block_user
|
||||||
|
@user.hide
|
||||||
|
Activity.log(current_user, :soft_block, @user)
|
||||||
|
end
|
||||||
|
|
||||||
def block_user
|
def block_user
|
||||||
@user.block
|
@user.block
|
||||||
Activity.log(current_user, :block, @user)
|
Activity.log(current_user, :block, @user)
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ module Abilities
|
|||||||
can :hide, User
|
can :hide, User
|
||||||
cannot :hide, User, id: user.id
|
cannot :hide, User, id: user.id
|
||||||
|
|
||||||
|
can :soft_block, User
|
||||||
|
cannot :soft_block, User, id: user.id
|
||||||
|
|
||||||
can :block, User
|
can :block, User
|
||||||
cannot :block, User, id: user.id
|
cannot :block, User, id: user.id
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class Activity < ApplicationRecord
|
|||||||
belongs_to :actionable, -> { with_hidden }, polymorphic: true
|
belongs_to :actionable, -> { with_hidden }, polymorphic: true
|
||||||
belongs_to :user, -> { with_hidden }, inverse_of: :activities
|
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 }
|
validates :action, inclusion: { in: VALID_ACTIONS }
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,8 @@
|
|||||||
<%= t("moderation.users.index.hidden") %>
|
<%= t("moderation.users.index.hidden") %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render Admin::TableActionsComponent.new(user, actions: []) do |actions| %>
|
<%= render Admin::TableActionsComponent.new(user, actions: []) do |actions| %>
|
||||||
<%= actions.action(
|
<%= actions.action(:soft_block, text: t("moderation.users.index.soft_hide"), method: :put) %>
|
||||||
:hide,
|
<%= actions.action(:hide, text: t("moderation.users.index.hide"), method: :put) %>
|
||||||
text: t("moderation.users.index.hide"),
|
|
||||||
method: :put,
|
|
||||||
class: "button hollow alert"
|
|
||||||
) %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -104,5 +104,7 @@ en:
|
|||||||
hidden: Blocked
|
hidden: Blocked
|
||||||
hide: Block
|
hide: Block
|
||||||
search_placeholder: email or name of user
|
search_placeholder: email or name of user
|
||||||
|
soft_hide: Soft Block
|
||||||
title: Block users
|
title: Block users
|
||||||
notice_hide: User blocked. All of this user's debates and comments have been hidden.
|
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
|
hidden: Bloqueado
|
||||||
hide: Bloquear
|
hide: Bloquear
|
||||||
search_placeholder: email o nombre de usuario
|
search_placeholder: email o nombre de usuario
|
||||||
|
soft_hide: Ocultar
|
||||||
title: Bloquear usuarios
|
title: Bloquear usuarios
|
||||||
notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
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
|
resources :users, only: :index do
|
||||||
member do
|
member do
|
||||||
put :hide
|
put :hide
|
||||||
|
put :soft_block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -30,4 +30,14 @@ describe Moderation::UsersController do
|
|||||||
expect(response).to redirect_to budget_investments_path(investment.budget)
|
expect(response).to redirect_to budget_investments_path(investment.budget)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ describe Abilities::Moderator do
|
|||||||
it { should_not be_able_to(:hide, user) }
|
it { should_not be_able_to(:hide, user) }
|
||||||
it { should be_able_to(:hide, other_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_not be_able_to(:block, user) }
|
||||||
it { should be_able_to(:block, other_user) }
|
it { should be_able_to(:block, other_user) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user