Skip to content

Commit d0b40f7

Browse files
committed
Enable documents module by default when real-time collaboration is enabled
Note: For existing instances, documents will only be added to defaults if real-time collaboration is enabled when the migration runs. Enabling collaboration later requires manual addition to default modules.
1 parent a750f84 commit d0b40f7

5 files changed

Lines changed: 188 additions & 1 deletion

File tree

app/seeders/standard.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ projects:
9191
- board_view
9292
- team_planner_view
9393
- meetings
94+
- documents
9495
news:
9596
- t_title: Welcome to your demo project
9697
t_summary: |
@@ -389,6 +390,7 @@ projects:
389390
- work_package_tracking
390391
- gantt
391392
- board_view
393+
- documents
392394
news:
393395
- t_title: Welcome to your Scrum demo project
394396
t_summary: |

config/constants/settings/definition.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,14 @@ class Definition
346346
allowed: -> { Redmine::I18n.all_languages }
347347
},
348348
default_projects_modules: {
349-
default: %w[calendar board_view work_package_tracking gantt news costs wiki],
349+
default: -> {
350+
base_modules = %w[calendar board_view work_package_tracking gantt news costs wiki]
351+
if Setting.real_time_text_collaboration_enabled?
352+
base_modules + %w[documents]
353+
else
354+
base_modules
355+
end
356+
},
350357
allowed: -> { OpenProject::AccessControl.available_project_modules.map(&:to_s) }
351358
},
352359
default_projects_public: {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
class AddDocumentsToDefaultProjectsModules < ActiveRecord::Migration[8.0]
32+
def up
33+
return unless Setting.real_time_text_collaboration_enabled?
34+
35+
# Only update if setting exists in DB (avoid updating on new installations - seeder handles that)
36+
setting = Setting.find_by(name: "default_projects_modules")
37+
return unless setting
38+
39+
current_modules = setting.value || []
40+
return if current_modules.include?("documents")
41+
42+
Setting.default_projects_modules = current_modules + ["documents"]
43+
end
44+
45+
def down
46+
# No-op
47+
end
48+
end
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
require "spec_helper"
32+
require Rails.root.join("db/migrate/20260106151226_add_documents_to_default_projects_modules")
33+
34+
RSpec.describe AddDocumentsToDefaultProjectsModules, type: :model do
35+
let(:base_modules) { %w[calendar board_view work_package_tracking gantt news costs wiki] }
36+
37+
before do
38+
# Ensure a clean state
39+
Setting.find_by(name: "default_projects_modules")&.destroy
40+
Setting.clear_cache
41+
end
42+
43+
context "when real_time_text_collaboration is enabled",
44+
with_settings: { real_time_text_collaboration_enabled: true } do
45+
context "when default_projects_modules setting exists in DB" do
46+
before do
47+
Setting.default_projects_modules = base_modules
48+
end
49+
50+
it "adds documents to the default modules" do
51+
ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) }
52+
53+
Setting.clear_cache
54+
expect(Setting.default_projects_modules).to include("documents")
55+
end
56+
57+
it "preserves existing modules" do
58+
ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) }
59+
60+
Setting.clear_cache
61+
expect(Setting.default_projects_modules).to include(*base_modules)
62+
end
63+
64+
context "when documents is already in the default modules" do
65+
before do
66+
Setting.default_projects_modules = base_modules + ["documents"]
67+
end
68+
69+
it "does not duplicate documents" do
70+
ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) }
71+
72+
Setting.clear_cache
73+
expect(Setting.default_projects_modules.count("documents")).to eq(1)
74+
end
75+
end
76+
end
77+
78+
context "when default_projects_modules setting does not exist in DB" do
79+
it "does not create the setting (seeder handles new installations)" do
80+
expect(Setting.find_by(name: "default_projects_modules")).to be_nil
81+
82+
ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) }
83+
84+
# Setting should still not exist - seeder will handle it
85+
expect(Setting.find_by(name: "default_projects_modules")).to be_nil
86+
end
87+
end
88+
end
89+
90+
context "when real_time_text_collaboration is disabled",
91+
with_settings: { real_time_text_collaboration_enabled: false } do
92+
before do
93+
Setting.default_projects_modules = base_modules
94+
end
95+
96+
it "does not modify the default modules" do
97+
ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) }
98+
99+
Setting.clear_cache
100+
expect(Setting.default_projects_modules).not_to include("documents")
101+
expect(Setting.default_projects_modules).to match_array(base_modules)
102+
end
103+
end
104+
end

spec/models/setting_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,30 @@
603603
end
604604
end
605605
end
606+
607+
describe "default_projects_modules conditional default" do
608+
context "when real_time_text_collaboration is enabled",
609+
with_settings: { real_time_text_collaboration_enabled: true } do
610+
it "includes documents in the default modules" do
611+
expect(Settings::Definition[:default_projects_modules].default).to include("documents")
612+
end
613+
614+
it "includes the base modules" do
615+
base_modules = %w[calendar board_view work_package_tracking gantt news costs wiki]
616+
expect(Settings::Definition[:default_projects_modules].default).to include(*base_modules)
617+
end
618+
end
619+
620+
context "when real_time_text_collaboration is disabled",
621+
with_settings: { real_time_text_collaboration_enabled: false } do
622+
it "does not include documents in the default modules" do
623+
expect(Settings::Definition[:default_projects_modules].default).not_to include("documents")
624+
end
625+
626+
it "includes the base modules" do
627+
base_modules = %w[calendar board_view work_package_tracking gantt news costs wiki]
628+
expect(Settings::Definition[:default_projects_modules].default).to include(*base_modules)
629+
end
630+
end
631+
end
606632
end

0 commit comments

Comments
 (0)