move job files so they live underneath app/ and not in lib/
introduce new setting email_always, that will force emails to send to users regardless of presence on site
This commit is contained in:
parent
420cd7aa2c
commit
f0a122a66c
|
@ -150,6 +150,7 @@ Discourse.User = Discourse.Model.extend({
|
|||
'name',
|
||||
'email_digests',
|
||||
'email_direct',
|
||||
'email_always',
|
||||
'email_private_messages',
|
||||
'dynamic_favicon',
|
||||
'digest_after_days',
|
||||
|
|
|
@ -80,6 +80,8 @@
|
|||
{{i18n user.email_private_messages}}</label>
|
||||
<label>{{view Ember.Checkbox checkedBinding="email_direct"}}
|
||||
{{i18n user.email_direct}}</label>
|
||||
<label>{{view Ember.Checkbox checkedBinding="email_always"}}
|
||||
{{i18n user.email_always}}</label>
|
||||
</div>
|
||||
<div class='instructions'>
|
||||
{{i18n user.email.frequency}}
|
||||
|
|
|
@ -57,7 +57,7 @@ class UsersController < ApplicationController
|
|||
u.new_topic_duration_minutes = params[:new_topic_duration_minutes].to_i if params[:new_topic_duration_minutes]
|
||||
u.title = params[:title] || u.title if guardian.can_grant_title?(u)
|
||||
|
||||
[:email_digests, :email_direct, :email_private_messages,
|
||||
[:email_digests, :email_always, :email_direct, :email_private_messages,
|
||||
:external_links_in_new_tab, :enable_quoting, :dynamic_favicon].each do |i|
|
||||
if params[i].present?
|
||||
u.send("#{i.to_s}=", params[i] == 'true')
|
||||
|
|
|
@ -215,4 +215,5 @@ module Jobs
|
|||
end
|
||||
|
||||
# Require all jobs
|
||||
Dir["#{Rails.root}/lib/jobs/*"].each {|file| require_dependency file }
|
||||
Dir["#{Rails.root}/app/jobs/regular/*.rb"].each {|file| require_dependency file }
|
||||
Dir["#{Rails.root}/app/jobs/scheduled/*.rb"].each {|file| require_dependency file }
|
|
@ -16,6 +16,7 @@ module Jobs
|
|||
return if !user || user.is_banned?
|
||||
|
||||
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
|
||||
|
||||
email_args = {}
|
||||
|
|
@ -15,7 +15,8 @@ module Jobs
|
|||
query = User.real
|
||||
.where(email_digests: true, active: true)
|
||||
.where("COALESCE(last_emailed_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)")
|
||||
.where("COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)")
|
||||
.where("(COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)) OR
|
||||
email_always")
|
||||
|
||||
# If the site requires approval, make sure the user is approved
|
||||
if SiteSetting.must_approve_users?
|
|
@ -1,4 +1,4 @@
|
|||
require_dependency 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
require_dependency 'pretty_text'
|
||||
require_dependency 'rate_limiter'
|
||||
require_dependency 'post_revisor'
|
||||
|
|
|
@ -47,6 +47,7 @@ class UserSerializer < BasicUserSerializer
|
|||
:email_digests,
|
||||
:email_private_messages,
|
||||
:email_direct,
|
||||
:email_always,
|
||||
:digest_after_days,
|
||||
:auto_track_topics_after_msecs,
|
||||
:new_topic_duration_minutes,
|
||||
|
|
|
@ -34,6 +34,7 @@ module Discourse
|
|||
# Custom directories with classes and modules you want to be autoloadable.
|
||||
config.autoload_paths += Dir["#{config.root}/app/serializers"]
|
||||
config.autoload_paths += Dir["#{config.root}/lib/validators/"]
|
||||
config.autoload_paths += Dir["#{config.root}/app"]
|
||||
|
||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||
# :all can be used as a placeholder for all plugins not explicitly named.
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
||||
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
||||
|
||||
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
||||
# Rails.backtrace_cleaner.remove_silencers!
|
|
@ -284,6 +284,7 @@ en:
|
|||
|
||||
email_direct: "Receive an email when someone quotes you, replies to your post, or mentions your @username"
|
||||
email_private_messages: "Receive an email when someone sends you a private message"
|
||||
email_always: "Receive email notifications and email digests even if I am active on the forum"
|
||||
|
||||
other_settings: "Other"
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddEmailAlwaysToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :email_always, :bool, default: false, null: false
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::CloseTopic do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::EnqueueDigestEmails do
|
||||
|
||||
|
@ -38,6 +38,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_emailed_recently.id).should be_false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "inactive user" do
|
||||
|
@ -48,16 +49,21 @@ describe Jobs::EnqueueDigestEmails do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
context 'visited the site today' do
|
||||
let!(:user_visited_today) { Fabricate(:active_user, last_seen_at: 6.days.ago) }
|
||||
context 'visited the site this week' do
|
||||
let(:user_visited_this_week) { Fabricate(:active_user, last_seen_at: 6.days.ago) }
|
||||
let(:user_visited_this_week_email_always) { Fabricate(:active_user, last_seen_at: 6.days.ago, email_always: true) }
|
||||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_visited_today.id).should be_false
|
||||
user = user_visited_this_week
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id).should be_false
|
||||
end
|
||||
|
||||
it "does return users who have been emailed recently but have email_always set" do
|
||||
user = user_visited_this_week_email_always
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'regular users' do
|
||||
let!(:user) { Fabricate(:active_user) }
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::Exporter do
|
||||
before do
|
|
@ -1,5 +1,6 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs/process_post'
|
||||
require_dependency 'jobs/base'
|
||||
require 'jobs/regular/process_post'
|
||||
|
||||
describe Jobs::FeatureTopicUsers do
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::Importer do
|
||||
def stub_schema_changes
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::InviteEmail do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::Base do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs do
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs/process_post'
|
||||
require_dependency 'jobs/base'
|
||||
require_dependency 'jobs/regular/process_post'
|
||||
|
||||
describe Jobs::NotifyMovedPosts do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs/periodical_updates'
|
||||
require_dependency 'jobs/scheduled/periodical_updates'
|
||||
|
||||
describe Jobs::PeriodicalUpdates do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs/process_post'
|
||||
require_dependency 'jobs/regular/process_post'
|
||||
|
||||
describe Jobs::PollMailbox do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs/process_post'
|
||||
require 'jobs/regular/process_post'
|
||||
|
||||
describe Jobs::ProcessPost do
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'jobs/send_system_message'
|
||||
require 'jobs/regular/send_system_message'
|
||||
|
||||
describe Jobs::SendSystemMessage do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::TestEmail do
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'jobs'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::UserEmail do
|
||||
|
||||
|
@ -43,7 +43,13 @@ describe Jobs::UserEmail do
|
|||
it "doesn't send an email to a user that's been recently seen" do
|
||||
user.update_column(:last_seen_at, 9.minutes.ago)
|
||||
Email::Sender.any_instance.expects(:send).never
|
||||
Jobs::UserEmail.new.execute(type: :private_message, user_id: user.id, post_id: post.id)
|
||||
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
|
||||
end
|
||||
|
||||
it "does send an email to a user that's been recently seen but has email_always set" do
|
||||
user.update_attributes(last_seen_at: 9.minutes.ago, email_always: true)
|
||||
Email::Sender.any_instance.expects(:send)
|
||||
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue