mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-25 05:23:36 -04:00
FIX: staged users couldn't create new topic in a private category via email
This commit is contained in:
parent
1b9b68cb51
commit
5415b2666d
5 changed files with 17 additions and 27 deletions
lib/email
spec
components/email
fixtures/emails
|
@ -78,7 +78,7 @@ module Email
|
|||
raise StrangersNotAllowedError if user.staged? && !category.email_in_allow_strangers
|
||||
raise InsufficientTrustLevelError if !user.has_trust_level?(SiteSetting.email_in_min_trust)
|
||||
|
||||
create_topic(user: user, raw: body, title: subject, category: category.id)
|
||||
create_topic(user: user, raw: body, title: subject, category: category.id, skip_validations: user.staged?)
|
||||
when :reply
|
||||
email_log = destination[:obj]
|
||||
|
||||
|
|
|
@ -273,31 +273,32 @@ describe Email::Receiver do
|
|||
let!(:category) { Fabricate(:category, email_in: "category@bar.com", email_in_allow_strangers: false) }
|
||||
|
||||
it "raises a StrangersNotAllowedError when 'email_in_allow_strangers' is disabled" do
|
||||
expect { process(:stranger_not_allowed) }.to raise_error(Email::Receiver::StrangersNotAllowedError)
|
||||
expect { process(:new_user) }.to raise_error(Email::Receiver::StrangersNotAllowedError)
|
||||
end
|
||||
|
||||
it "raises an InsufficientTrustLevelError when user's trust level isn't enough" do
|
||||
Fabricate(:user, email: "existing@bar.com", trust_level: 3)
|
||||
SiteSetting.email_in_min_trust = 4
|
||||
Fabricate(:user, email: "insufficient@bar.com", trust_level: 3)
|
||||
expect { process(:insufficient_trust_level) }.to raise_error(Email::Receiver::InsufficientTrustLevelError)
|
||||
expect { process(:existing_user) }.to raise_error(Email::Receiver::InsufficientTrustLevelError)
|
||||
end
|
||||
|
||||
it "raises an InvalidAccess when the user is part of a readonly group" do
|
||||
user = Fabricate(:user, email: "readonly@bar.com", trust_level: SiteSetting.email_in_min_trust)
|
||||
it "works" do
|
||||
user = Fabricate(:user, email: "existing@bar.com", trust_level: SiteSetting.email_in_min_trust)
|
||||
group = Fabricate(:group)
|
||||
|
||||
group.add(user)
|
||||
group.save
|
||||
|
||||
category.set_permissions(group => :readonly)
|
||||
category.set_permissions(group => :create_post)
|
||||
category.save
|
||||
|
||||
expect { process(:readonly) }.to raise_error(Discourse::InvalidAccess)
|
||||
end
|
||||
# raises an InvalidAccess when the user doesn't have the privileges to create a topic
|
||||
expect { process(:existing_user) }.to raise_error(Discourse::InvalidAccess)
|
||||
|
||||
it "works" do
|
||||
Fabricate(:user, email: "sufficient@bar.com", trust_level: SiteSetting.email_in_min_trust)
|
||||
expect { process(:sufficient_trust_level) }.to change(Topic, :count)
|
||||
category.update_columns(email_in_allow_strangers: true)
|
||||
|
||||
# allows new user to create a topic
|
||||
expect { process(:new_user) }.to change(Topic, :count)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
Return-Path: <insufficient@bar.com>
|
||||
From: Foo Bar <insufficient@bar.com>
|
||||
Return-Path: <existing@bar.com>
|
||||
From: Foo Bar <existing@bar.com>
|
||||
To: category@bar.com
|
||||
Subject: This is a topic from a complete stranger
|
||||
Subject: This is a topic from an existing user
|
||||
Date: Fri, 15 Jan 2016 00:12:43 +0100
|
||||
Message-ID: <32@foo.bar.mail>
|
||||
Mime-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
Hey, this is a topic from a complete stranger ;)
|
||||
Hey, this is a topic from an existing user ;)
|
11
spec/fixtures/emails/sufficient_trust_level.eml
vendored
11
spec/fixtures/emails/sufficient_trust_level.eml
vendored
|
@ -1,11 +0,0 @@
|
|||
Return-Path: <sufficient@bar.com>
|
||||
From: Foo Bar <sufficient@bar.com>
|
||||
To: category@bar.com
|
||||
Subject: This is a topic from a know user
|
||||
Date: Fri, 15 Jan 2016 00:12:43 +0100
|
||||
Message-ID: <33@foo.bar.mail>
|
||||
Mime-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
Hey, this is a topic from a known user ;)
|
Loading…
Add table
Add a link
Reference in a new issue