mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
new hidden 'allow_staged_accounts' setting
This commit is contained in:
parent
09bfe49254
commit
0d54c18c8b
11 changed files with 94 additions and 159 deletions
|
@ -23,7 +23,7 @@ module Jobs
|
|||
return if @user.staged && args[:type] == :digest
|
||||
|
||||
seen_recently = (@user.last_seen_at.present? && @user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago)
|
||||
seen_recently = false if @user.email_always
|
||||
seen_recently = false if @user.email_always || @user.staged
|
||||
|
||||
email_args = {}
|
||||
|
||||
|
|
|
@ -293,7 +293,7 @@ class UserNotifications < ActionMailer::Base
|
|||
topic_id: post.topic_id,
|
||||
context: context,
|
||||
username: username,
|
||||
add_unsubscribe_link: true,
|
||||
add_unsubscribe_link: !user.staged,
|
||||
unsubscribe_url: post.topic.unsubscribe_url,
|
||||
allow_reply_by_email: allow_reply_by_email,
|
||||
use_site_subject: use_site_subject,
|
||||
|
|
|
@ -39,7 +39,7 @@ class UserEmailObserver < ActiveRecord::Observer
|
|||
private
|
||||
|
||||
def enqueue(type)
|
||||
return unless (notification.user.email_direct? && notification.user.active?)
|
||||
return unless notification.user.email_direct? && (notification.user.active? || notification.user.staged?)
|
||||
|
||||
Jobs.enqueue_in(delay,
|
||||
:user_email,
|
||||
|
@ -49,7 +49,7 @@ class UserEmailObserver < ActiveRecord::Observer
|
|||
end
|
||||
|
||||
def enqueue_private(type)
|
||||
return unless (notification.user.email_private_messages? && notification.user.active?)
|
||||
return unless notification.user.email_private_messages? && (notification.user.active? || notification.user.staged?)
|
||||
|
||||
Jobs.enqueue_in(delay,
|
||||
:user_email,
|
||||
|
|
|
@ -224,10 +224,11 @@ class PostAlerter
|
|||
exclude_user_ids << reply_to_user.id if reply_to_user.present?
|
||||
exclude_user_ids.flatten!
|
||||
|
||||
TopicUser
|
||||
.where(topic_id: post.topic_id, notification_level: TopicUser.notification_levels[:watching])
|
||||
TopicUser.where(topic_id: post.topic_id)
|
||||
.where(notification_level: TopicUser.notification_levels[:watching])
|
||||
.where("user_id NOT IN (?)", exclude_user_ids)
|
||||
.includes(:user).each do |tu|
|
||||
create_notification(tu.user, Notification.types[:posted], post) unless exclude_user_ids.include?(tu.user_id)
|
||||
create_notification(tu.user, Notification.types[:posted], post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -792,6 +792,9 @@ developer:
|
|||
default: 500
|
||||
client: true
|
||||
hidden: true
|
||||
allow_staged_accounts:
|
||||
default: false
|
||||
hidden: true
|
||||
|
||||
embedding:
|
||||
feed_polling_enabled:
|
||||
|
|
|
@ -59,13 +59,17 @@ module Email
|
|||
return unless html_override = @opts[:html_override]
|
||||
|
||||
if @opts[:add_unsubscribe_link]
|
||||
unsubscribe_link = PrettyText.cook(I18n.t('unsubscribe_link', template_args)).html_safe
|
||||
html_override.gsub!("%{unsubscribe_link}", unsubscribe_link)
|
||||
else
|
||||
html_override.gsub!("%{unsubscribe_link}", "")
|
||||
end
|
||||
|
||||
if response_instructions = @template_args[:respond_instructions]
|
||||
respond_instructions = PrettyText.cook(response_instructions).html_safe
|
||||
html_override.gsub!("%{respond_instructions}", respond_instructions)
|
||||
end
|
||||
|
||||
unsubscribe_link = PrettyText.cook(I18n.t('unsubscribe_link', template_args)).html_safe
|
||||
html_override.gsub!("%{unsubscribe_link}", unsubscribe_link)
|
||||
else
|
||||
html_override.gsub!("%{respond_instructions}", "")
|
||||
end
|
||||
|
||||
styled = Email::Styles.new(html_override, @opts)
|
||||
|
|
|
@ -58,13 +58,18 @@ module Email
|
|||
|
||||
user_email = @message.from.first
|
||||
@user = User.find_by_email(user_email)
|
||||
if @user.blank? && @allow_strangers
|
||||
|
||||
wrap_body_in_quote user_email
|
||||
# TODO This is WRONG it should register an account
|
||||
# and email the user details on how to log in / activate
|
||||
# create staged account when user doesn't exist
|
||||
if @user.blank? && @allow_strangers
|
||||
if SiteSetting.allow_staged_accounts
|
||||
username = UserNameSuggester.suggest(user_email)
|
||||
name = User.suggest_name(user_email)
|
||||
@user = User.create(email: user_email, username: username, name: name, staged: true)
|
||||
else
|
||||
wrap_body_in_quote(user_email)
|
||||
@user = Discourse.system_user
|
||||
end
|
||||
end
|
||||
|
||||
raise UserNotFoundError if @user.blank?
|
||||
raise UserNotSufficientTrustLevelError.new @user unless @allow_strangers || @user.has_trust_level?(TrustLevel[SiteSetting.email_in_min_trust.to_i])
|
||||
|
@ -196,14 +201,12 @@ module Email
|
|||
lines[range_start..range_end].join.strip
|
||||
end
|
||||
|
||||
def wrap_body_in_quote(user_email)
|
||||
@body = "[quote=\"#{user_email}\"]
|
||||
#{@body}
|
||||
[/quote]"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wrap_body_in_quote(user_email)
|
||||
@body = "[quote=\"#{user_email}\"]\n#{@body}\n[/quote]"
|
||||
end
|
||||
|
||||
def create_reply
|
||||
create_post_with_attachments(@email_log.user,
|
||||
raw: @body,
|
||||
|
|
|
@ -69,7 +69,7 @@ class NewPostManager
|
|||
def self.user_needs_approval?(manager)
|
||||
user = manager.user
|
||||
|
||||
return false if user.staff?
|
||||
return false if user.staff? || user.staged
|
||||
|
||||
(user.post_count < SiteSetting.approve_post_count) ||
|
||||
(user.trust_level < SiteSetting.approve_unless_trust_level.to_i) ||
|
||||
|
@ -105,7 +105,6 @@ class NewPostManager
|
|||
end
|
||||
|
||||
def perform
|
||||
|
||||
# We never queue private messages
|
||||
return perform_create_post if @args[:archetype] == Archetype.private_message
|
||||
if args[:topic_id] && Topic.where(id: args[:topic_id], archetype: Archetype.private_message).exists?
|
||||
|
@ -145,7 +144,6 @@ class NewPostManager
|
|||
|
||||
def perform_create_post
|
||||
result = NewPostResult.new(:create_post)
|
||||
|
||||
creator = PostCreator.new(@user, @args)
|
||||
post = creator.create
|
||||
result.check_errors_from(creator)
|
||||
|
|
|
@ -7,8 +7,8 @@ class PostJobsEnqueuer
|
|||
end
|
||||
|
||||
def enqueue_jobs
|
||||
# We need to enqueue jobs after the transaction. Otherwise they might begin before the data has
|
||||
# been comitted.
|
||||
# We need to enqueue jobs after the transaction.
|
||||
# Otherwise they might begin before the data has been comitted.
|
||||
enqueue_post_alerts unless @opts[:import_mode]
|
||||
feature_topic_users unless @opts[:import_mode]
|
||||
trigger_post_post_process
|
||||
|
|
|
@ -604,7 +604,6 @@ greatest show ever created. Everyone should watch it.
|
|||
SiteSetting.email_in = true
|
||||
end
|
||||
|
||||
|
||||
it "rejects anon email" do
|
||||
Fabricate(:category, email_in_allow_strangers: false, email_in: "bob@bob.com")
|
||||
expect { process_email(from: "test@test.com", to: "bob@bob.com") }.to raise_error(Email::Receiver::UserNotFoundError)
|
||||
|
|
|
@ -3,184 +3,111 @@ require 'spec_helper'
|
|||
describe UserEmailObserver do
|
||||
|
||||
# something is off with fabricator
|
||||
def create_notification(type=nil, user=nil)
|
||||
def create_notification(type, user=nil)
|
||||
user ||= Fabricate(:user)
|
||||
type ||= Notification.types[:mentioned]
|
||||
Notification.create(data: '', user: user, notification_type: type)
|
||||
end
|
||||
|
||||
context 'user_mentioned' do
|
||||
let!(:notification) do
|
||||
create_notification
|
||||
end
|
||||
shared_examples "enqueue" do
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_mentioned, user_id: notification.user_id, notification_id: notification.id)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: type, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
context "inactive user" do
|
||||
|
||||
before { notification.user.active = false }
|
||||
|
||||
it "doesn't enqueue a job" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "enqueues a job if the user is staged" do
|
||||
notification.user.staged = true
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: type, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
shared_examples "enqueue_public" do
|
||||
include_examples "enqueue"
|
||||
|
||||
it "doesn't enqueue a job if the user has mention emails disabled" do
|
||||
notification.user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "enqueue_private" do
|
||||
include_examples "enqueue"
|
||||
|
||||
it "doesn't enqueue a job if the user has private message emails disabled" do
|
||||
notification.user.expects(:email_private_messages?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
end
|
||||
|
||||
context 'user_mentioned' do
|
||||
let(:type) { :user_mentioned }
|
||||
let!(:notification) { create_notification(1) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
|
||||
it "enqueue a delayed job for users that are online" do
|
||||
notification.user.last_seen_at = 1.minute.ago
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_mentioned, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has mention emails disabled" do
|
||||
notification.user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_mentioned)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user account is deactivated" do
|
||||
notification.user.active = false
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_mentioned)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'posted' do
|
||||
|
||||
let!(:notification) { create_notification(9) }
|
||||
let(:user) { notification.user }
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_posted, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has mention emails disabled" do
|
||||
user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_posted)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user account is deactivated" do
|
||||
user.active = false
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_posted)).never
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: type, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'user_replied' do
|
||||
|
||||
let(:type) { :user_replied }
|
||||
let!(:notification) { create_notification(2) }
|
||||
let(:user) { notification.user }
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_replied, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has mention emails disabled" do
|
||||
user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_replied)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user account is deactivated" do
|
||||
user.active = false
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_replied)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'user_quoted' do
|
||||
|
||||
let(:type) { :user_quoted }
|
||||
let!(:notification) { create_notification(3) }
|
||||
let(:user) { notification.user }
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_quoted, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has mention emails disabled" do
|
||||
user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_quoted)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
context 'user_posted' do
|
||||
let(:type) { :user_posted }
|
||||
let!(:notification) { create_notification(9) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user account is deactivated" do
|
||||
user.active = false
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_quoted)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'email_user_invited_to_private_message' do
|
||||
|
||||
let!(:notification) { create_notification(7) }
|
||||
let(:user) { notification.user }
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_invited_to_private_message, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has mention emails disabled" do
|
||||
user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_private_message)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user account is deactivated" do
|
||||
user.active = false
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_private_message)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'private_message' do
|
||||
|
||||
context 'user_private_message' do
|
||||
let(:type) { :user_private_message }
|
||||
let!(:notification) { create_notification(6) }
|
||||
let(:user) { notification.user }
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_private_message, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
include_examples "enqueue_private"
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has private message emails disabled" do
|
||||
user.expects(:email_private_messages?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_private_message)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user account is deactivated" do
|
||||
user.active = false
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_private_message)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
context 'user_invited_to_private_message' do
|
||||
let(:type) { :user_invited_to_private_message }
|
||||
let!(:notification) { create_notification(7) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'user_invited_to_topic' do
|
||||
|
||||
let(:type) { :user_invited_to_topic }
|
||||
let!(:notification) { create_notification(13) }
|
||||
let(:user) { notification.user }
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_invited_to_topic, user_id: notification.user_id, notification_id: notification.id)
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user has mention emails disabled" do
|
||||
user.expects(:email_direct?).returns(false)
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_topic)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email if the user account is deactivated" do
|
||||
user.active = false
|
||||
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_topic)).never
|
||||
UserEmailObserver.send(:new).after_commit(notification)
|
||||
end
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue