OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
remove notification cleanup job
ulfertsf558fd1d698f
diff --git a/app/controllers/admin/settings/aggregation_settings_controller.rb b/app/controllers/admin/settings/aggregation_settings_controller.rbindex fb87cf4a01e..1584fb3ae78 100644--- a/app/controllers/admin/settings/aggregation_settings_controller.rb+++ b/app/controllers/admin/settings/aggregation_settings_controller.rb@@ -37,7 +37,7 @@ module Admin::Settingsenddef default_breadcrumb- t(:'menus.admin.aggregation_and_retention')+ t(:'menus.admin.aggregation')enddef show_local_breadcrumbdiff --git a/app/views/admin/settings/aggregation_settings/show.html.erb b/app/views/admin/settings/aggregation_settings/show.html.erbindex eb050cd5921..6b8b35adbc5 100644--- a/app/views/admin/settings/aggregation_settings/show.html.erb+++ b/app/views/admin/settings/aggregation_settings/show.html.erb@@ -27,9 +27,9 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<% html_title t(:label_administration), t(:'menus.admin.aggregation_and_retention') -%>+<% html_title t(:label_administration), t(:'menus.admin.aggregation') -%>-<%= toolbar title: t(:'menus.admin.aggregation_and_retention') %>+<%= toolbar title: t(:'menus.admin.aggregation') %><%= styled_form_tag(admin_settings_aggregation_path, method: :patch) do %><div class="form--field">@@ -47,12 +47,5 @@ See COPYRIGHT and LICENSE files for more details.</span></div>- <div class="form--field">- <%= setting_number_field :notification_retention_period_days, size: 6, min: 2, unit: t(:label_day_plural), container_class: '-xslim' %>- <span class="form--field-instructions">- <%= t(:'settings.notifications.retention_text') %>- </span>- </div>-<%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %><% end %>diff --git a/config/constants/settings/definitions.rb b/config/constants/settings/definitions.rbindex 5494ad26678..a6087267884 100644--- a/config/constants/settings/definitions.rb+++ b/config/constants/settings/definitions.rb@@ -606,9 +606,6 @@ Settings::Definition.define dodefault: nil,writable: false- add :notification_retention_period_days,- default: 30-add :notification_email_delay_minutes,default: 15diff --git a/config/initializers/cronjobs.rb b/config/initializers/cronjobs.rbindex c6d0332359e..6c8f88178b1 100644--- a/config/initializers/cronjobs.rb+++ b/config/initializers/cronjobs.rb@@ -9,7 +9,6 @@ OpenProject::Application.configure do |application|::PaperTrailAudits::CleanupJob,::Attachments::CleanupUncontaineredJob,::Notifications::ScheduleReminderMailsJob,- ::Notifications::CleanupJob,::Ldap::SynchronizationJobendenddiff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex b7871830561..61d2e36cf33 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -299,7 +299,7 @@ Redmine::MenuManager.map :admin_menu do |menu|menu.push :notification_settings,{ controller: '/admin/settings/aggregation_settings', action: :show },if: Proc.new { User.current.admin? },- caption: :'menus.admin.aggregation_and_retention',+ caption: :'menus.admin.aggregation',parent: :mail_and_notificationsmenu.push :mail_notifications,diff --git a/config/locales/en.yml b/config/locales/en.ymlindex ea0b567ca8a..c65bf00e0ed 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1424,7 +1424,7 @@ en:admin:mail_notification: "Email notifications"mails_and_notifications: "Emails and notification"- aggregation_and_retention: 'Aggregation and retention'+ aggregation: 'Aggregation'api_and_webhooks: "API and webhooks"quick_add:label: "Open quick add menu"@@ -2554,7 +2554,6 @@ en:setting_email_login: "Use email as login"setting_enabled_scm: "Enabled SCM"setting_enabled_projects_columns: "Visible in project list"- setting_notification_retention_period_days: "Notification retention period"setting_feeds_enabled: "Enable Feeds"setting_feeds_limit: "Feed content limit"setting_file_max_size_displayed: "Max size of text files displayed inline"@@ -2633,9 +2632,6 @@ en:Leave empty to allow any file type to be uploaded.Multiple values allowed (one line for each value).notifications:- retention_text: >- Set the number of days notification events for users (the source for in-app notifications)- will be kept in the system. Any events older than this time will be deleted.events_explanation: 'Governs for which event an email is sent out. Work packages are excluded from this list as the notifications for them can be configured specifically for every user.'delay_minutes_explanation: "Email sending can be delayed to allow users with configured in app notification to confirm the notification within the application before a mail is sent out. Users who read a notification within the application will not receive an email for the already read notification."display:diff --git a/app/workers/notifications/cleanup_job.rb b/db/migrate/20220804112533_remove_notification_cleanup_job.rbsimilarity index 70%rename from app/workers/notifications/cleanup_job.rbrename to db/migrate/20220804112533_remove_notification_cleanup_job.rbindex 0192e9bae16..744cbac8943 100644--- a/app/workers/notifications/cleanup_job.rb+++ b/db/migrate/20220804112533_remove_notification_cleanup_job.rb@@ -26,26 +26,16 @@# See COPYRIGHT and LICENSE files for more details.#++-module Notifications- class CleanupJob < ::Cron::CronJob- DEFAULT_RETENTION ||= 30+class RemoveNotificationCleanupJob < ActiveRecord::Migration[7.0]+ def up+ # Remove the cron job no longer desired.+ # The code itself is removed but keeping it in the database would lead to UninitializedConstant errors.+ Delayed::Job+ .where('handler LIKE ?', "%job_class: Notifications::CleanupJob%")+ .delete_all- # runs at 2:22 nightly- self.cron_expression = '22 2 * * *'-- def perform- Notification- .where('updated_at < ?', oldest_notification_retention_time)- .delete_all- end-- private-- def oldest_notification_retention_time- days_ago = Setting.notification_retention_period_days.to_i- days_ago = DEFAULT_RETENTION if days_ago <= 0-- Time.zone.today - days_ago.days- end+ Setting+ .where(name: 'notification_retention_period_days')+ .delete_allendenddiff --git a/spec/workers/notifications/cleanup_job_spec.rb b/spec/workers/notifications/cleanup_job_spec.rbdeleted file mode 100644index dd813b1b427..00000000000--- a/spec/workers/notifications/cleanup_job_spec.rb+++ /dev/null@@ -1,18 +0,0 @@-require 'rails_helper'--RSpec.describe Notifications::CleanupJob, type: :job do- let(:job) { described_class.new }-- describe 'with default period', with_settings: { notification_retention_period_days: 30 } do- let!(:old_notification) { create :notification }- let!(:new_notification) { create :notification }-- it 'removes any older event' do- old_notification.update_column(:updated_at, 31.days.ago)-- expect { job.perform }.to change { Notification.count }.from(2).to(1)-- expect { old_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)- end- end-end