Make action names to block and hide more clear
The `hide` action was calling the `block` method while the `soft_block` action was calling the `hide` method. Combined with the fact that we also have a `block` permission which is used in `ModerateActions` the logic was hard to follow.
This commit is contained in:
@@ -8,11 +8,11 @@
|
|||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
.soft-block-link {
|
.hide-link {
|
||||||
@include hollow-button($color-warning);
|
@include hollow-button($color-warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
.hide-link {
|
.block-link {
|
||||||
@include hollow-button($alert-color);
|
@include hollow-button($alert-color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<% if can? :hide, record.author %>
|
<% if can? :hide, record.author %>
|
||||||
<%= raw separator %>
|
<%= raw separator %>
|
||||||
<%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(record.author_id),
|
<%= link_to t("admin.actions.block_author").capitalize, block_moderation_user_path(record.author_id),
|
||||||
method: :put, data: { confirm: confirm_hide_author_text } %>
|
method: :put, data: { confirm: confirm_block_author_text } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ class Shared::ModerationActionsComponent < ApplicationComponent
|
|||||||
t("admin.actions.confirm_action", action: t("admin.actions.hide"), name: record.human_name)
|
t("admin.actions.confirm_action", action: t("admin.actions.hide"), name: record.human_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def confirm_hide_author_text
|
def confirm_block_author_text
|
||||||
t("admin.actions.confirm_action", action: t("admin.actions.hide_author"), name: record.author.name)
|
t("admin.actions.confirm_action", action: t("admin.actions.block_author"), name: record.author.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def separator
|
def separator
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ class Moderation::UsersController < Moderation::BaseController
|
|||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
def soft_block
|
def hide
|
||||||
soft_block_user
|
hide_user
|
||||||
|
|
||||||
redirect_with_query_params_to({ action: :index }, { notice: I18n.t("moderation.users.notice_soft_hide") })
|
redirect_with_query_params_to({ action: :index }, { notice: I18n.t("moderation.users.notice_hide") })
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide
|
def block
|
||||||
block_user
|
block_user
|
||||||
|
|
||||||
redirect_with_query_params_to index_path_options, { notice: I18n.t("moderation.users.notice_hide") }
|
redirect_with_query_params_to index_path_options, { notice: I18n.t("moderation.users.notice_block") }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -24,9 +24,9 @@ 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
|
def hide_user
|
||||||
@user.hide
|
@user.hide
|
||||||
Activity.log(current_user, :soft_block, @user)
|
Activity.log(current_user, :hide, @user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def block_user
|
def block_user
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ 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 soft_block block restore valuate email].freeze
|
VALID_ACTIONS = %w[hide block restore valuate email].freeze
|
||||||
|
|
||||||
validates :action, inclusion: { in: VALID_ACTIONS }
|
validates :action, inclusion: { in: VALID_ACTIONS }
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +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(:soft_block, text: t("moderation.users.index.soft_hide"), method: :put) %>
|
|
||||||
<%= actions.action(:hide, text: t("moderation.users.index.hide"), method: :put) %>
|
<%= actions.action(:hide, text: t("moderation.users.index.hide"), method: :put) %>
|
||||||
|
<%= actions.action(:block, text: t("moderation.users.index.block"), method: :put) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ en:
|
|||||||
title: Administration
|
title: Administration
|
||||||
actions:
|
actions:
|
||||||
actions: Actions
|
actions: Actions
|
||||||
|
block_author: "Block author"
|
||||||
confirm_action: "Are you sure? %{action} \"%{name}\""
|
confirm_action: "Are you sure? %{action} \"%{name}\""
|
||||||
confirm_delete: "Are you sure? This action will delete \"%{name}\" and can't be undone."
|
confirm_delete: "Are you sure? This action will delete \"%{name}\" and can't be undone."
|
||||||
confirm_hide: Confirm moderation
|
confirm_hide: Confirm moderation
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
hide: Hide
|
hide: Hide
|
||||||
hide_author: Hide author
|
|
||||||
label: "%{action} %{name}"
|
label: "%{action} %{name}"
|
||||||
restore: Restore
|
restore: Restore
|
||||||
mark_featured: Featured
|
mark_featured: Featured
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ en:
|
|||||||
title: Proposal notifications
|
title: Proposal notifications
|
||||||
users:
|
users:
|
||||||
index:
|
index:
|
||||||
|
block: Block
|
||||||
hidden: Blocked
|
hidden: Blocked
|
||||||
hide: Block
|
hide: Hide
|
||||||
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_block: 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.
|
notice_hide: User blocked. All ot this user's debates and comments are still available.
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ es:
|
|||||||
title: Administración
|
title: Administración
|
||||||
actions:
|
actions:
|
||||||
actions: Acciones
|
actions: Acciones
|
||||||
|
block_author: "Bloquear al autor"
|
||||||
confirm_action: "¿Estás seguro? %{action} \"%{name}\""
|
confirm_action: "¿Estás seguro? %{action} \"%{name}\""
|
||||||
confirm_delete: "¿Estás seguro? Esta acción borrará \"%{name}\" y no se puede deshacer."
|
confirm_delete: "¿Estás seguro? Esta acción borrará \"%{name}\" y no se puede deshacer."
|
||||||
confirm_hide: Confirmar moderación
|
confirm_hide: Confirmar moderación
|
||||||
delete: Borrar
|
delete: Borrar
|
||||||
hide: Ocultar
|
hide: Ocultar
|
||||||
hide_author: Bloquear al autor
|
|
||||||
label: "%{action} %{name}"
|
label: "%{action} %{name}"
|
||||||
restore: Volver a mostrar
|
restore: Volver a mostrar
|
||||||
mark_featured: Destacar
|
mark_featured: Destacar
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ es:
|
|||||||
title: Notificaciones de propuestas
|
title: Notificaciones de propuestas
|
||||||
users:
|
users:
|
||||||
index:
|
index:
|
||||||
|
block: Bloquear
|
||||||
hidden: Bloqueado
|
hidden: Bloqueado
|
||||||
hide: Bloquear
|
hide: Ocultar
|
||||||
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_block: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
||||||
notice_soft_hide: Usuario bloqueado. Todos sus debates y comentarios siguen disponibles.
|
notice_hide: Usuario bloqueado. Todos sus debates y comentarios siguen disponibles.
|
||||||
|
|||||||
@@ -4,7 +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
|
put :block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,19 @@ describe Moderation::UsersController do
|
|||||||
|
|
||||||
describe "PUT hide" do
|
describe "PUT hide" do
|
||||||
it "keeps query parameters while using protected redirects" do
|
it "keeps query parameters while using protected redirects" do
|
||||||
get :hide, params: { id: user, search: "user@consul.dev", host: "evil.dev" }
|
user = create(:user, email: "user@consul.dev")
|
||||||
|
|
||||||
|
get :hide, 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
|
||||||
|
|
||||||
|
describe "PUT block" do
|
||||||
|
it "keeps query parameters while using protected redirects" do
|
||||||
|
user = create(:user, email: "user@consul.dev")
|
||||||
|
|
||||||
|
get :block, params: { id: user, search: "user@consul.dev", host: "evil.dev" }
|
||||||
|
|
||||||
expect(response).to redirect_to "/moderation/users?search=user%40consul.dev"
|
expect(response).to redirect_to "/moderation/users?search=user%40consul.dev"
|
||||||
end
|
end
|
||||||
@@ -15,7 +27,7 @@ describe Moderation::UsersController do
|
|||||||
proposal = create(:proposal, author: user)
|
proposal = create(:proposal, author: user)
|
||||||
request.env["HTTP_REFERER"] = proposal_path(proposal)
|
request.env["HTTP_REFERER"] = proposal_path(proposal)
|
||||||
|
|
||||||
put :hide, params: { id: user }
|
put :block, params: { id: user }
|
||||||
|
|
||||||
expect(response).to redirect_to proposals_path
|
expect(response).to redirect_to proposals_path
|
||||||
expect(flash[:notice]).to eq "User blocked. All of this user's debates and comments have been hidden."
|
expect(flash[:notice]).to eq "User blocked. All of this user's debates and comments have been hidden."
|
||||||
@@ -25,19 +37,9 @@ describe Moderation::UsersController do
|
|||||||
investment = create(:budget_investment, author: user)
|
investment = create(:budget_investment, author: user)
|
||||||
request.env["HTTP_REFERER"] = budget_investment_path(investment.budget, investment)
|
request.env["HTTP_REFERER"] = budget_investment_path(investment.budget, investment)
|
||||||
|
|
||||||
put :hide, params: { id: user }
|
put :block, params: { id: user }
|
||||||
|
|
||||||
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,9 +90,6 @@ 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) }
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ describe "Admin activity" do
|
|||||||
visit proposal_path(proposal)
|
visit proposal_path(proposal)
|
||||||
|
|
||||||
within("#proposal_#{proposal.id}") do
|
within("#proposal_#{proposal.id}") do
|
||||||
accept_confirm("Are you sure? Hide author \"#{proposal.author.name}\"") { click_link "Hide author" }
|
accept_confirm("Are you sure? Block author \"#{proposal.author.name}\"") { click_link "Block author" }
|
||||||
|
|
||||||
expect(page).to have_current_path(proposals_path)
|
expect(page).to have_current_path(proposals_path)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ describe "Admin hidden comments", :admin do
|
|||||||
visit proposal_path(proposal)
|
visit proposal_path(proposal)
|
||||||
|
|
||||||
within("#proposal_#{proposal.id}") do
|
within("#proposal_#{proposal.id}") do
|
||||||
accept_confirm("Are you sure? Hide author \"#{proposal.author.name}\"") { click_link "Hide author" }
|
accept_confirm("Are you sure? Block author \"#{proposal.author.name}\"") { click_link "Block author" }
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_current_path proposals_path
|
expect(page).to have_current_path proposals_path
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe "Moderate budget investments" do
|
|||||||
login_as(mod.user)
|
login_as(mod.user)
|
||||||
visit budget_investment_path(budget, investment)
|
visit budget_investment_path(budget, investment)
|
||||||
|
|
||||||
accept_confirm("Are you sure? Hide author \"#{investment.author.name}\"") { click_link "Hide author" }
|
accept_confirm("Are you sure? Block author \"#{investment.author.name}\"") { click_link "Block author" }
|
||||||
|
|
||||||
expect(page).to have_current_path(budget_investments_path(budget))
|
expect(page).to have_current_path(budget_investments_path(budget))
|
||||||
expect(page).not_to have_content(investment.title)
|
expect(page).not_to have_content(investment.title)
|
||||||
@@ -37,7 +37,7 @@ describe "Moderate budget investments" do
|
|||||||
|
|
||||||
within "#budget_investment_#{investment.id}" do
|
within "#budget_investment_#{investment.id}" do
|
||||||
expect(page).not_to have_link("Hide")
|
expect(page).not_to have_link("Hide")
|
||||||
expect(page).not_to have_link("Hide author")
|
expect(page).not_to have_link("Block author")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ describe "Moderate users" do
|
|||||||
visit debate_path(debate1)
|
visit debate_path(debate1)
|
||||||
|
|
||||||
within("#debate_#{debate1.id}") do
|
within("#debate_#{debate1.id}") do
|
||||||
accept_confirm("Are you sure? Hide author \"#{debate1.author.name}\"") { click_link "Hide author" }
|
accept_confirm("Are you sure? Block author \"#{debate1.author.name}\"") { click_link "Block author" }
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_current_path(debates_path)
|
expect(page).to have_current_path(debates_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user