diff --git a/app/controllers/admin/activity_controller.rb b/app/controllers/admin/activity_controller.rb new file mode 100644 index 000000000..8f7993a09 --- /dev/null +++ b/app/controllers/admin/activity_controller.rb @@ -0,0 +1,8 @@ +class Admin::ActivityController < Admin::BaseController + has_filters %w{all on_users on_proposals on_debates on_comments} + + def show + @activity = Activity.for_render.send(@current_filter).order(created_at: :desc).page(params[:page]) + end + +end diff --git a/app/controllers/moderation/proposals_controller.rb b/app/controllers/moderation/proposals_controller.rb index e7cf86043..f8517eb4a 100644 --- a/app/controllers/moderation/proposals_controller.rb +++ b/app/controllers/moderation/proposals_controller.rb @@ -16,6 +16,7 @@ class Moderation::ProposalsController < Moderation::BaseController def hide @proposal.hide + Activity.log(current_user, :hide, @proposal) end def moderate diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 42d979209..89e1b6641 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -60,6 +60,13 @@ <% end %> +
  • > + <%= link_to admin_activity_path do %> + + <%= t('admin.menu.activity') %> + <% end %> +
  • +
  • > <%= link_to admin_settings_path do %> diff --git a/app/views/admin/activity/show.html.erb b/app/views/admin/activity/show.html.erb new file mode 100644 index 000000000..0f422cfa8 --- /dev/null +++ b/app/views/admin/activity/show.html.erb @@ -0,0 +1,43 @@ +

    <%= t("admin.activity.show.title") %>

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

    <%= page_entries_info @activity %>

    + + + + + + + + + <% @activity.each do |activity| %> + + + + + + + <% end %> +
    <%= t("admin.activity.show.type") %><%= t("admin.activity.show.action") %> <%= t("admin.activity.show.by") %>
    + <%= activity.actionable_type.constantize.model_name.human %>
    + <%= l activity.actionable.created_at.to_date %> +
    + <%= t("admin.activity.show.actions.#{activity.action}") %>
    + <%= l activity.created_at.to_date %> +
    + <% case activity.actionable_type %> + <% when "User" %> + <%= activity.actionable.username %> (<%= activity.actionable.email %>) + <% when "Comment" %> + <%= activity.actionable.body %> + <% else %> + <%= activity.actionable.title %> +
    +
    + <%= activity.actionable.description %> +
    + <% end %> +
    <%= activity.user.name %> (<%= activity.user.email %>)
    + +<%= paginate @activity %> diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index f17dc73de..303bd5ded 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -1,6 +1,7 @@ en: activerecord: models: + activity: Activity comment: Comment debate: Debate proposal: Proposal diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 0d6ecba40..3ba5e7cca 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -1,6 +1,9 @@ es: activerecord: models: + activity: + one: actividad + other: actividades comment: one: Comentario other: Comentarios diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 7317b2a31..a134cd673 100644 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -20,6 +20,7 @@ en: officials: Officials moderators: Moderators stats: Statistics + activity: Moderation Activity organizations: index: title: Organizations @@ -129,4 +130,18 @@ en: moderator: delete: Delete add: Add + activity: + show: + title: Activity of Moderators + filter: Show + filters: + all: All + on_proposals: On Proposals + on_debates: On Debates + on_comments: On Comments + on_users: On Users + actions: + hide: Hidden + restore: Restored + block: Blocked diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 01117ff42..8c6e43371 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -20,6 +20,7 @@ es: officials: Cargos públicos moderators: Moderadores stats: Estadísticas + activity: Actividad de moderadores organizations: index: title: Organizaciones @@ -129,3 +130,17 @@ es: moderator: delete: Borrar add: Añadir + activity: + show: + title: Actividad de los Moderadores + filter: Mostrar + filters: + all: Todo + on_proposals: Propuestas + on_debates: Debates + on_comments: Comentarios + on_users: Usuarios + actions: + hide: Ocultado + restore: Restaurado + block: Bloqueado diff --git a/config/routes.rb b/config/routes.rb index ae52181bb..e60b50ca8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,6 +112,8 @@ Rails.application.routes.draw do resources :moderators, only: [:index, :create, :destroy] do collection { get :search } end + + resource :activity, controller: :activity, only: :show end namespace :moderation do diff --git a/spec/features/admin/activity_spec.rb b/spec/features/admin/activity_spec.rb new file mode 100644 index 000000000..9382875f1 --- /dev/null +++ b/spec/features/admin/activity_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +feature 'Admin activity' do + + background do + @admin = create(:administrator) + login_as(@admin.user) + end + + context "Proposals" do + scenario "Shows moderation activity on proposals", :js do + proposal = create(:proposal) + + visit proposal_path(proposal) + + within("#proposal_#{proposal.id}") do + click_link 'Hide' + end + + visit admin_activity_path + + within("#activity_#{Activity.last.id}") do + expect(page).to have_content(proposal.title) + expect(page).to have_content(@admin.user.username) + end + end + end + +end \ No newline at end of file