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)
|
redirect_to request.query_parameters.merge(action: :index)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def debate_params
|
def debate_params
|
||||||
|
|||||||
@@ -80,6 +80,14 @@ class ProposalsController < ApplicationController
|
|||||||
@tag_cloud = tag_cloud
|
@tag_cloud = tag_cloud
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def proposal_params
|
def proposal_params
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ module Abilities
|
|||||||
can [:read], Legislation::Question
|
can [:read], Legislation::Question
|
||||||
can [:read, :map, :share], Legislation::Proposal
|
can [:read, :map, :share], Legislation::Proposal
|
||||||
can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation
|
can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation
|
||||||
|
can :disable_recommendations, [Debate, Proposal]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -36,7 +36,9 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @recommended_debates.present? %>
|
<% 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 %>
|
<% end %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -38,7 +38,9 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @recommended_proposals.present? %>
|
<% 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 %>
|
<% end %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -5,9 +5,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="recommendations" data-toggler=".hide">
|
<div id="recommendations" data-toggler=".hide">
|
||||||
<%= link_to "#", title: t("shared.recommended_index.hide"),
|
<%= link_to disable_recommendations_path, title: t("shared.recommended_index.hide"),
|
||||||
class: "float-right-medium small hide-recommendations",
|
class: "float-right-medium small hide-recommendations",
|
||||||
data: { toggle: "recommendations" } do %>
|
data: {
|
||||||
|
toggle: "recommendations",
|
||||||
|
confirm: t("#{namespace}.index.recommendations.disable")
|
||||||
|
},
|
||||||
|
method: :put do %>
|
||||||
<span class="icon-x"></span>
|
<span class="icon-x"></span>
|
||||||
<span class="show-for-sr"><%= t("shared.recommended_index.hide") %></span>
|
<span class="show-for-sr"><%= t("shared.recommended_index.hide") %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ en:
|
|||||||
recommendations:
|
recommendations:
|
||||||
without_results: There are not debates related to your interests
|
without_results: There are not debates related to your interests
|
||||||
without_interests: Follow proposals so we can give you recommendations
|
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:
|
search_form:
|
||||||
button: Search
|
button: Search
|
||||||
placeholder: Search debates...
|
placeholder: Search debates...
|
||||||
@@ -364,6 +368,10 @@ en:
|
|||||||
recommendations:
|
recommendations:
|
||||||
without_results: There are not proposals related to your interests
|
without_results: There are not proposals related to your interests
|
||||||
without_interests: Follow proposals so we can give you recommendations
|
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: Retired proposals
|
||||||
retired_proposals_link: "Proposals retired by the author"
|
retired_proposals_link: "Proposals retired by the author"
|
||||||
retired_links:
|
retired_links:
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ es:
|
|||||||
recommendations:
|
recommendations:
|
||||||
without_results: No existen debates relacionados con tus intereses
|
without_results: No existen debates relacionados con tus intereses
|
||||||
without_interests: Sigue propuestas para que podamos darte recomendaciones
|
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:
|
search_form:
|
||||||
button: Buscar
|
button: Buscar
|
||||||
placeholder: Buscar debates...
|
placeholder: Buscar debates...
|
||||||
@@ -364,6 +368,10 @@ es:
|
|||||||
recommendations:
|
recommendations:
|
||||||
without_results: No existen propuestas relacionadas con tus intereses
|
without_results: No existen propuestas relacionadas con tus intereses
|
||||||
without_interests: Sigue propuestas para que podamos darte recomendaciones
|
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: Propuestas retiradas
|
||||||
retired_proposals_link: "Propuestas retiradas por sus autores"
|
retired_proposals_link: "Propuestas retiradas por sus autores"
|
||||||
retired_links:
|
retired_links:
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ resources :debates do
|
|||||||
collection do
|
collection do
|
||||||
get :map
|
get :map
|
||||||
get :suggest
|
get :suggest
|
||||||
|
put 'recommendations/disable', only: :index, controller: 'debates', action: :disable_recommendations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ resources :proposals do
|
|||||||
get :map
|
get :map
|
||||||
get :suggest
|
get :suggest
|
||||||
get :summary
|
get :summary
|
||||||
|
put 'recommendations/disable', only: :index, controller: 'proposals', action: :disable_recommendations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -488,7 +488,7 @@ feature 'Debates' do
|
|||||||
expect(page).not_to have_link('recommendations')
|
expect(page).not_to have_link('recommendations')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'shown on index header are dismissable', :js do
|
scenario 'are automatically disabled when dismissed from index', :js do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
proposal = create(:proposal, tag_list: 'Sport')
|
proposal = create(:proposal, tag_list: 'Sport')
|
||||||
create(:follow, followable: proposal, user: user)
|
create(:follow, followable: proposal, user: user)
|
||||||
@@ -502,13 +502,19 @@ feature 'Debates' do
|
|||||||
expect(page).to have_content('Medium')
|
expect(page).to have_content('Medium')
|
||||||
expect(page).to have_css('.recommendation', count: 3)
|
expect(page).to have_css('.recommendation', count: 3)
|
||||||
|
|
||||||
find('.icon-x').click
|
accept_confirm { click_link 'Hide recommendations' }
|
||||||
|
|
||||||
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)
|
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -812,7 +812,7 @@ feature 'Proposals' do
|
|||||||
expect(page).not_to have_link('recommendations')
|
expect(page).not_to have_link('recommendations')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'shown on index header are dismissable', :js do
|
scenario 'are automatically disabled when dismissed from index', :js do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
proposal = create(:proposal, tag_list: 'Sport')
|
proposal = create(:proposal, tag_list: 'Sport')
|
||||||
create(:follow, followable: proposal, user: user)
|
create(:follow, followable: proposal, user: user)
|
||||||
@@ -826,13 +826,19 @@ feature 'Proposals' do
|
|||||||
expect(page).to have_content('Medium')
|
expect(page).to have_content('Medium')
|
||||||
expect(page).to have_css('.recommendation', count: 3)
|
expect(page).to have_css('.recommendation', count: 3)
|
||||||
|
|
||||||
find('.icon-x').click
|
accept_confirm { click_link 'Hide recommendations' }
|
||||||
|
|
||||||
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)
|
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user