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.

Let a meetings view configuration go without a project

Guido Boykeea5afc49ac48
diff --git a/app/models/view_configuration.rb b/app/models/view_configuration.rb
index 4a1ac32..b357170 100644
--- a/app/models/view_configuration.rb
+++ b/app/models/view_configuration.rb
@@ -3,6 +3,12 @@
# Stores user-specific view configurations for tables and lists. The column
# list of the base view lives here (doc/spaltenwahl_plan.md); a saved view
# carries its own in SmartFolder#display_columns.
+#
+# A row belongs to one project, or to none: the base view of "Alle Meetings"
+# (meetings_uebersicht_vereinheitlichen_plan.md, PR 2) is the one list without a
+# project, so only view_type 'meetings' may go without one. project: nil means
+# "organisation-wide" everywhere in this class; tickets, notes and documents
+# always pass a project.
# == Schema Information
#
# Table name: view_configurations
@@ -19,18 +25,19 @@
# updated_at :datetime not null
# kanban_attribute_definition_id :uuid
# organisation_id :uuid not null
-# project_id :uuid not null
+# project_id :uuid
# user_id :uuid not null
#
# Indexes
#
-# index_view_configs_on_user_project_type (user_id,project_id,view_type) UNIQUE
-# index_view_configurations_on_header_columns (header_columns) USING gin
-# index_view_configurations_on_list_columns (list_columns) USING gin
-# index_view_configurations_on_organisation_id (organisation_id)
-# index_view_configurations_on_project_id (project_id)
-# index_view_configurations_on_table_columns (table_columns) USING gin
-# index_view_configurations_on_user_id (user_id)
+# index_view_configs_on_user_organisation_type_without_project (user_id,organisation_id,view_type) UNIQUE WHERE (project_id IS NULL)
+# index_view_configs_on_user_project_type (user_id,project_id,view_type) UNIQUE
+# index_view_configurations_on_header_columns (header_columns) USING gin
+# index_view_configurations_on_list_columns (list_columns) USING gin
+# index_view_configurations_on_organisation_id (organisation_id)
+# index_view_configurations_on_project_id (project_id)
+# index_view_configurations_on_table_columns (table_columns) USING gin
+# index_view_configurations_on_user_id (user_id)
#
# Foreign Keys
#
@@ -43,7 +50,7 @@ class ViewConfiguration < ApplicationRecord
acts_as_tenant :organisation
belongs_to :user
- belongs_to :project
+ belongs_to :project, optional: true
belongs_to :kanban_attribute_definition, class_name: 'TicketAttributeDefinition', optional: true
# View modes for ticket views
@@ -82,7 +89,8 @@ class ViewConfiguration < ApplicationRecord
COLUMN_MIN_WIDTH_PX = {
'number' => 48, 'title' => 320, 'assignees' => 120, 'tags' => 140,
'created_at' => 110, 'updated_at' => 110, 'time_spent' => 90, 'billing_status' => 140, 'subtask_count' => 70,
- 'waiting' => 70, 'custom_status' => 138, 'participants' => 220, 'occurred_at' => 170, 'duration_minutes' => 90
+ 'waiting' => 70, 'custom_status' => 138, 'participants' => 220, 'occurred_at' => 170, 'duration_minutes' => 90,
+ 'project' => 140
}.freeze
COLUMN_MIN_WIDTH_BY_TYPE_PX = {
'select' => 110, 'multiselect' => 140, 'text' => 140, 'textarea' => 160, 'checkbox' => 70,
@@ -132,7 +140,17 @@ class ViewConfiguration < ApplicationRecord
}.freeze
validates :view_type, presence: true, inclusion: { in: %w[tickets notes documents meetings] }
- validates :user_id, uniqueness: { scope: %i[project_id view_type] }
+ # The list types that have a page without a project.
+ ORGANISATION_WIDE_VIEW_TYPES = %w[meetings].freeze
+
+ validates :user_id, uniqueness: { scope: %i[project_id view_type] }, if: :project_id?
+ # Without a project the organisation is the scope: the validator reads past
+ # the tenant scope, so (project_id, view_type) alone would let a user have
+ # one overview row across all their organisations. The database holds the
+ # same rule in a partial unique index (NULLs are distinct in the other one).
+ validates :user_id, uniqueness: { scope: %i[organisation_id view_type], conditions: -> { where(project_id: nil) } },
+ unless: :project_id?
+ validates :project, presence: true, unless: -> { ORGANISATION_WIDE_VIEW_TYPES.include?(view_type) }
validates :view_mode, inclusion: { in: VIEW_MODES }, allow_nil: true
validate :kanban_attribute_definition_of_own_project
@@ -204,8 +222,14 @@ class ViewConfiguration < ApplicationRecord
# status attribute when it has one, who works on it, when it was created.
# Status is found the way the kanban board finds it, not by name: a
# project's status column is `custom_<name>`, whatever the name.
+ #
+ # Meetings: the project page shows title, date, duration and participants;
+ # "Alle Meetings" (no project) names each row's project after the title, the
+ # list that page showed before it had a column picker.
def self.default_columns_for(project, view_type = 'tickets')
- return %w[title occurred_at duration_minutes participants] if view_type == 'meetings'
+ if view_type == 'meetings'
+ return project ? %w[title occurred_at duration_minutes participants] : %w[title project occurred_at duration_minutes participants]
+ end
status = status_attribute_for(project)
columns = DEFAULT_REQUIRED_COLUMNS.dup
@@ -248,16 +272,30 @@ class ViewConfiguration < ApplicationRecord
# Get configuration for a user/project/view combination
def self.for_user_project(user, project, view_type = 'tickets')
- find_or_initialize_by(
- user: user,
- project: project,
- view_type: view_type
- ) do |config|
- config.table_columns = default_columns_for(project, view_type)
- config.pinned_columns = %w[participants] if view_type == 'meetings'
+ find_or_initialize_with_defaults(user: user, project: project, view_type: view_type)
+ end
+
+ # The row without a project: the base view of a list of the whole
+ # organisation ("Alle Meetings"). Only ORGANISATION_WIDE_VIEW_TYPES save.
+ def self.for_user_organisation(user, organisation, view_type)
+ find_or_initialize_with_defaults(user: user, organisation: organisation, project: nil, view_type: view_type)
+ end
+
+ # The base view of the list a caller stands on: its project's row, or the
+ # organisation's row when the list has no project. Every write path of the
+ # column picker asks this, so the choice is made once.
+ def self.for_list(user:, organisation:, project:, view_type:)
+ project ? for_user_project(user, project, view_type) : for_user_organisation(user, organisation, view_type)
+ end
+
+ def self.find_or_initialize_with_defaults(**attributes)
+ find_or_initialize_by(**attributes) do |config|
+ config.table_columns = default_columns_for(attributes[:project], attributes[:view_type])
+ config.pinned_columns = %w[participants] if attributes[:view_type] == 'meetings'
config.header_columns = DEFAULT_HEADER_COLUMNS
end
end
+ private_class_method :find_or_initialize_with_defaults
# Get all available columns for configuration (instance method)
#
@@ -283,6 +321,9 @@ class ViewConfiguration < ApplicationRecord
else []
end
+ # Every row of a list without a project names its own (meetings only).
+ base += [meeting_project_column] if view_type == 'meetings' && project.nil?
+
base += time_columns if view_type == 'tickets' && time_columns_visible_for?(project, user)
append_custom_columns(base, project, view_type)
@@ -344,6 +385,8 @@ class ViewConfiguration < ApplicationRecord
# All select attributes that are suitable as a Kanban column
def kanban_eligible_attributes
+ return TicketAttributeDefinition.none if project.nil?
+
project.ticket_attribute_definitions.active.ordered
.where(field_type: %w[select])
end
@@ -369,7 +412,7 @@ class ViewConfiguration < ApplicationRecord
# Appends custom attribute columns to base when view_type == 'tickets'
def self.append_custom_columns(base, project, view_type)
- if view_type == 'tickets' && project.ticket_attribute_definitions.any?
+ if view_type == 'tickets' && project&.ticket_attribute_definitions&.any?
custom = project.ticket_attribute_definitions.active.ordered.map do |attr|
{ key: "custom_#{attr.name}", label: attr.label_for, type: attr.field_type, custom: true }
end
@@ -411,6 +454,11 @@ class ViewConfiguration < ApplicationRecord
].map { |column| column.merge(label: I18n.t("models.view_configuration.meeting_columns.#{column[:key]}")) }
end
+ # Offered only on a meetings list without a project (available_columns_for).
+ def self.meeting_project_column
+ { key: 'project', label: I18n.t('models.view_configuration.meeting_columns.project'), type: 'project' }
+ end
+
def self.note_base_columns
[
{ key: 'title', label: I18n.t('models.view_configuration.columns.title'), type: 'text', required: true },
diff --git a/db/migrate/20261017120000_allow_view_configurations_without_project.rb b/db/migrate/20261017120000_allow_view_configurations_without_project.rb
new file mode 100644
index 0000000..67c5b4d
--- /dev/null
+++ b/db/migrate/20261017120000_allow_view_configurations_without_project.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+# The base view of "Alle Meetings" has no project: a view configuration with
+# project_id NULL, one per user, organisation and view type. The unique index
+# over (user_id, project_id, view_type) does not hold that row (Postgres counts
+# NULLs as distinct), so it gets a partial index of its own. No data changes.
+#
+# Rolling back fails while a row without a project exists (the column cannot
+# be NOT NULL again over it). Those rows are personal column lists of the
+# overview; delete them first: ViewConfiguration.where(project_id: nil).delete_all
+class AllowViewConfigurationsWithoutProject < ActiveRecord::Migration[8.1]
+ disable_ddl_transaction!
+
+ INDEX = 'index_view_configs_on_user_organisation_type_without_project'
+
+ def change
+ change_column_null :view_configurations, :project_id, true
+ add_index :view_configurations, %i[user_id organisation_id view_type],
+ unique: true, where: 'project_id IS NULL', name: INDEX, algorithm: :concurrently
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e23fec8..e979906 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.1].define(version: 2026_10_15_120000) do
+ActiveRecord::Schema[8.1].define(version: 2026_10_17_120000) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pgcrypto"
@@ -1924,7 +1924,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_10_15_120000) do
create_table "view_configurations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "user_id", null: false
- t.uuid "project_id", null: false
+ t.uuid "project_id"
t.uuid "organisation_id", null: false
t.string "view_type", default: "tickets"
t.jsonb "table_columns", default: []
@@ -1941,6 +1941,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_10_15_120000) do
t.index ["organisation_id"], name: "index_view_configurations_on_organisation_id"
t.index ["project_id"], name: "index_view_configurations_on_project_id"
t.index ["table_columns"], name: "index_view_configurations_on_table_columns", using: :gin
+ t.index ["user_id", "organisation_id", "view_type"], name: "index_view_configs_on_user_organisation_type_without_project", unique: true, where: "(project_id IS NULL)"
t.index ["user_id", "project_id", "view_type"], name: "index_view_configs_on_user_project_type", unique: true
t.index ["user_id"], name: "index_view_configurations_on_user_id"
end
diff --git a/spec/factories/view_configurations.rb b/spec/factories/view_configurations.rb
index 23b4bb1..117bef2 100644
--- a/spec/factories/view_configurations.rb
+++ b/spec/factories/view_configurations.rb
@@ -16,18 +16,19 @@
# updated_at :datetime not null
# kanban_attribute_definition_id :uuid
# organisation_id :uuid not null
-# project_id :uuid not null
+# project_id :uuid
# user_id :uuid not null
#
# Indexes
#
-# index_view_configs_on_user_project_type (user_id,project_id,view_type) UNIQUE
-# index_view_configurations_on_header_columns (header_columns) USING gin
-# index_view_configurations_on_list_columns (list_columns) USING gin
-# index_view_configurations_on_organisation_id (organisation_id)
-# index_view_configurations_on_project_id (project_id)
-# index_view_configurations_on_table_columns (table_columns) USING gin
-# index_view_configurations_on_user_id (user_id)
+# index_view_configs_on_user_organisation_type_without_project (user_id,organisation_id,view_type) UNIQUE WHERE (project_id IS NULL)
+# index_view_configs_on_user_project_type (user_id,project_id,view_type) UNIQUE
+# index_view_configurations_on_header_columns (header_columns) USING gin
+# index_view_configurations_on_list_columns (list_columns) USING gin
+# index_view_configurations_on_organisation_id (organisation_id)
+# index_view_configurations_on_project_id (project_id)
+# index_view_configurations_on_table_columns (table_columns) USING gin
+# index_view_configurations_on_user_id (user_id)
#
# Foreign Keys
#
diff --git a/spec/models/view_configuration_spec.rb b/spec/models/view_configuration_spec.rb
index 3c8c0e7..831b7f1 100644
--- a/spec/models/view_configuration_spec.rb
+++ b/spec/models/view_configuration_spec.rb
@@ -16,18 +16,19 @@
# updated_at :datetime not null
# kanban_attribute_definition_id :uuid
# organisation_id :uuid not null
-# project_id :uuid not null
+# project_id :uuid
# user_id :uuid not null
#
# Indexes
#
-# index_view_configs_on_user_project_type (user_id,project_id,view_type) UNIQUE
-# index_view_configurations_on_header_columns (header_columns) USING gin
-# index_view_configurations_on_list_columns (list_columns) USING gin
-# index_view_configurations_on_organisation_id (organisation_id)
-# index_view_configurations_on_project_id (project_id)
-# index_view_configurations_on_table_columns (table_columns) USING gin
-# index_view_configurations_on_user_id (user_id)
+# index_view_configs_on_user_organisation_type_without_project (user_id,organisation_id,view_type) UNIQUE WHERE (project_id IS NULL)
+# index_view_configs_on_user_project_type (user_id,project_id,view_type) UNIQUE
+# index_view_configurations_on_header_columns (header_columns) USING gin
+# index_view_configurations_on_list_columns (list_columns) USING gin
+# index_view_configurations_on_organisation_id (organisation_id)
+# index_view_configurations_on_project_id (project_id)
+# index_view_configurations_on_table_columns (table_columns) USING gin
+# index_view_configurations_on_user_id (user_id)
#
# Foreign Keys
#
diff --git a/spec/models/view_configuration_without_project_spec.rb b/spec/models/view_configuration_without_project_spec.rb
new file mode 100644
index 0000000..3717709
--- /dev/null
+++ b/spec/models/view_configuration_without_project_spec.rb
@@ -0,0 +1,154 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# The base view of "Alle Meetings" (meetings_uebersicht_vereinheitlichen_plan.md,
+# PR 2): a view configuration without a project. Only the meetings list has a
+# page without a project, so only view_type 'meetings' may go without one. The
+# row of a project and the row of the organisation are separate, and there is
+# at most one row without a project per user, organisation and view type: in
+# the validation AND in the database, because Postgres counts NULLs as distinct
+# and the unique index over (user_id, project_id, view_type) lets any number of
+# them through.
+RSpec.describe ViewConfiguration, 'without a project' do
+ let(:organisation) { create(:organisation) }
+ let(:other_organisation) { create(:organisation) }
+ let(:user) { create(:user) }
+ let(:project) { ActsAsTenant.with_tenant(organisation) { create(:project, organisation: organisation) } }
+
+ before { ActsAsTenant.current_tenant = organisation }
+ after { ActsAsTenant.current_tenant = nil }
+
+ def build_overview_config(view_type: 'meetings', in_organisation: organisation)
+ described_class.new(user: user, organisation: in_organisation, project: nil, view_type: view_type)
+ end
+
+ describe 'validations' do
+ it 'accepts a meetings view without a project' do
+ expect(build_overview_config).to be_valid
+ end
+
+ %w[tickets notes documents].each do |view_type|
+ it "refuses a #{view_type} view without a project" do
+ config = build_overview_config(view_type: view_type)
+
+ expect(config).not_to be_valid
+ expect(config.errors[:project]).to be_present
+ end
+ end
+
+ it 'refuses a second row without a project for the same user, organisation and view type' do
+ build_overview_config.save!
+
+ duplicate = build_overview_config
+ expect(duplicate).not_to be_valid
+ expect(duplicate.errors[:user_id]).to be_present
+ end
+
+ it 'allows the row without a project next to the row of a project' do
+ described_class.create!(user: user, organisation: organisation, project: project, view_type: 'meetings')
+
+ expect(build_overview_config).to be_valid
+ end
+
+ it 'allows a row without a project in each organisation' do
+ build_overview_config.save!
+
+ ActsAsTenant.with_tenant(other_organisation) do
+ expect(build_overview_config(in_organisation: other_organisation)).to be_valid
+ end
+ end
+
+ it 'still refuses a second row of the same project' do
+ described_class.create!(user: user, organisation: organisation, project: project, view_type: 'meetings')
+
+ duplicate = described_class.new(user: user, organisation: organisation, project: project, view_type: 'meetings')
+ expect(duplicate).not_to be_valid
+ end
+ end
+
+ describe 'the unique index' do
+ it 'refuses a second row without a project even past the validation' do
+ build_overview_config.save!
+
+ expect { build_overview_config.save!(validate: false) }.to raise_error(ActiveRecord::RecordNotUnique)
+ end
+
+ it 'takes one row without a project per organisation' do
+ build_overview_config.save!
+
+ ActsAsTenant.with_tenant(other_organisation) do
+ expect { build_overview_config(in_organisation: other_organisation).save!(validate: false) }.not_to raise_error
+ end
+ end
+ end
+
+ describe '.for_user_organisation' do
+ it 'starts with the columns "Alle Meetings" always showed, participants pinned' do
+ config = described_class.for_user_organisation(user, organisation, 'meetings')
+
+ expect(config).not_to be_persisted
+ expect(config.project).to be_nil
+ expect(config.organisation).to eq(organisation)
+ expect(config.ordered_columns).to eq(%w[title project occurred_at duration_minutes participants])
+ expect(config.pinned_column_keys).to eq(%w[participants])
+ end
+
+ it 'returns the stored row' do
+ stored = build_overview_config.tap(&:save!)
+
+ expect(described_class.for_user_organisation(user, organisation, 'meetings')).to eq(stored)
+ end
+
+ it 'never returns the row of a project' do
+ described_class.create!(user: user, organisation: organisation, project: project, view_type: 'meetings',
+ table_columns: %w[title creator])
+
+ config = described_class.for_user_organisation(user, organisation, 'meetings')
+ expect(config).not_to be_persisted
+ expect(config.ordered_columns).to include('project')
+ end
+
+ it 'never returns the row of another organisation' do
+ ActsAsTenant.with_tenant(other_organisation) { build_overview_config(in_organisation: other_organisation).save! }
+
+ expect(described_class.for_user_organisation(user, organisation, 'meetings')).not_to be_persisted
+ 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')
+ without = described_class.for_list(user: user, organisation: organisation, project: nil, view_type: 'meetings')
+
+ expect(with_project.project).to eq(project)
+ expect(without.project).to be_nil
+ expect(without.organisation).to eq(organisation)
+ end
+ end
+
+ describe 'columns' do
+ it 'offers the column "Projekt" only without a project' do
+ without = described_class.available_columns_for(nil, 'meetings').pluck(:key)
+ with_project = described_class.available_columns_for(project, 'meetings').pluck(:key)
+
+ expect(without).to eq(with_project + %w[project])
+ expect(with_project).not_to include('project')
+ expect(described_class.available_columns_for(nil, 'meetings').find { |column| column[:key] == 'project' })
+ .to include(label: 'Projekt')
+ end
+
+ it 'starts a project page without the column "Projekt"' do
+ expect(described_class.default_columns_for(project, 'meetings')).to eq(%w[title occurred_at duration_minutes participants])
+ expect(described_class.default_columns_for(nil, 'meetings')).to eq(%w[title project occurred_at duration_minutes participants])
+ end
+
+ it 'answers the ticket helpers without a project instead of raising' do
+ expect(described_class.available_columns_for(nil, 'tickets').pluck(:key)).to include('number', 'title')
+ expect(described_class.status_attribute_for(nil)).to be_nil
+ expect(described_class.time_columns_visible_for?(nil, user)).to be false
+ expect(build_overview_config.kanban_eligible_attributes).to be_empty
+ expect(build_overview_config.available_header_columns.pluck(:key)).to include('assignees')
+ end
+ end
+end