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;
|
||||
}
|
||||
|
||||
.soft-block-link {
|
||||
.hide-link {
|
||||
@include hollow-button($color-warning);
|
||||
}
|
||||
|
||||
.hide-link {
|
||||
.block-link {
|
||||
@include hollow-button($alert-color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<% if can? :hide, record.author %>
|
||||
<%= raw separator %>
|
||||
<%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(record.author_id),
|
||||
method: :put, data: { confirm: confirm_hide_author_text } %>
|
||||
<%= link_to t("admin.actions.block_author").capitalize, block_moderation_user_path(record.author_id),
|
||||
method: :put, data: { confirm: confirm_block_author_text } %>
|
||||
<% end %>
|
||||
</span>
|
||||
|
||||
@@ -20,8 +20,8 @@ class Shared::ModerationActionsComponent < ApplicationComponent
|
||||
t("admin.actions.confirm_action", action: t("admin.actions.hide"), name: record.human_name)
|
||||
end
|
||||
|
||||
def confirm_hide_author_text
|
||||
t("admin.actions.confirm_action", action: t("admin.actions.hide_author"), name: record.author.name)
|
||||
def confirm_block_author_text
|
||||
t("admin.actions.confirm_action", action: t("admin.actions.block_author"), name: record.author.name)
|
||||
end
|
||||
|
||||
def separator
|
||||
|
||||
@@ -6,16 +6,16 @@ class Moderation::UsersController < Moderation::BaseController
|
||||
def index
|
||||
end
|
||||
|
||||
def soft_block
|
||||
soft_block_user
|
||||
def hide
|
||||
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
|
||||
|
||||
def hide
|
||||
def block
|
||||
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
|
||||
|
||||
private
|
||||
@@ -24,9 +24,9 @@ class Moderation::UsersController < Moderation::BaseController
|
||||
@users = User.with_hidden.search(params[:search]).page(params[:page]).for_render
|
||||
end
|
||||
|
||||
def soft_block_user
|
||||
def hide_user
|
||||
@user.hide
|
||||
Activity.log(current_user, :soft_block, @user)
|
||||
Activity.log(current_user, :hide, @user)
|
||||
end
|
||||
|
||||
def block_user
|
||||
|
||||
@@ -47,9 +47,6 @@ 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 soft_block block restore valuate email].freeze
|
||||
VALID_ACTIONS = %w[hide block restore valuate email].freeze
|
||||
|
||||
validates :action, inclusion: { in: VALID_ACTIONS }
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
<%= t("moderation.users.index.hidden") %>
|
||||
<% else %>
|
||||
<%= 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(:block, text: t("moderation.users.index.block"), method: :put) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
@@ -4,12 +4,12 @@ en:
|
||||
title: Administration
|
||||
actions:
|
||||
actions: Actions
|
||||
block_author: "Block author"
|
||||
confirm_action: "Are you sure? %{action} \"%{name}\""
|
||||
confirm_delete: "Are you sure? This action will delete \"%{name}\" and can't be undone."
|
||||
confirm_hide: Confirm moderation
|
||||
delete: "Delete"
|
||||
hide: Hide
|
||||
hide_author: Hide author
|
||||
label: "%{action} %{name}"
|
||||
restore: Restore
|
||||
mark_featured: Featured
|
||||
|
||||
@@ -101,10 +101,10 @@ en:
|
||||
title: Proposal notifications
|
||||
users:
|
||||
index:
|
||||
block: Block
|
||||
hidden: Blocked
|
||||
hide: Block
|
||||
hide: Hide
|
||||
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.
|
||||
notice_block: User blocked. All of this user's debates and comments have been hidden.
|
||||
notice_hide: User blocked. All ot this user's debates and comments are still available.
|
||||
|
||||
@@ -4,12 +4,12 @@ es:
|
||||
title: Administración
|
||||
actions:
|
||||
actions: Acciones
|
||||
block_author: "Bloquear al autor"
|
||||
confirm_action: "¿Estás seguro? %{action} \"%{name}\""
|
||||
confirm_delete: "¿Estás seguro? Esta acción borrará \"%{name}\" y no se puede deshacer."
|
||||
confirm_hide: Confirmar moderación
|
||||
delete: Borrar
|
||||
hide: Ocultar
|
||||
hide_author: Bloquear al autor
|
||||
label: "%{action} %{name}"
|
||||
restore: Volver a mostrar
|
||||
mark_featured: Destacar
|
||||
|
||||
@@ -101,10 +101,10 @@ es:
|
||||
title: Notificaciones de propuestas
|
||||
users:
|
||||
index:
|
||||
block: Bloquear
|
||||
hidden: Bloqueado
|
||||
hide: Bloquear
|
||||
hide: Ocultar
|
||||
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.
|
||||
notice_block: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
||||
notice_hide: Usuario bloqueado. Todos sus debates y comentarios siguen disponibles.
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace :moderation do
|
||||
resources :users, only: :index do
|
||||
member do
|
||||
put :hide
|
||||
put :soft_block
|
||||
put :block
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,19 @@ describe Moderation::UsersController do
|
||||
|
||||
describe "PUT hide" 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"
|
||||
end
|
||||
@@ -15,7 +27,7 @@ describe Moderation::UsersController do
|
||||
proposal = create(:proposal, author: user)
|
||||
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(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)
|
||||
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)
|
||||
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,9 +90,6 @@ 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) }
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ describe "Admin activity" do
|
||||
visit proposal_path(proposal)
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ describe "Admin hidden comments", :admin do
|
||||
visit proposal_path(proposal)
|
||||
|
||||
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
|
||||
|
||||
expect(page).to have_current_path proposals_path
|
||||
|
||||
@@ -23,7 +23,7 @@ describe "Moderate budget investments" do
|
||||
login_as(mod.user)
|
||||
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).not_to have_content(investment.title)
|
||||
@@ -37,7 +37,7 @@ describe "Moderate budget investments" do
|
||||
|
||||
within "#budget_investment_#{investment.id}" do
|
||||
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
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ describe "Moderate users" do
|
||||
visit debate_path(debate1)
|
||||
|
||||
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
|
||||
|
||||
expect(page).to have_current_path(debates_path)
|
||||
|
||||
Reference in New Issue
Block a user