diff --git a/app/controllers/admin/proposals_controller.rb b/app/controllers/admin/proposals_controller.rb new file mode 100644 index 000000000..4f399bff7 --- /dev/null +++ b/app/controllers/admin/proposals_controller.rb @@ -0,0 +1,26 @@ +class Admin::ProposalsController < Admin::BaseController + has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index + + before_action :load_proposal, only: [:confirm_hide, :restore] + + def index + @proposals = Proposal.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page]) + end + + def confirm_hide + @proposal.confirm_hide + redirect_to request.query_parameters.merge(action: :index) + end + + def restore + @proposal.restore + redirect_to request.query_parameters.merge(action: :index) + end + + private + + def load_proposal + @proposal = Proposal.with_hidden.find(params[:id]) + end + +end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 89cf9694e..42d979209 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -11,6 +11,13 @@ <% end %> +
  • > + <%= link_to admin_proposals_path do %> + + <%= t("admin.menu.hidden_proposals") %> + <% end %> +
  • +
  • > <%= link_to admin_debates_path do %> diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/proposals/index.html.erb new file mode 100644 index 000000000..2c6c8fd84 --- /dev/null +++ b/app/views/admin/proposals/index.html.erb @@ -0,0 +1,28 @@ +

    <%= t("admin.proposals.index.title") %>

    + +<%= render 'shared/filter_subnav', i18n_namespace: "admin.proposals.index" %> + +

    <%= page_entries_info @proposals %>

    + + + +<%= paginate @proposals %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 8d52dc1bf..b8da4429b 100644 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -12,6 +12,7 @@ en: menu: settings: Global settings debate_topics: Debate topics + hidden_proposals: Hidden proposals hidden_debates: Hidden debates hidden_comments: Hidden comments hidden_users: Blocked users @@ -71,6 +72,14 @@ en: all: All with_confirmed_hide: Confirmed without_confirmed_hide: Pending + proposals: + index: + title: Hidden proposals + filter: Filter + filters: + all: All + with_confirmed_hide: Confirmed + without_confirmed_hide: Pending users: index: title: Banned users diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index f7fc12e14..26e241a99 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -12,6 +12,7 @@ es: menu: settings: Configuración global debate_topics: Temas de debate + hidden_proposals: Propuestas ocultas hidden_debates: Debates ocultos hidden_comments: Comentarios ocultos hidden_users: Usuarios bloqueados @@ -71,6 +72,14 @@ es: all: Todos with_confirmed_hide: Confirmados without_confirmed_hide: Pendientes + proposals: + index: + title: Propuestas ocultos + filter: Filtro + filters: + all: Todas + with_confirmed_hide: Confirmadas + without_confirmed_hide: Pendientes users: index: title: Usuarios bloqueados diff --git a/spec/features/admin/proposals_spec.rb b/spec/features/admin/proposals_spec.rb new file mode 100644 index 000000000..e31b84578 --- /dev/null +++ b/spec/features/admin/proposals_spec.rb @@ -0,0 +1,85 @@ +require 'rails_helper' + +feature 'Admin proposals' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + scenario 'Restore' do + proposal = create(:proposal, :hidden) + visit admin_proposals_path + + click_link 'Restore' + + expect(page).to_not have_content(proposal.title) + + expect(proposal.reload).to_not be_hidden + end + + scenario 'Confirm hide' do + proposal = create(:proposal, :hidden) + visit admin_proposals_path + + click_link 'Confirm' + + expect(page).to_not have_content(proposal.title) + click_link('Confirmed') + expect(page).to have_content(proposal.title) + + expect(proposal.reload).to be_confirmed_hide + end + + scenario "Current filter is properly highlighted" do + visit admin_proposals_path + expect(page).to_not have_link('Pending') + expect(page).to have_link('All') + expect(page).to have_link('Confirmed') + + visit admin_proposals_path(filter: 'Pending') + expect(page).to_not have_link('Pending') + expect(page).to have_link('All') + expect(page).to have_link('Confirmed') + + visit admin_proposals_path(filter: 'all') + expect(page).to have_link('Pending') + expect(page).to_not have_link('All') + expect(page).to have_link('Confirmed') + + visit admin_proposals_path(filter: 'with_confirmed_hide') + expect(page).to have_link('All') + expect(page).to have_link('Pending') + expect(page).to_not have_link('Confirmed') + end + + scenario "Filtering proposals" do + create(:proposal, :hidden, title: "Unconfirmed proposal") + create(:proposal, :hidden, :with_confirmed_hide, title: "Confirmed proposal") + + visit admin_proposals_path(filter: 'pending') + expect(page).to have_content('Unconfirmed proposal') + expect(page).to_not have_content('Confirmed proposal') + + visit admin_proposals_path(filter: 'all') + expect(page).to have_content('Unconfirmed proposal') + expect(page).to have_content('Confirmed proposal') + + visit admin_proposals_path(filter: 'with_confirmed_hide') + expect(page).to_not have_content('Unconfirmed proposal') + expect(page).to have_content('Confirmed proposal') + end + + scenario "Action links remember the pagination setting and the filter" do + per_page = Kaminari.config.default_per_page + (per_page + 2).times { create(:proposal, :hidden, :with_confirmed_hide) } + + visit admin_proposals_path(filter: 'with_confirmed_hide', page: 2) + + click_on('Restore', match: :first, exact: true) + + expect(current_url).to include('filter=with_confirmed_hide') + expect(current_url).to include('page=2') + end + +end