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
Clean out any anonymous user created reminder notifications
Kabiru Mwenjaf1bdb856d5c0
diff --git a/app/models/reminder_notification.rb b/app/models/reminder_notification.rbindex cbdd70905a9..3e18cee0474 100644--- a/app/models/reminder_notification.rb+++ b/app/models/reminder_notification.rb@@ -1,4 +1,4 @@class ReminderNotification < ApplicationRecordbelongs_to :reminder- belongs_to :notification+ belongs_to :notification, dependent: :destroyenddiff --git a/db/migrate/20250108100511_remove_incorrect_manage_own_reminders_permission.rb b/db/migrate/20250108100511_remove_incorrect_manage_own_reminders_permission.rbindex fff0b4b0cc5..02ac3e39c7c 100644--- a/db/migrate/20250108100511_remove_incorrect_manage_own_reminders_permission.rb+++ b/db/migrate/20250108100511_remove_incorrect_manage_own_reminders_permission.rb@@ -1,10 +1,14 @@class RemoveIncorrectManageOwnRemindersPermission < ActiveRecord::Migration[7.1]def up+ # Remove manage_own_reminders permission from non member and anonymous rolesRolePermission.where(role: Role.where(builtin: [Role::BUILTIN_NON_MEMBER, Role::BUILTIN_ANONYMOUS]),permission: :manage_own_reminders).destroy_all++ # Remove all reminders created by anonymous user+ Reminder.where(creator_id: AnonymousUser.first.id).destroy_allend# No-opdiff --git a/spec/migrations/remove_incorrect_manage_own_reminders_permission_spec.rb b/spec/migrations/remove_incorrect_manage_own_reminders_permission_spec.rbindex 7f5a0422817..7b9dfa87b81 100644--- a/spec/migrations/remove_incorrect_manage_own_reminders_permission_spec.rb+++ b/spec/migrations/remove_incorrect_manage_own_reminders_permission_spec.rb@@ -35,21 +35,35 @@ RSpec.describe RemoveIncorrectManageOwnRemindersPermission, type: :model dolet(:anonymous) { create(:anonymous_role, permissions:) }let(:other_role) { create(:work_package_role, permissions:) }- before do- non_member- anonymous- other_role+ let(:anonymous_user_reminder) do+ create(:reminder, :with_unread_notifications, creator: AnonymousUser.first)end+ let(:normal_user_reminder) { create(:reminder, :with_unread_notifications) }+it "removes the `manage_own_reminders` permission from non member and anonymous roles" doexpect(non_member.permissions).to include(:manage_own_reminders)expect(anonymous.permissions).to include(:manage_own_reminders)expect(other_role.permissions).to include(:manage_own_reminders)- ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) }+ expect(anonymous_user_reminder).to be_persisted+ expect(normal_user_reminder.creator).to be_persisted++ expect do+ ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) }+ end.to(+ change(RolePermission, :count).by(-2) &+ change(Reminder, :count).by(-1) &+ change(ReminderNotification, :count).by(-1) &+ change(Notification, :count).by(-1)+ )expect(non_member.reload.permissions).not_to include(:manage_own_reminders)expect(anonymous.reload.permissions).not_to include(:manage_own_reminders)expect(other_role.reload.permissions).to include(:manage_own_reminders)++ reminder_creators = Reminder.pluck(:creator_id)+ expect(reminder_creators).not_to include(AnonymousUser.first.id)+ expect(reminder_creators).to include(normal_user_reminder.creator_id)endenddiff --git a/spec/models/reminder_notification_spec.rb b/spec/models/reminder_notification_spec.rbindex 95c8193813c..d079c49aae0 100644--- a/spec/models/reminder_notification_spec.rb+++ b/spec/models/reminder_notification_spec.rb@@ -31,6 +31,6 @@ require "spec_helper"RSpec.describe ReminderNotification dodescribe "Associations" doit { is_expected.to belong_to(:reminder) }- it { is_expected.to belong_to(:notification) }+ it { is_expected.to belong_to(:notification).dependent(:destroy) }endend