mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: blocked users can send and reply to private messages from staff
This commit is contained in:
parent
9569235d76
commit
685ba1eb7f
@ -10,6 +10,7 @@ export default Ember.Controller.extend({
|
|||||||
|
|
||||||
selected: Em.computed.alias('controllers.user-topics-list.selected'),
|
selected: Em.computed.alias('controllers.user-topics-list.selected'),
|
||||||
bulkSelectEnabled: Em.computed.alias('controllers.user-topics-list.bulkSelectEnabled'),
|
bulkSelectEnabled: Em.computed.alias('controllers.user-topics-list.bulkSelectEnabled'),
|
||||||
|
showNewPM: Em.computed.alias('controllers.user-topics-list.showNewPM'),
|
||||||
|
|
||||||
@computed('selected.@each', 'bulkSelectEnabled')
|
@computed('selected.@each', 'bulkSelectEnabled')
|
||||||
hasSelection(selected, bulkSelectEnabled){
|
hasSelection(selected, bulkSelectEnabled){
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<section class='user-navigation'>
|
<section class='user-navigation'>
|
||||||
{{#if viewingSelf}}
|
{{#if showNewPM}}
|
||||||
{{d-button class="btn-primary new-private-message" action="composePrivateMessage" icon="envelope" label="user.new_private_message"}}
|
{{d-button class="btn-primary new-private-message" action="composePrivateMessage" icon="envelope" label="user.new_private_message"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<ul class='action-list nav-stacked'>
|
<ul class='action-list nav-stacked'>
|
||||||
|
@ -96,14 +96,6 @@ class PostsController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
||||||
if !is_api? && current_user.blocked?
|
|
||||||
|
|
||||||
# error has parity with what user would get if they posted when blocked
|
|
||||||
# and it went through post creator
|
|
||||||
render json: {errors: [I18n.t("topic_not_found")]}, status: 422
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
@manager_params = create_params
|
@manager_params = create_params
|
||||||
@manager_params[:first_post_checks] = !is_api?
|
@manager_params[:first_post_checks] = !is_api?
|
||||||
|
|
||||||
|
@ -256,7 +256,9 @@ class Guardian
|
|||||||
@user.username == SiteSetting.site_contact_username ||
|
@user.username == SiteSetting.site_contact_username ||
|
||||||
@user == Discourse.system_user) &&
|
@user == Discourse.system_user) &&
|
||||||
# Can't send PMs to suspended users
|
# Can't send PMs to suspended users
|
||||||
(is_staff? || target.is_a?(Group) || !target.suspended?)
|
(is_staff? || target.is_a?(Group) || !target.suspended?) &&
|
||||||
|
# Blocked users can only send PM to staff
|
||||||
|
(!@user.blocked? || target.staff?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_see_emails?
|
def can_see_emails?
|
||||||
|
@ -73,7 +73,7 @@ module PostGuardian
|
|||||||
|
|
||||||
# Creating Method
|
# Creating Method
|
||||||
def can_create_post?(parent)
|
def can_create_post?(parent)
|
||||||
!SpamRule::AutoBlock.block?(@user) && (
|
(!SpamRule::AutoBlock.block?(@user) || (!!parent.try(:private_message?) && parent.allowed_users.include?(@user))) && (
|
||||||
!parent ||
|
!parent ||
|
||||||
!parent.category ||
|
!parent.category ||
|
||||||
Category.post_create_allowed(self).where(:id => parent.category.id).count == 1
|
Category.post_create_allowed(self).where(:id => parent.category.id).count == 1
|
||||||
|
@ -187,6 +187,22 @@ describe Guardian do
|
|||||||
expect(Guardian.new(user).can_send_private_message?(suspended_user)).to be_falsey
|
expect(Guardian.new(user).can_send_private_message?(suspended_user)).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "author is blocked" do
|
||||||
|
before do
|
||||||
|
user.blocked = true
|
||||||
|
user.save
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns true if target is staff" do
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(admin)).to be_truthy
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(moderator)).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if target is not staff" do
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(another_user)).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'can_reply_as_new_topic' do
|
describe 'can_reply_as_new_topic' do
|
||||||
@ -661,11 +677,34 @@ describe Guardian do
|
|||||||
it "doesn't allow new posts from admins" do
|
it "doesn't allow new posts from admins" do
|
||||||
expect(Guardian.new(admin).can_create?(Post, topic)).to be_falsey
|
expect(Guardian.new(admin).can_create?(Post, topic)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "private message" do
|
||||||
|
let(:private_message) { Fabricate(:topic, archetype: Archetype.private_message, category_id: nil) }
|
||||||
|
|
||||||
end
|
before { user.save! }
|
||||||
|
|
||||||
|
it "allows new posts by people included in the pm" do
|
||||||
|
private_message.topic_allowed_users.create!(user_id: user.id)
|
||||||
|
expect(Guardian.new(user).can_create?(Post, private_message)).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't allow new posts by people not invited to the pm" do
|
||||||
|
expect(Guardian.new(user).can_create?(Post, private_message)).to be_falsey
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows new posts from blocked users included in the pm" do
|
||||||
|
user.update_attribute(:blocked, true)
|
||||||
|
private_message.topic_allowed_users.create!(user_id: user.id)
|
||||||
|
expect(Guardian.new(user).can_create?(Post, private_message)).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't allow new posts from blocked users not invited to the pm" do
|
||||||
|
user.update_attribute(:blocked, true)
|
||||||
|
expect(Guardian.new(user).can_create?(Post, private_message)).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end # can_create? a Post
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user