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

prevent ical_url url generation when ical sharing is globally disabled

Jonas Jabarifc45cb8d66e9
diff --git a/lib/api/v3/queries/ical_url/query_ical_url_api.rb b/lib/api/v3/queries/ical_url/query_ical_url_api.rb
index 5f5271cc5d4..7c99d9a36cf 100644
--- a/lib/api/v3/queries/ical_url/query_ical_url_api.rb
+++ b/lib/api/v3/queries/ical_url/query_ical_url_api.rb
@@ -35,10 +35,9 @@ module API
# API inflection rule prevents ICal inflection rule to be used in this context
class QueryIcalUrlAPI < ::API::OpenProjectAPI
namespace :ical_url do
- # TODO: introduce OpenProject::Configuration.ical_subscriptions_enabled configuration
- # before do
- # raise API::Errors::NotFound unless OpenProject::Configuration.ical_subscriptions_enabled?
- # end
+ before do
+ raise API::Errors::Unauthorized unless Setting.ical_enabled?
+ end
params do
requires :token_name, type: String, desc: 'The name which should be used for the ical token'
diff --git a/lib/api/v3/queries/query_representer.rb b/lib/api/v3/queries/query_representer.rb
index 78e972c2e87..d1ffa0046b1 100644
--- a/lib/api/v3/queries/query_representer.rb
+++ b/lib/api/v3/queries/query_representer.rb
@@ -149,7 +149,8 @@ module API
link :icalUrl do
next if represented.new_record? ||
- !allowed_to?(:share_via_ical)
+ !allowed_to?(:share_via_ical) ||
+ !Setting.ical_enabled?
{
href: api_v3_paths.query_ical_url(represented.id),
diff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rb
index 6aa9f161154..0424a082086 100644
--- a/modules/calendar/spec/features/calendar_sharing_spec.rb
+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb
@@ -67,9 +67,6 @@ RSpec.describe 'Calendar sharing via ical', js: true do
end
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
-
before do
login_as user_with_sharing_permission
calendar.visit!
@@ -142,7 +139,7 @@ RSpec.describe 'Calendar sharing via ical', js: true do
end
context 'when ical sharing is disabled globally', with_settings: { ical_enabled: false } do
- it 'shows an active menu item' do
+ it 'shows a disabled menu item' do
# wait for settings button to become visible
expect(page).to have_selector("#work-packages-settings-button")
@@ -180,7 +177,7 @@ RSpec.describe 'Calendar sharing via ical', js: true do
it 'successfully requests a new tokenized iCalendar URL when a unique name is provided' do
open_sharing_modal
- fill_in "Name", with: "A token name"
+ fill_in "Token name", with: "A token name"
click_button "Copy URL"
@@ -201,7 +198,7 @@ RSpec.describe 'Calendar sharing via ical', js: true do
it 'validates the presence of a name' do
open_sharing_modal
- # fill_in "Name", with: "A token name"
+ # fill_in "Token name", with: "A token name"
click_button "Copy URL"
@@ -213,7 +210,7 @@ RSpec.describe 'Calendar sharing via ical', js: true do
it 'validates the uniqueness of a name' do
open_sharing_modal
- fill_in "Name", with: "A token name"
+ fill_in "Token name", with: "A token name"
click_button "Copy URL"
@@ -224,7 +221,7 @@ RSpec.describe 'Calendar sharing via ical', js: true do
open_sharing_modal
- fill_in "Name", with: "A token name" # same name for same user and same query -> not allowed
+ fill_in "Token name", with: "A token name" # same name for same user and same query -> not allowed
click_button "Copy URL"
diff --git a/spec/lib/api/v3/queries/query_representer_rendering_spec.rb b/spec/lib/api/v3/queries/query_representer_rendering_spec.rb
index e03e5817812..757a1862271 100644
--- a/spec/lib/api/v3/queries/query_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/queries/query_representer_rendering_spec.rb
@@ -551,9 +551,18 @@ RSpec.describe API::V3::Queries::QueryRepresenter do
context 'when allowed to subscribe to ical' do
let(:permissions) { %i(share_via_ical) }
- it_behaves_like 'has an untitled link' do
- let(:link) { 'icalUrl' }
- let(:href) { api_v3_paths.query_ical_url(query.id) }
+ context 'when icalendar sharing is enabled globally', with_settings: { ical_enabled: true } do
+ it_behaves_like 'has an untitled link' do
+ let(:link) { 'icalUrl' }
+ let(:href) { api_v3_paths.query_ical_url(query.id) }
+ end
+ end
+
+ context 'when icalendar sharing is disabled globally', with_settings: { ical_enabled: false } do
+ it 'has no icalUrl link' do
+ expect(subject)
+ .not_to have_json_path('_links/icalUrl')
+ end
end
end
diff --git a/spec/requests/api/v3/queries/ical_url/query_ical_url_api_spec.rb b/spec/requests/api/v3/queries/ical_url/query_ical_url_api_spec.rb
index f3e4f62b24b..8d1bf83291e 100644
--- a/spec/requests/api/v3/queries/ical_url/query_ical_url_api_spec.rb
+++ b/spec/requests/api/v3/queries/ical_url/query_ical_url_api_spec.rb
@@ -85,7 +85,13 @@ RSpec.describe 'API v3 Query ICal Url' do
end
context 'when user has sufficient permissions and owns the query' do
- it_behaves_like 'success'
+ context 'when icalendar sharing is enabled globally', with_settings: { ical_enabled: true } do
+ it_behaves_like 'success'
+ end
+
+ context 'when icalendar sharing is disabled globally', with_settings: { ical_enabled: false } do
+ it_behaves_like 'unauthorized access'
+ end
end
context 'when user has sufficient permissions and tries to get the iCalendar url of the public query of another user' do
@@ -98,10 +104,16 @@ RSpec.describe 'API v3 Query ICal Url' do
let(:query) { create(:query, project:, user: other_user, public: true) }
let(:path) { api_v3_paths.query_ical_url(query.id) }
- it_behaves_like 'success'
+ context 'when icalendar sharing is enabled globally', with_settings: { ical_enabled: true } do
+ it_behaves_like 'success'
+ end
+
+ context 'when icalendar sharing is disabled globally', with_settings: { ical_enabled: false } do
+ it_behaves_like 'unauthorized access'
+ end
end
- context 'when user has no access to the associated project' do
+ context 'when user has no access to the associated project', with_settings: { ical_enabled: true } do
let(:other_project) { create(:project) }
let(:query) { create(:query, project: other_project, user:) }
let(:path) { api_v3_paths.query_ical_url(query.id) }
@@ -109,7 +121,8 @@ RSpec.describe 'API v3 Query ICal Url' do
it_behaves_like 'not found'
end
- context 'when user tries to get an iCalendar url from a private query of another user' do
+ context 'when user tries to get an iCalendar url from a private query of another user',
+ with_settings: { ical_enabled: true } do
let(:other_user) { create(:user) }
let(:query) { create(:query, project:, user: other_user, public: false) }
let(:path) { api_v3_paths.query_ical_url(query.id) }
@@ -117,7 +130,7 @@ RSpec.describe 'API v3 Query ICal Url' do
it_behaves_like 'not found'
end
- context 'when user has insufficient permissions' do
+ context 'when user has insufficient permissions', with_settings: { ical_enabled: true } do
# :view_work_packages permission is mandatory, otherwise a 404 is returned.
let(:permissions) { [:view_work_packages] } # share_calendars is missing