Skip to content

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

WIP: adding global ical control to settings

Jonas Jabari8f555209bde9
diff --git a/app/contracts/queries/ical_sharing_contract.rb b/app/contracts/queries/ical_sharing_contract.rb
index d67bf14a519..a4d2995ced3 100644
--- a/app/contracts/queries/ical_sharing_contract.rb
+++ b/app/contracts/queries/ical_sharing_contract.rb
@@ -35,11 +35,15 @@ module Queries
protected
def user_allowed_to_subscribe_to_query_via_ical
- return if user_allowed_to_use_ical_sharing? && query_visible_for_user? && token_valid_for_query?
+ return if ical_globally_enabled? && user_allowed_to_use_ical_sharing? && query_visible_for_user? && token_valid_for_query?
errors.add :base, :error_unauthorized
end
+ def ical_globally_enabled?
+ Setting.ical_enabled?
+ end
+
def user_allowed_to_use_ical_sharing?
QueryPolicy.new(user).allowed?(model, :share_via_ical)
end
diff --git a/app/views/admin/settings/general_settings/show.html.erb b/app/views/admin/settings/general_settings/show.html.erb
index 6569e592380..ad7182b180a 100644
--- a/app/views/admin/settings/general_settings/show.html.erb
+++ b/app/views/admin/settings/general_settings/show.html.erb
@@ -49,6 +49,7 @@ See COPYRIGHT and LICENSE files for more details.
</div>
<div class="form--field"><%= setting_check_box :cache_formatted_text %></div>
<div class="form--field"><%= setting_check_box :feeds_enabled, size: 6 %></div>
+ <div class="form--field"><%= setting_check_box :ical_enabled, size: 6 %></div>
<div class="form--field"><%= setting_text_field :feeds_limit, size: 6, container_class: '-xslim' %></div>
<div class="form--field"><%= setting_text_field :work_packages_projects_export_limit, size: 6, container_class: '-xslim' %></div>
<div class="form--field">
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c111e6ace68..7950e12a45b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2679,6 +2679,7 @@ en:
setting_enabled_scm: "Enabled SCM"
setting_enabled_projects_columns: "Visible in project list"
setting_feeds_enabled: "Enable Feeds"
+ setting_ical_enabled: "Enable iCalendar Subscriptions"
setting_feeds_limit: "Feed content limit"
setting_file_max_size_displayed: "Max size of text files displayed inline"
setting_host_name: "Host name"
diff --git a/modules/calendar/lib/open_project/calendar/engine.rb b/modules/calendar/lib/open_project/calendar/engine.rb
index 8a41e2123f4..3664a173024 100644
--- a/modules/calendar/lib/open_project/calendar/engine.rb
+++ b/modules/calendar/lib/open_project/calendar/engine.rb
@@ -65,5 +65,11 @@ module OpenProject::Calendar
Mime::Type.register('text/calendar', :ics)
end
+
+ initializer 'calendar.configuration' do
+ ::Settings::Definition.add 'ical_enabled',
+ default: true,
+ format: :boolean
+ end
end
end
diff --git a/modules/calendar/spec/controllers/ical_controller_spec.rb b/modules/calendar/spec/controllers/ical_controller_spec.rb
index 3d354bf06bf..52df43feafe 100644
--- a/modules/calendar/spec/controllers/ical_controller_spec.rb
+++ b/modules/calendar/spec/controllers/ical_controller_spec.rb
@@ -133,6 +133,19 @@ RSpec.describe Calendar::ICalController do
it_behaves_like 'success'
end
+ context 'with valid params and permissions when targeting own query when globally disabled',
+ with_settings: { ical_enabled: false } do
+ before do
+ get :show, params: {
+ project_id: project.id,
+ id: query.id,
+ ical_token: valid_ical_token_value
+ }
+ end
+
+ it_behaves_like 'failure'
+ end
+
context 'with valid params and permissions when targeting own query with login required set to `true`',
with_settings: { login_required: true } do
before do
@@ -173,6 +186,34 @@ RSpec.describe Calendar::ICalController do
it_behaves_like 'success'
end
+ context 'with valid params and permissions when targeting a public query of somebody else',
+ with_settings: { ical_enabled: false } do
+ let(:user2) do
+ create(:user,
+ member_in_project: project,
+ member_with_permissions: sufficient_permissions)
+ end
+ let(:query2) do
+ create(:query,
+ project:,
+ user: user2,
+ public: true)
+ end
+ let(:valid_ical_token_value) do
+ Token::ICal.create_and_return_value(user, query2, "Some Token Name")
+ end
+
+ before do
+ get :show, params: {
+ project_id: project.id,
+ id: query2.id,
+ ical_token: valid_ical_token_value
+ }
+ end
+
+ it_behaves_like 'failure'
+ end
+
context 'with valid params and permissions when targeting a public query of somebody else with login required set to `true`',
with_settings: { login_required: true } do
let(:user2) do
@@ -302,5 +343,19 @@ RSpec.describe Calendar::ICalController do
# should the project id still be used in the ical url anyways?
it_behaves_like 'success'
end
+
+ context 'with invalid project', with_settings: { ical_enabled: false } do
+ before do
+ get :show, params: {
+ project_id: SecureRandom.hex,
+ id: query.id,
+ ical_token: valid_ical_token_value
+ }
+ end
+
+ # TODO: the project id is actually irrelevant - the query id is enough
+ # should the project id still be used in the ical url anyways?
+ it_behaves_like 'failure'
+ end
end
end
diff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rb
index c2492405122..6aa9f161154 100644
--- a/modules/calendar/spec/features/calendar_sharing_spec.rb
+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe 'Calendar sharing via ical', js: true do
public: false)
end
- context 'with sufficient permissions' do
+ context 'with sufficient permissions', with_settings: { ical_enabled: true } do
# TODO: save_queries permission is mandatory to see settings button used for sharing option
# does that make sense? the sharing feature therefore has an implicit dependency on this permission
@@ -141,6 +141,26 @@ RSpec.describe 'Calendar sharing via ical', js: true do
end
end
+ context 'when ical sharing is disabled globally', with_settings: { ical_enabled: false } do
+ it 'shows an active menu item' do
+ # wait for settings button to become visible
+ expect(page).to have_selector("#work-packages-settings-button")
+
+ # click on settings button
+ page.find_by_id('work-packages-settings-button').click
+
+ # expect disabled sharing menu item
+ within "#settingsDropdown" do
+ # expect(page).to have_button("Subscribe to iCalendar", disabled: true) # disabled selector not working
+ expect(page).to have_selector(".menu-item.inactive", text: "Subscribe to iCalendar")
+ page.click_button("Subscribe to iCalendar")
+
+ # modal should not be shown
+ expect(page).not_to have_selector('.spot-modal--header', text: "Subscribe to iCalendar")
+ end
+ end
+ end
+
it 'shows a sharing modal' do
open_sharing_modal
diff --git a/spec/contracts/queries/ical_sharing_contract_spec.rb b/spec/contracts/queries/ical_sharing_contract_spec.rb
index 4e30ecd99a7..4c194435186 100644
--- a/spec/contracts/queries/ical_sharing_contract_spec.rb
+++ b/spec/contracts/queries/ical_sharing_contract_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe Queries::ICalSharingContract do
describe 'private query' do
let(:public) { false }
- context 'when user is author' do
+ context 'when user is author', with_settings: { ical_enabled: true } do
let(:user) { current_user }
context 'when user has no permission to share via ical' do
@@ -65,6 +65,10 @@ RSpec.describe Queries::ICalSharingContract do
let(:permissions) { %i(view_work_packages share_calendars) }
it_behaves_like 'contract is valid'
+
+ context 'when iCalendar subscriptions are globally disabled', with_settings: { ical_enabled: false } do
+ it_behaves_like 'contract user is unauthorized'
+ end
end
context 'when ical_token is not scoped to query' do
@@ -87,7 +91,7 @@ RSpec.describe Queries::ICalSharingContract do
end
end
- context 'when author is someone else' do
+ context 'when author is someone else', with_settings: { ical_enabled: true } do
let(:user) { create(:user) } # other user as owner of query
let(:permissions) { %i(view_work_packages share_calendars) } # all necessary permissions
@@ -99,7 +103,7 @@ RSpec.describe Queries::ICalSharingContract do
let(:public) { true }
let(:user) { current_user }
- context 'when user has no permission to share via ical' do
+ context 'when user has no permission to share via ical', with_settings: { ical_enabled: true } do
let(:permissions) { %i(view_work_packages view_calendar manage_calendars) }
it_behaves_like 'contract user is unauthorized'
@@ -111,7 +115,7 @@ RSpec.describe Queries::ICalSharingContract do
end
end
- context 'when user has permission to share via ical' do
+ context 'when user has permission to share via ical', with_settings: { ical_enabled: true } do
let(:permissions) { %i(view_work_packages share_calendars) }
it_behaves_like 'contract is valid'
@@ -121,6 +125,16 @@ RSpec.describe Queries::ICalSharingContract do
it_behaves_like 'contract is valid' # authorized as query is public
end
+
+ context 'when iCalendar subscriptions are globally disabled', with_settings: { ical_enabled: false } do
+ it_behaves_like 'contract user is unauthorized'
+
+ context 'when author is someone else' do
+ let(:user) { create(:user) } # other user as owner of query
+
+ it_behaves_like 'contract user is unauthorized'
+ end
+ end
end
end
@@ -133,7 +147,7 @@ RSpec.describe Queries::ICalSharingContract do
member_with_permissions: permissions)
end
- context 'when user is author but not member of project (anymore)' do
+ context 'when user is author but not member of project (anymore)', with_settings: { ical_enabled: true } do
let(:user) { current_user }
context 'when user has no permission to share via ical' do