Add a way for moderators to view user inboxes
This commit is contained in:
parent
cd581fd2b1
commit
be8ba63b95
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Moderation::InboxController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
@user = User.find_by(screen_name: params[:user])
|
||||
@inboxes = @user.cursored_inbox(last_id: params[:last_id])
|
||||
@inbox_last_id = @inboxes.map(&:id).min
|
||||
@more_data_available = !@user.cursored_inbox(last_id: @inbox_last_id, size: 1).count.zero?
|
||||
@inbox_count = @user.inboxes.count
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js { render layout: false }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -32,25 +32,25 @@
|
|||
%a.dropdown-item{ href: rails_admin_path_for_resource(i) }
|
||||
%i.fa.fa-gears
|
||||
= t("voc.view_in_rails_admin")
|
||||
|
||||
.card-body
|
||||
%textarea.form-control{ name: "ib-answer", placeholder: t(".placeholder"), data: { id: i.id } }
|
||||
%br/
|
||||
%button.btn.btn-success{ name: "ib-answer", data: { ib_id: i.id } }
|
||||
= t("voc.answer")
|
||||
%button.btn.btn-danger{ name: "ib-destroy", data: { ib_id: i.id } }
|
||||
= t("voc.delete")
|
||||
%button.btn.btn-default{ name: "ib-options", data: { ib_id: i.id, state: :hidden } }
|
||||
%i.fa.fa-cog
|
||||
%span.sr-only= t(".options")
|
||||
.card-footer.d-none{ id: "ib-options-#{i.id}" }
|
||||
%h4= t(".sharing.heading")
|
||||
- if current_user.services.count.positive?
|
||||
.row
|
||||
- current_user.services.each do |service|
|
||||
.col-md-3.col-sm-4.col-xs-6
|
||||
%label
|
||||
%input{ type: "checkbox", name: "ib-share", checked: :checked, data: { ib_id: i.id, service: service.provider } }
|
||||
= raw t(".sharing.post_to", service: service.provider.capitalize)
|
||||
- else
|
||||
%p= t(".sharing.none_html", settings: link_to(t(".sharing.settings"), services_path))
|
||||
- if current_user == i.user
|
||||
.card-body
|
||||
%textarea.form-control{ name: "ib-answer", placeholder: t(".placeholder"), data: { id: i.id } }
|
||||
%br/
|
||||
%button.btn.btn-success{ name: "ib-answer", data: { ib_id: i.id } }
|
||||
= t("voc.answer")
|
||||
%button.btn.btn-danger{ name: "ib-destroy", data: { ib_id: i.id } }
|
||||
= t("voc.delete")
|
||||
%button.btn.btn-default{ name: "ib-options", data: { ib_id: i.id, state: :hidden } }
|
||||
%i.fa.fa-cog
|
||||
%span.sr-only= t(".options")
|
||||
.card-footer.d-none{ id: "ib-options-#{i.id}" }
|
||||
%h4= t(".sharing.heading")
|
||||
- if current_user.services.count.positive?
|
||||
.row
|
||||
- current_user.services.each do |service|
|
||||
.col-md-3.col-sm-4.col-xs-6
|
||||
%label
|
||||
%input{ type: "checkbox", name: "ib-share", checked: :checked, data: { ib_id: i.id, service: service.provider } }
|
||||
= raw t(".sharing.post_to", service: service.provider.capitalize)
|
||||
- else
|
||||
%p= t(".sharing.none_html", settings: link_to(t(".sharing.settings"), services_path))
|
||||
|
|
|
@ -11,4 +11,4 @@
|
|||
|
||||
.d-flex.justify-content-center.justify-content-sm-start
|
||||
%button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @inbox_last_id } }
|
||||
= t("vpc.load")
|
||||
= t("voc.load")
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
- provide(:title, generate_title(t(".title", user: @user.screen_name)))
|
||||
|
||||
.card.question--fixed
|
||||
.container
|
||||
.card-body
|
||||
.media
|
||||
%a.pull-left{ href: show_user_profile_path(@user.screen_name) }
|
||||
%img.answerbox__question-user-avatar.avatar-md{ src: @user.profile_picture.url(:medium) }
|
||||
.media-body
|
||||
Viewing inbox for
|
||||
%br
|
||||
%strong= @user.screen_name
|
||||
= " (##{@user.id})"
|
||||
.container-lg.container--main
|
||||
#entries
|
||||
- @inboxes.each do |i|
|
||||
= render "inbox/entry", i: i
|
||||
|
||||
= render "shared/cursored_pagination_dummy", more_data_available: @more_data_available, last_id: @inbox_last_id
|
||||
|
||||
- if @more_data_available
|
||||
|
||||
.d-flex.justify-content-center.justify-content-sm-start
|
||||
%button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @inbox_last_id } }
|
||||
= t("voc.load")
|
|
@ -0,0 +1,8 @@
|
|||
$('#entries').append('<% @inboxes.each do |i|
|
||||
%><%= j render 'inbox/entry', i: i
|
||||
%><% end %>');
|
||||
<% if @more_data_available %>
|
||||
$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @inbox_last_id %>');
|
||||
<% else %>
|
||||
$('#pagination, #load-more-btn').remove();
|
||||
<% end %>
|
|
@ -36,6 +36,10 @@
|
|||
%a.dropdown-item{ href: '#', data: { target: '#modal-ban', toggle: :modal } }
|
||||
%i.fa.fa-ban
|
||||
= t 'views.actions.ban'
|
||||
- if current_user.mod? && user != current_user
|
||||
%a.dropdown-item{ href: mod_inbox_index_path(user: user.screen_name) }
|
||||
%i.fa.fa-inbox
|
||||
View inbox
|
||||
- if current_user.has_role? :administrator
|
||||
%a.dropdown-item{ href: rails_admin_path_for_resource(user), target: '_blank' }
|
||||
%i.fa.fa-cogs
|
||||
|
|
|
@ -326,3 +326,7 @@ en:
|
|||
title: "Theme Settings"
|
||||
export:
|
||||
title: "Export"
|
||||
moderation:
|
||||
inbox:
|
||||
index:
|
||||
title: "Inbox for %{user}"
|
||||
|
|
|
@ -25,6 +25,7 @@ Rails.application.routes.draw do
|
|||
match '/moderation/priority(/:user_id)', to: 'moderation#priority', via: :get, as: :moderation_priority
|
||||
match '/moderation/ip/:user_id', to: 'moderation#ip', via: :get, as: :moderation_ip
|
||||
match '/moderation(/:type)', to: 'moderation#index', via: :get, as: :moderation, defaults: {type: 'all'}
|
||||
match '/moderation/inbox/:user', to: 'moderation/inbox#index', via: :get, as: :mod_inbox_index
|
||||
namespace :ajax do
|
||||
match '/mod/destroy_report', to: 'moderation#destroy_report', via: :post, as: :mod_destroy_report
|
||||
match '/mod/create_comment', to: 'moderation#create_comment', via: :post, as: :mod_create_comment
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Moderation::InboxController do
|
||||
context "#index" do
|
||||
subject { get :index, params: params }
|
||||
|
||||
let(:target_user) { FactoryBot.create(:user) }
|
||||
let!(:inboxes) { FactoryBot.create_list(:inbox, 60, user: target_user) }
|
||||
let(:params) { { user: target_user.screen_name } }
|
||||
|
||||
context "moderator signed in" do
|
||||
before do
|
||||
sign_in(FactoryBot.create(:user, roles: [:moderator]))
|
||||
end
|
||||
|
||||
it "renders the index template" do
|
||||
subject
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
|
||||
it "assigns inbox entries" do
|
||||
subject
|
||||
expect(assigns(:inboxes).count).to eq(APP_CONFIG[:items_per_page])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue