Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redmine #2713: automatische Jobs: Rückmeldungen #47

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/jobs/archive_closed_issues_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform
private

def issues_to_be_archived(time)
Issue.where(iat[:status].eq('closed').and(iat[:archived_at].eq(nil)).and(iat[:updated_at].lt(time)))
Issue.where(iat[:status].in(Issue::CLOSED_STATUSES).and(iat[:archived_at].eq(nil)).and(iat[:updated_at].lt(time)))
end

def iat
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/delete_authors_after_deadline_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def remove_author(issue)
# rubocop:enable Rails/SkipsModelValidations

def deletion_conds(time)
iat[:archived_at].not_eq(nil).iat[:archived_at].lt(time)
iat[:archived_at].not_eq(nil).and(iat[:archived_at].lt(time))
end

def iat
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/inform_editorial_staff_on_issues_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def perform
find_issues(time, notification.level, notification.user.group_ids)
next if @issues.blank?
notification.update(notified_at: Time.current)
IssueMailer.inform_editorial_staff(to: notification.user_email, issues: @issues, days: @days).deliver_later
IssueMailer.inform_editorial_staff(to: notification.user_email, issues: @issues, days: @days).deliver_now
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/inform_on_delegated_issues_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def perform
time = Time.current
iss = delegated_issues(time - JobSettings::Issue.delegation_deadline.hours)
iss.group_by(&:delegation).each do |delegation, issues|
IssueMailer.delegation(to: delegation.users.pluck(:email), issues: issues).deliver_later
IssueMailer.delegation(to: delegation.users.pluck(:email), issues: issues).deliver_now
end
end

Expand Down
6 changes: 4 additions & 2 deletions app/jobs/notify_on_closed_issues_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ class NotifyOnClosedIssuesJob < ApplicationJob

def perform
issues_with_status_changes(Time.current - JobSettings::Issue.status_change_days.days).find_each do |issue|
IssueMailer.closed(to: issue.author, issue: issue).deliver_later
IssueMailer.closed(to: issue.author, issue: issue).deliver_now
end
end

private

def issues_with_status_changes(time)
Issue.where(status: %w[closed not_solvable]).where(id: status_since_deadline(time, %w[closed not_solvable]))
Issue.where(status: %w[closed not_solvable duplicate]).where(
id: status_since_deadline(time, %w[closed not_solvable duplicate])
)
end
end
2 changes: 1 addition & 1 deletion app/jobs/notify_on_issues_in_process_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class NotifyOnIssuesInProcessJob < ApplicationJob

def perform
issues_with_status_changes(Time.current - JobSettings::Issue.status_change_days.days).find_each do |issue|
IssueMailer.in_process(to: issue.author, issue: issue).deliver_later
IssueMailer.in_process(to: issue.author, issue: issue).deliver_now
end
end

Expand Down
1 change: 1 addition & 0 deletions bin/deploy/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
0 37 * * * rails rails runner DeleteUnconfirmedSupportersJob.perform_now
0 42 * * * rails rails runner DeleteUnconfirmedAbusesJob.perform_now
0 47 * * * rails rails runner DeleteUnconfirmedPhotosJob.perform_now
0 52 * * * rails rails runner DeleteAuthorsAfterDeadlineJob.perform_now
0 40 00 * * rails rails runner ArchiveClosedIssuesJob.perform_now
0 40 01 * * rails rails runner InformEditorialStaffOnIssuesJob.perform_now
0 00 07 * * rails rails runner InformOnDelegatedIssuesJob.perform_now
Expand Down
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
config.active_storage.service = :test

config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: 'localhost', port: 3001 }

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
Expand Down
9 changes: 5 additions & 4 deletions test/jobs/inform_on_delegated_issues_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class InformOnDelegatedIssuesJobTest < ActiveJob::TestCase
include ActionMailer::TestHelper

test 'perform and mails get sent' do
assert_emails 0
assert_nothing_raised { InformOnDelegatedIssuesJob.perform_now }
assert_enqueued_email_with(
IssueMailer, :delegation,
args: [{ to: group(:external).users.pluck(:email), issues: Issue.where(id: issue(:delegated).id) }]
)
assert_emails 1
mail = ActionMailer::Base.deliveries.first
group(:external).users.pluck(:email).each { |email| assert_includes mail.to, email }
assert_equal 'Neue delegierte Vorgänge', mail.subject
end
end
6 changes: 5 additions & 1 deletion test/jobs/notify_on_closed_issues_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class NotifyOnClosedIssuesJobTest < ActiveJob::TestCase
include ActionMailer::TestHelper

test 'performable and mails get sent' do
assert_emails 0
assert_nothing_raised { NotifyOnClosedIssuesJob.perform_now }
assert_emails 1
issue = issue(:closed)
assert_enqueued_email_with(IssueMailer, :closed, args: [{ to: issue.author, issue: issue }])
mail = ActionMailer::Base.deliveries.first
assert_includes mail.to, issue.author
assert_equal "##{issue.id}: abgeschlossen", mail.subject
end
end
6 changes: 5 additions & 1 deletion test/jobs/notify_on_issues_in_process_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class NotifyOnIssuesInProcessJobTest < ActiveJob::TestCase
include ActionMailer::TestHelper

test 'performable and mails get sent' do
assert_emails 0
assert_nothing_raised { NotifyOnIssuesInProcessJob.perform_now }
assert_emails 1
issue = issue(:in_process)
assert_enqueued_email_with(IssueMailer, :in_process, args: [{ to: issue.author, issue: issue }])
mail = ActionMailer::Base.deliveries.first
assert_includes mail.to, issue.author
assert_equal "##{issue.id}: in Bearbeitung", mail.subject
end
end