Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Destroy view configurations without a project with their organisation

Guido Boykebc3ba01c27ce
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index ff289e8..19c84f0 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -103,6 +103,9 @@ class Organisation < ApplicationRecord
has_many :projects, dependent: :destroy
has_many :tickets, through: :projects
has_many :smart_folders, dependent: :destroy
+ # Project#view_configurations takes the rows of a project; this one takes the
+ # rows without a project (the base view of "Alle Meetings"). The FK is NO ACTION.
+ has_many :view_configurations, dependent: :destroy
has_many :ai_usages, dependent: :destroy
has_many :codebase_import_files, dependent: :destroy
has_many :tags, dependent: :destroy
diff --git a/spec/models/view_configuration_without_project_spec.rb b/spec/models/view_configuration_without_project_spec.rb
index 685b86e..71930d0 100644
--- a/spec/models/view_configuration_without_project_spec.rb
+++ b/spec/models/view_configuration_without_project_spec.rb
@@ -145,6 +145,26 @@ RSpec.describe ViewConfiguration, 'without a project' do
end
end
+ # Organisation deletion is Rails-driven and the organisation FK is NO ACTION.
+ # Project#view_configurations only reaches rows with a project; without
+ # Organisation#view_configurations the overview row would block the delete
+ # with InvalidForeignKey.
+ describe 'when the organisation is destroyed' do
+ it 'removes the row without a project and keeps the row of another organisation' do
+ overview_row = build_overview_config.tap(&:save!)
+ other_row = ActsAsTenant.with_tenant(other_organisation) do
+ build_overview_config(in_organisation: other_organisation).tap(&:save!)
+ end
+
+ organisation.destroy!
+
+ ActsAsTenant.without_tenant do
+ expect(described_class.exists?(overview_row.id)).to be(false)
+ expect(described_class.exists?(other_row.id)).to be(true)
+ end
+ end
+ end
+
describe '.for_list' do
it 'picks the row of the project when there is one, the organisation row otherwise' do
with_project = described_class.for_list(user: user, organisation: organisation, project: project, view_type: 'meetings')