mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
If an admin or moderator edits a visitor's post, the restrictions should be based
on the *editors* access rights, not the original poster.
This commit is contained in:
parent
ab85d4a757
commit
af9b27358c
5 changed files with 52 additions and 6 deletions
|
@ -123,8 +123,19 @@ class Post < ActiveRecord::Base
|
||||||
total
|
total
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Sometimes the post is being edited by someone else, for example, a mod.
|
||||||
|
# If that's the case, they should not be bound by the original poster's
|
||||||
|
# restrictions, for example on not posting images.
|
||||||
|
def acting_user
|
||||||
|
@acting_user || user
|
||||||
|
end
|
||||||
|
|
||||||
|
def acting_user=(pu)
|
||||||
|
@acting_user = pu
|
||||||
|
end
|
||||||
|
|
||||||
def max_mention_validator
|
def max_mention_validator
|
||||||
if user.present? && user.has_trust_level?(:basic)
|
if acting_user.present? && acting_user.has_trust_level?(:basic)
|
||||||
errors.add(:base, I18n.t(:too_many_mentions, count: SiteSetting.max_mentions_per_post)) if raw_mentions.size > SiteSetting.max_mentions_per_post
|
errors.add(:base, I18n.t(:too_many_mentions, count: SiteSetting.max_mentions_per_post)) if raw_mentions.size > SiteSetting.max_mentions_per_post
|
||||||
else
|
else
|
||||||
errors.add(:base, I18n.t(:too_many_mentions_visitor, count: SiteSetting.visitor_max_mentions_per_post)) if raw_mentions.size > SiteSetting.visitor_max_mentions_per_post
|
errors.add(:base, I18n.t(:too_many_mentions_visitor, count: SiteSetting.visitor_max_mentions_per_post)) if raw_mentions.size > SiteSetting.visitor_max_mentions_per_post
|
||||||
|
@ -132,12 +143,12 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_images_validator
|
def max_images_validator
|
||||||
return if user.present? && user.has_trust_level?(:basic)
|
return if acting_user.present? && acting_user.has_trust_level?(:basic)
|
||||||
errors.add(:base, I18n.t(:too_many_images, count: SiteSetting.visitor_max_images)) if image_count > SiteSetting.visitor_max_images
|
errors.add(:base, I18n.t(:too_many_images, count: SiteSetting.visitor_max_images)) if image_count > SiteSetting.visitor_max_images
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_links_validator
|
def max_links_validator
|
||||||
return if user.present? && user.has_trust_level?(:basic)
|
return if acting_user.present? && acting_user.has_trust_level?(:basic)
|
||||||
errors.add(:base, I18n.t(:too_many_links, count: SiteSetting.visitor_max_links)) if link_count > SiteSetting.visitor_max_links
|
errors.add(:base, I18n.t(:too_many_links, count: SiteSetting.visitor_max_links)) if link_count > SiteSetting.visitor_max_links
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ require_dependency 'site_content_class_methods'
|
||||||
class SiteContent < ActiveRecord::Base
|
class SiteContent < ActiveRecord::Base
|
||||||
extend SiteContentClassMethods
|
extend SiteContentClassMethods
|
||||||
|
|
||||||
set_primary_key :content_type
|
self.primary_key = 'content_type'
|
||||||
|
|
||||||
validates_presence_of :content
|
validates_presence_of :content
|
||||||
|
|
||||||
def self.formats
|
def self.formats
|
||||||
|
|
|
@ -10,6 +10,8 @@ class PostRevisor
|
||||||
def revise!(user, new_raw, opts = {})
|
def revise!(user, new_raw, opts = {})
|
||||||
@user, @new_raw, @opts = user, new_raw, opts
|
@user, @new_raw, @opts = user, new_raw, opts
|
||||||
return false if not should_revise?
|
return false if not should_revise?
|
||||||
|
|
||||||
|
@post.acting_user = @user
|
||||||
revise_post
|
revise_post
|
||||||
update_category_description
|
update_category_description
|
||||||
post_process_post
|
post_process_post
|
||||||
|
|
|
@ -4,10 +4,10 @@ require 'post_revisor'
|
||||||
describe PostRevisor do
|
describe PostRevisor do
|
||||||
|
|
||||||
let(:topic) { Fabricate(:topic) }
|
let(:topic) { Fabricate(:topic) }
|
||||||
let(:post_args) { {user: topic.user, topic: topic} }
|
let(:visitor) { Fabricate(:visitor) }
|
||||||
|
let(:post_args) { {user: visitor, topic: topic} }
|
||||||
|
|
||||||
context 'revise' do
|
context 'revise' do
|
||||||
|
|
||||||
let(:post) { Fabricate(:post, post_args) }
|
let(:post) { Fabricate(:post, post_args) }
|
||||||
let(:first_version_at) { post.last_version_at }
|
let(:first_version_at) { post.last_version_at }
|
||||||
|
|
||||||
|
@ -186,6 +186,32 @@ describe PostRevisor do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "admin editing a visitor's post" do
|
||||||
|
let(:changed_by) { Fabricate(:admin) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SiteSetting.stubs(:too_many_images).returns(0)
|
||||||
|
subject.revise!(changed_by, "So, post them here!\nhttp://i.imgur.com/FGg7Vzu.gif")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows an admin to insert images into a visitor's post" do
|
||||||
|
post.errors.should be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "visitor editing their own post" do
|
||||||
|
before do
|
||||||
|
SiteSetting.stubs(:too_many_images).returns(0)
|
||||||
|
subject.revise!(post.user, "So, post them here!\nhttp://i.imgur.com/FGg7Vzu.gif")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows an admin to insert images into a visitor's post" do
|
||||||
|
post.errors.should be_present
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'with a new body' do
|
describe 'with a new body' do
|
||||||
let(:changed_by) { Fabricate(:coding_horror) }
|
let(:changed_by) { Fabricate(:coding_horror) }
|
||||||
let!(:result) { subject.revise!(changed_by, 'updated body') }
|
let!(:result) { subject.revise!(changed_by, 'updated body') }
|
||||||
|
|
|
@ -49,3 +49,9 @@ Fabricator(:another_admin, from: :user) do
|
||||||
admin true
|
admin true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Fabricator(:visitor, from: :user) do
|
||||||
|
name 'Newbie Newperson'
|
||||||
|
username 'newbie'
|
||||||
|
email 'newbie@new.com'
|
||||||
|
trust_level TrustLevel.levels[:visitor]
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue