Recommendations are automatically disabled if dismissed by user
This commit is contained in:
@@ -44,6 +44,14 @@ class DebatesController < ApplicationController
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
end
|
||||
|
||||
def disable_recommendations
|
||||
if current_user.update(recommended_debates: false)
|
||||
redirect_to debates_path, notice: t('debates.index.recommendations.actions.success')
|
||||
else
|
||||
redirect_to debates_path, error: t('debates.index.recommendations.actions.error')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def debate_params
|
||||
|
||||
@@ -80,6 +80,14 @@ class ProposalsController < ApplicationController
|
||||
@tag_cloud = tag_cloud
|
||||
end
|
||||
|
||||
def disable_recommendations
|
||||
if current_user.update(recommended_proposals: false)
|
||||
redirect_to proposals_path, notice: t('proposals.index.recommendations.actions.success')
|
||||
else
|
||||
redirect_to proposals_path, error: t('proposals.index.recommendations.actions.error')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def proposal_params
|
||||
|
||||
@@ -29,6 +29,7 @@ module Abilities
|
||||
can [:read], Legislation::Question
|
||||
can [:read, :map, :share], Legislation::Proposal
|
||||
can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation
|
||||
can :disable_recommendations, [Debate, Proposal]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +36,9 @@
|
||||
<% end %>
|
||||
|
||||
<% if @recommended_debates.present? %>
|
||||
<%= render "shared/recommended_index", recommended: @recommended_debates %>
|
||||
<%= render "shared/recommended_index", recommended: @recommended_debates,
|
||||
disable_recommendations_path: recommendations_disable_debates_path,
|
||||
namespace: "debates" %>
|
||||
<% end %>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
<% end %>
|
||||
|
||||
<% if @recommended_proposals.present? %>
|
||||
<%= render "shared/recommended_index", recommended: @recommended_proposals %>
|
||||
<%= render "shared/recommended_index", recommended: @recommended_proposals,
|
||||
disable_recommendations_path: recommendations_disable_proposals_path,
|
||||
namespace: "proposals" %>
|
||||
<% end %>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -5,9 +5,13 @@
|
||||
</div>
|
||||
|
||||
<div id="recommendations" data-toggler=".hide">
|
||||
<%= link_to "#", title: t("shared.recommended_index.hide"),
|
||||
class: "float-right-medium small hide-recommendations",
|
||||
data: { toggle: "recommendations" } do %>
|
||||
<%= link_to disable_recommendations_path, title: t("shared.recommended_index.hide"),
|
||||
class: "float-right-medium small hide-recommendations",
|
||||
data: {
|
||||
toggle: "recommendations",
|
||||
confirm: t("#{namespace}.index.recommendations.disable")
|
||||
},
|
||||
method: :put do %>
|
||||
<span class="icon-x"></span>
|
||||
<span class="show-for-sr"><%= t("shared.recommended_index.hide") %></span>
|
||||
<% end %>
|
||||
|
||||
@@ -113,6 +113,10 @@ en:
|
||||
recommendations:
|
||||
without_results: There are not debates related to your interests
|
||||
without_interests: Follow proposals so we can give you recommendations
|
||||
disable: "If you dismiss debates recommendations, the setting will be automatically disabled. Do you wish to continue?"
|
||||
actions:
|
||||
success: "Recommendations for debates are now disabled for this account"
|
||||
error: "An error has occured. Please go to 'Your account' page to manually disable recommendations for debates"
|
||||
search_form:
|
||||
button: Search
|
||||
placeholder: Search debates...
|
||||
@@ -364,6 +368,10 @@ en:
|
||||
recommendations:
|
||||
without_results: There are not proposals related to your interests
|
||||
without_interests: Follow proposals so we can give you recommendations
|
||||
disable: "If you dismiss proposals recommendations, the setting will be automatically disabled. Do you wish to continue?"
|
||||
actions:
|
||||
success: "Recommendations for proposals are now disabled for this account"
|
||||
error: "An error has occured. Please go to 'Your account' page to manually disable recommendations for proposals"
|
||||
retired_proposals: Retired proposals
|
||||
retired_proposals_link: "Proposals retired by the author"
|
||||
retired_links:
|
||||
|
||||
@@ -113,6 +113,10 @@ es:
|
||||
recommendations:
|
||||
without_results: No existen debates relacionados con tus intereses
|
||||
without_interests: Sigue propuestas para que podamos darte recomendaciones
|
||||
disable: "Si ocultas las recomendaciones para debates, se desactivará automáticamente el ajuste. ¿Deseas continuar?"
|
||||
actions:
|
||||
success: "Las recomendaciones de debates han sido desactivadas"
|
||||
error: "Ha ocurrido un error. Por favor dirígete al apartado 'Mi cuenta' para desactivar las recomendaciones manualmente"
|
||||
search_form:
|
||||
button: Buscar
|
||||
placeholder: Buscar debates...
|
||||
@@ -364,6 +368,10 @@ es:
|
||||
recommendations:
|
||||
without_results: No existen propuestas relacionadas con tus intereses
|
||||
without_interests: Sigue propuestas para que podamos darte recomendaciones
|
||||
disable: "Si ocultas las recomendaciones para propuestas, se desactivará automáticamente el ajuste. ¿Deseas continuar?"
|
||||
actions:
|
||||
success: "Las recomendaciones de propuestas han sido desactivadas"
|
||||
error: "Ha ocurrido un error. Por favor dirígete al apartado 'Mi cuenta' para desactivar las recomendaciones manualmente"
|
||||
retired_proposals: Propuestas retiradas
|
||||
retired_proposals_link: "Propuestas retiradas por sus autores"
|
||||
retired_links:
|
||||
|
||||
@@ -10,5 +10,6 @@ resources :debates do
|
||||
collection do
|
||||
get :map
|
||||
get :suggest
|
||||
put 'recommendations/disable', only: :index, controller: 'debates', action: :disable_recommendations
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,5 +13,6 @@ resources :proposals do
|
||||
get :map
|
||||
get :suggest
|
||||
get :summary
|
||||
put 'recommendations/disable', only: :index, controller: 'proposals', action: :disable_recommendations
|
||||
end
|
||||
end
|
||||
|
||||
@@ -488,7 +488,7 @@ feature 'Debates' do
|
||||
expect(page).not_to have_link('recommendations')
|
||||
end
|
||||
|
||||
scenario 'shown on index header are dismissable', :js do
|
||||
scenario 'are automatically disabled when dismissed from index', :js do
|
||||
user = create(:user)
|
||||
proposal = create(:proposal, tag_list: 'Sport')
|
||||
create(:follow, followable: proposal, user: user)
|
||||
@@ -502,13 +502,19 @@ feature 'Debates' do
|
||||
expect(page).to have_content('Medium')
|
||||
expect(page).to have_css('.recommendation', count: 3)
|
||||
|
||||
find('.icon-x').click
|
||||
|
||||
expect(page).not_to have_content('Best')
|
||||
expect(page).not_to have_content('Worst')
|
||||
expect(page).not_to have_content('Medium')
|
||||
expect(page).not_to have_css('.recommendation', count: 3)
|
||||
accept_confirm { click_link 'Hide recommendations' }
|
||||
end
|
||||
|
||||
expect(page).not_to have_link('recommendations')
|
||||
expect(page).not_to have_css('.recommendation', count: 3)
|
||||
expect(page).to have_content('Recommendations for debates are now disabled for this account')
|
||||
|
||||
user.reload
|
||||
|
||||
visit account_path
|
||||
|
||||
expect(find("#account_recommended_debates")).not_to be_checked
|
||||
expect(user.recommended_debates).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -812,7 +812,7 @@ feature 'Proposals' do
|
||||
expect(page).not_to have_link('recommendations')
|
||||
end
|
||||
|
||||
scenario 'shown on index header are dismissable', :js do
|
||||
scenario 'are automatically disabled when dismissed from index', :js do
|
||||
user = create(:user)
|
||||
proposal = create(:proposal, tag_list: 'Sport')
|
||||
create(:follow, followable: proposal, user: user)
|
||||
@@ -826,13 +826,19 @@ feature 'Proposals' do
|
||||
expect(page).to have_content('Medium')
|
||||
expect(page).to have_css('.recommendation', count: 3)
|
||||
|
||||
find('.icon-x').click
|
||||
|
||||
expect(page).not_to have_content('Best')
|
||||
expect(page).not_to have_content('Worst')
|
||||
expect(page).not_to have_content('Medium')
|
||||
expect(page).not_to have_css('.recommendation', count: 3)
|
||||
accept_confirm { click_link 'Hide recommendations' }
|
||||
end
|
||||
|
||||
expect(page).not_to have_link('recommendations')
|
||||
expect(page).not_to have_css('.recommendation', count: 3)
|
||||
expect(page).to have_content('Recommendations for proposals are now disabled for this account')
|
||||
|
||||
user.reload
|
||||
|
||||
visit account_path
|
||||
|
||||
expect(find("#account_recommended_proposals")).not_to be_checked
|
||||
expect(user.recommended_proposals).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user