FIX: Ensure that post action moderation post uses the site's default locale.
https://meta.discourse.org/t/a-post-in-looking-for-someone-to-customize-discourse-to-create-a-forum-site-requires-staff-attention/67468/5?u=tgxworld
This commit is contained in:
parent
e993d53260
commit
90d7dd1f05
|
@ -207,7 +207,10 @@ SQL
|
||||||
return if staff_already_replied?(related_post.topic)
|
return if staff_already_replied?(related_post.topic)
|
||||||
message_key = "flags_dispositions.#{disposition}"
|
message_key = "flags_dispositions.#{disposition}"
|
||||||
message_key << "_and_deleted" if delete_post
|
message_key << "_and_deleted" if delete_post
|
||||||
related_post.topic.add_moderator_post(moderator, I18n.t(message_key))
|
|
||||||
|
I18n.with_locale(SiteSetting.default_locale) do
|
||||||
|
related_post.topic.add_moderator_post(moderator, I18n.t(message_key))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def staff_already_replied?(topic)
|
def staff_already_replied?(topic)
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
describe Admin::FlagsController do
|
|
||||||
|
|
||||||
it "is a subclass of AdminController" do
|
|
||||||
expect(Admin::FlagsController < Admin::AdminController).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'while logged in as an admin' do
|
|
||||||
before do
|
|
||||||
@user = log_in(:admin)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'index' do
|
|
||||||
it 'returns empty json when nothing is flagged' do
|
|
||||||
xhr :get, :index
|
|
||||||
|
|
||||||
data = ::JSON.parse(response.body)
|
|
||||||
expect(data["users"]).to eq([])
|
|
||||||
expect(data["posts"]).to eq([])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns a valid json payload when some thing is flagged' do
|
|
||||||
p = Fabricate(:post)
|
|
||||||
u = Fabricate(:user)
|
|
||||||
|
|
||||||
PostAction.act(u, p, PostActionType.types[:spam])
|
|
||||||
xhr :get, :index
|
|
||||||
|
|
||||||
data = ::JSON.parse(response.body)
|
|
||||||
data["users"].length == 2
|
|
||||||
data["posts"].length == 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "Managing flags as an admin" do
|
||||||
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
let(:post) { Fabricate(:post) }
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in(admin)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'viewing flags' do
|
||||||
|
it 'should return the right response when nothing is flagged' do
|
||||||
|
get '/admin/flags.json'
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
data = ::JSON.parse(response.body)
|
||||||
|
expect(data["users"]).to eq([])
|
||||||
|
expect(data["posts"]).to eq([])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the right response' do
|
||||||
|
PostAction.act(user, post, PostActionType.types[:spam])
|
||||||
|
|
||||||
|
get '/admin/flags.json'
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
data = ::JSON.parse(response.body)
|
||||||
|
data["users"].length == 2
|
||||||
|
data["posts"].length == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'agreeing with a flag' do
|
||||||
|
it 'should work' do
|
||||||
|
SiteSetting.allow_user_locale = true
|
||||||
|
post_action = PostAction.act(user, post, PostActionType.types[:spam], message: 'bad')
|
||||||
|
admin.update!(locale: 'ja')
|
||||||
|
|
||||||
|
xhr :post, "/admin/flags/agree/#{post.id}"
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
post_action.reload
|
||||||
|
|
||||||
|
expect(post_action.agreed_by_id).to eq(admin.id)
|
||||||
|
|
||||||
|
post = Post.offset(1).last
|
||||||
|
|
||||||
|
expect(post.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed') })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -542,7 +542,7 @@ describe PostAction do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".add_moderator_post_if_needed" do
|
describe "#add_moderator_post_if_needed" do
|
||||||
|
|
||||||
it "should not add a moderator post when it's disabled" do
|
it "should not add a moderator post when it's disabled" do
|
||||||
post = create_post
|
post = create_post
|
||||||
|
@ -552,7 +552,7 @@ describe PostAction do
|
||||||
topic = action.related_post.topic
|
topic = action.related_post.topic
|
||||||
expect(topic.posts.count).to eq(1)
|
expect(topic.posts.count).to eq(1)
|
||||||
|
|
||||||
SiteSetting.expects(:auto_respond_to_flag_actions).returns(false)
|
SiteSetting.auto_respond_to_flag_actions = false
|
||||||
PostAction.agree_flags!(post, admin)
|
PostAction.agree_flags!(post, admin)
|
||||||
|
|
||||||
topic.reload
|
topic.reload
|
||||||
|
@ -566,7 +566,7 @@ describe PostAction do
|
||||||
topic = action.reload.related_post.topic
|
topic = action.reload.related_post.topic
|
||||||
expect(user.notifications.count).to eq(0)
|
expect(user.notifications.count).to eq(0)
|
||||||
|
|
||||||
SiteSetting.expects(:auto_respond_to_flag_actions).returns(true)
|
SiteSetting.auto_respond_to_flag_actions = true
|
||||||
PostAction.agree_flags!(post, admin)
|
PostAction.agree_flags!(post, admin)
|
||||||
|
|
||||||
user_notifications = user.notifications
|
user_notifications = user.notifications
|
||||||
|
|
|
@ -3,7 +3,7 @@ module IntegrationHelpers
|
||||||
password = 'somecomplicatedpassword'
|
password = 'somecomplicatedpassword'
|
||||||
user.update!(password: password)
|
user.update!(password: password)
|
||||||
Fabricate(:email_token, confirmed: true, user: user)
|
Fabricate(:email_token, confirmed: true, user: user)
|
||||||
post "/session.json", login: user.username, password: password
|
xhr :post, "/session.json", login: user.username, password: password
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue