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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
refactoring, bugfixing based on feedback, added first UI specs
Jonas Jabari3267ac1a35ac
diff --git a/app/policies/query_policy.rb b/app/policies/query_policy.rbindex f99f8b79a53..6430f86c3d1 100644--- a/app/policies/query_policy.rb+++ b/app/policies/query_policy.rb@@ -42,7 +42,7 @@ class QueryPolicy < BasePolicystar: persisted_and_own_or_public?(cached_query),unstar: persisted_and_own_or_public?(cached_query),reorder_work_packages: reorder_work_packages?(cached_query),- create_ical_url: create_ical_url_allowed?(cached_query)+ share_via_ical: share_via_ical_allowed?(cached_query)}end@@ -121,11 +121,11 @@ class QueryPolicy < BasePolicy@manage_public_queries_cache[query.project]end- def create_ical_url_allowed?(query)- @create_ical_url_cache ||= Hash.new do |hash, project|+ def share_via_ical_allowed?(query)+ @share_via_ical_cache ||= Hash.new do |hash, project|hash[project] = user.allowed_to?(:share_calendars, project, global: project.nil?)end- @create_ical_url_cache[query.project]+ @share_via_ical_cache[query.project]endenddiff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex b8b2a1893fa..46f45cf61ba 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -1150,6 +1150,7 @@ en:save_as: "Save as ..."export: "Export ..."visibility_settings: "Visibility settings ..."+ share_calendar: "Share calendar ..."page_settings: "Rename view ..."delete: "Delete"filter: "Filter"diff --git a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.tsindex 40bfd005554..f235948d128 100644--- a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts+++ b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts@@ -86,7 +86,7 @@ export class QueryGetIcalUrlModalComponent extends OpModalComponent implements Othis.query- .createIcalUrl()+ .shareCalendars().then((response:HalResource) => {this.icalUrl = response.icalUrl;this.isBusy = false;diff --git a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.tsindex bf5b20454cc..660e20b02a9 100644--- a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts+++ b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts@@ -318,11 +318,11 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {{// Calendar sharing modalhidden: !this.showCalendarSharingOption,- disabled: this.authorisationService.cannot('query', 'createIcalUrl'),- linkText: "Share Calendar", // TODO: translate+ disabled: this.authorisationService.cannot('query', 'shareCalendars'),+ linkText: this.I18n.t('js.toolbar.settings.share_calendar'),icon: 'icon-link', // TODO: find sharing iconsonClick: ($event:JQuery.TriggeredEvent) => {- if (this.authorisationService.can('query', 'createIcalUrl')) {+ if (this.authorisationService.can('query', 'shareCalendars')) {this.opModalService.show(QueryGetIcalUrlModalComponent, this.injector);}diff --git a/lib/api/v3/queries/queries_api.rb b/lib/api/v3/queries/queries_api.rbindex 9769f9aae41..6e0444ba64a 100644--- a/lib/api/v3/queries/queries_api.rb+++ b/lib/api/v3/queries/queries_api.rb@@ -161,7 +161,7 @@ module APInamespace :create_ical_url dopost do- authorize_by_policy(:create_ical_url)+ authorize_by_policy(:share_via_ical)# currently the generated URL points to controller action in calendar module# correct approach? or should it be implemented as a API here?diff --git a/lib/api/v3/queries/query_representer.rb b/lib/api/v3/queries/query_representer.rbindex 5007c519c45..45c7c5d7831 100644--- a/lib/api/v3/queries/query_representer.rb+++ b/lib/api/v3/queries/query_representer.rb@@ -147,9 +147,9 @@ module API}end- link :createIcalUrl do+ link :shareCalendars donext if represented.new_record? ||- !allowed_to?(:create_ical_url)+ !allowed_to?(:share_via_ical){href: api_v3_paths.query_create_ical_url(represented.id),diff --git a/modules/calendar/app/controllers/calendar/calendars_controller.rb b/modules/calendar/app/controllers/calendar/calendars_controller.rbindex 70cbc983d94..cb0d7df5b8b 100644--- a/modules/calendar/app/controllers/calendar/calendars_controller.rb+++ b/modules/calendar/app/controllers/calendar/calendars_controller.rb@@ -28,8 +28,8 @@module ::Calendarclass CalendarsController < ApplicationController- before_action :find_optional_project, except: %i[ical]- before_action :authorize, except: %i[ical]+ before_action :find_optional_project+ before_action :authorizebefore_action :find_calendar, only: %i[destroy]menu_item :calendar_view@@ -42,24 +42,6 @@ module ::Calendarrender layout: 'angular/angular'end- def ical- begin- call = ::Calendar::IcalResponseService.new().call(- ical_token: params[:ical_token],- query_id: params[:id]- )- rescue ActiveRecord::RecordNotFound- render_404- return- end-- if call.present? && call.success?- render plain: call.result- else- render_404- end- end-def destroyif @view.destroyflash[:notice] = t(:notice_successful_delete)diff --git a/modules/calendar/app/controllers/calendar/ical_controller.rb b/modules/calendar/app/controllers/calendar/ical_controller.rbnew file mode 100644index 00000000000..14274608962--- /dev/null+++ b/modules/calendar/app/controllers/calendar/ical_controller.rb@@ -0,0 +1,56 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module ::Calendar+ class IcalController < ApplicationController++ def ical+ begin+ call = ::Calendar::IcalResponseService.new().call(+ ical_token: params[:ical_token],+ query_id: params[:id]+ )+ rescue ActiveRecord::RecordNotFound+ render_404+ return+ end++ if call.present? && call.success?+ # # respond_to do |format|+ # # format.ics do+ send_data call.result, filename: "openproject_calendar_#{DateTime.now.to_i}.ics"+ # # end+ # # end+ # render plain: call.result#, mime_type: Mime::Type.lookup("text/calendar")+ else+ render_404+ end+ end++ end+enddiff --git a/modules/calendar/app/services/calendar/create_ical_service.rb b/modules/calendar/app/services/calendar/create_ical_service.rbindex 735cdf7bc19..be22ac88003 100644--- a/modules/calendar/app/services/calendar/create_ical_service.rb+++ b/modules/calendar/app/services/calendar/create_ical_service.rb@@ -44,10 +44,10 @@ module Calendarcalendar = Icalendar::Calendar.newcalendar.prodid = "-//OpenProject GmbH//OpenProject Core Project//EN"- calendar.x_wr_calname = "OpenProject Calendar"+ calendar.x_wr_calname = "OpenProject Calendar" # TODO: Use query name insteadwork_packages&.each do |work_package|- next if work_package.due_date.nil?+ next if work_package.start_date.nil? && work_package.due_date.nil?event = create_event(work_package)@@ -60,7 +60,8 @@ module Calendardef create_event(work_package)event = Icalendar::Event.newevent.uid = "#{work_package.id}@#{host}"- event.attendee = [work_package.assigned_to&.name]+ # event.attendee = [work_package.assigned_to&.name] # causing thunderbird error "id is null"+ event.attendee = [work_package.assigned_to&.name] if work_package.assigned_to.present?event.organizer = work_package.author&.nameevent.summary = work_package.nameevent.dtstart = Icalendar::Values::Date.new(start_date(work_package))@@ -81,7 +82,7 @@ module Calendardef due_date(work_package)if work_package.start_date.present?- work_package.due_date+ work_package.due_date + 1.dayelsework_package.due_date + 1.dayend@@ -119,11 +120,12 @@ module Calendar# enddef description_value(work_package)+ # TODO: translate keysproject = "Project: #{work_package.project.name}"- type = "Type: #{type_emoji(work_package)} #{work_package.type&.name}"+ type = "Type: #{type_emoji(work_package)}#{work_package.type&.name}"status = "Status: #{work_package.status&.name}"assignee = "Assignee: #{work_package.assigned_to&.name}"- priority = "Priority: #{priority_emoji(work_package)} #{work_package.priority&.name}"+ priority = "Priority: #{priority_emoji(work_package)}#{work_package.priority&.name}"unless work_package.description.blank?description = "Work package description: #{work_package.description&.truncate(250)}"end@@ -135,12 +137,12 @@ module Calendardef type_emoji(work_package)# TODO: Differentiate emoji based on type- "🟩"+ # "🟩"enddef priority_emoji(work_package)# TODO: Differentiate emoji based on priority- "🟢"+ # "🟢"endenddiff --git a/modules/calendar/app/services/calendar/generate_ical_url.rb b/modules/calendar/app/services/calendar/generate_ical_url.rbindex cfc36111392..6e15947623f 100644--- a/modules/calendar/app/services/calendar/generate_ical_url.rb+++ b/modules/calendar/app/services/calendar/generate_ical_url.rb@@ -45,7 +45,7 @@ module Calendardef create_ical_url(query_id, project_id, ical_token)url_for(- controller: "calendar/calendars",+ controller: "calendar/ical",action: :ical,id: query_id,project_id: project_id,diff --git a/modules/calendar/app/services/calendar/ical_response_service.rb b/modules/calendar/app/services/calendar/ical_response_service.rbindex c0fab83a03a..389e65f0ddc 100644--- a/modules/calendar/app/services/calendar/ical_response_service.rb+++ b/modules/calendar/app/services/calendar/ical_response_service.rb@@ -31,7 +31,7 @@ module Calendarclass IcalResponseService < ::BaseServices::BaseCallabledef perform(ical_token:, query_id:)- # STEP 1 -> TODO: simple time based caching -> recreate ics only every x minute(s)+ # TODO: simple time based caching -> recreate ics only every x minute(s)ical_string = resolve_from_cache(ical_token, query_id)if ical_string.present?@@ -40,17 +40,16 @@ module Calendarend# if not resolved from cache, proceed:-- # STEP 2 -> Resolve user by tokenuser = resolve_user_by_token(ical_token)- # STEP 3 -> Resolve work_packages and authorize user- work_packages = resolve_work_packages(user, query_id)+ query = resolve_and_authorize_query(user, query_id)++ work_packages = resolve_work_packages(query)- # STEP 4 -> Resolve work_packages and authorize userical_string = create_ical_string(work_packages)if ical_string.present?+ # TODO: save in cacheServiceResult.success(result: ical_string)elseServiceResult.failure@@ -72,11 +71,20 @@ module Calendaruserend- def resolve_work_packages(user, query_id)- call = ::Calendar::ResolveWorkPackagesService.new().call(+ def resolve_and_authorize_query(user, query_id)+ call = ::Calendar::ResolveAndAuthorizeQueryService.new().call(user: user,query_id: query_id)+ query = call.result if call.success?++ query+ end++ def resolve_work_packages(query)+ call = ::Calendar::ResolveWorkPackagesService.new().call(+ query: query+ )work_packages = call.result if call.success?work_packagesdiff --git a/modules/calendar/app/services/calendar/resolve_and_authorize_query_service.rb b/modules/calendar/app/services/calendar/resolve_and_authorize_query_service.rbnew file mode 100644index 00000000000..862053f80c4--- /dev/null+++ b/modules/calendar/app/services/calendar/resolve_and_authorize_query_service.rb@@ -0,0 +1,56 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Calendar+ class ResolveAndAuthorizeQueryService < ::BaseServices::BaseCallable++ def perform(user:, query_id:)+ query = Query+ .visible(user) # authorization+ .find(query_id)++ # TODO:+ # Is this the correct way of unscoping the calendar view state+ # in order to get all workpackages from the query?+ query.filters = query.filters+ .reject { |filter| filter.name == :dates_interval }++ sharing_permitted = QueryPolicy.new(user).allowed?(+ query, :share_via_ical+ )++ if query.present? && sharing_permitted+ ServiceResult.success(result: query)+ else+ # TODO: raise specific auth error+ raise ActiveRecord::RecordNotFound+ end+ end++ end+enddiff --git a/modules/calendar/app/services/calendar/resolve_ical_user_service.rb b/modules/calendar/app/services/calendar/resolve_ical_user_service.rbindex 18fdf32f95d..7adf64ee7b9 100644--- a/modules/calendar/app/services/calendar/resolve_ical_user_service.rb+++ b/modules/calendar/app/services/calendar/resolve_ical_user_service.rb@@ -35,8 +35,14 @@ module Calendarendtoken = Token::Ical.find_by_plaintext_value(ical_token)+if token.present?user = token.user+ # Setting the current user to the one resolved via ical_token+ # TODO: required for internal query scoping?+ # TODO: does that have any security implications?+ User.current = user+ServiceResult.success(result: user)elseraise ActiveRecord::RecordNotFounddiff --git a/modules/calendar/app/services/calendar/resolve_work_packages_service.rb b/modules/calendar/app/services/calendar/resolve_work_packages_service.rbindex a405734e1fa..32c59f63971 100644--- a/modules/calendar/app/services/calendar/resolve_work_packages_service.rb+++ b/modules/calendar/app/services/calendar/resolve_work_packages_service.rb@@ -29,35 +29,23 @@module Calendarclass ResolveWorkPackagesService < ::BaseServices::BaseCallable- def perform(user:, query_id:)- query = resolve_query(user, query_id)- work_packages = resolve_work_packages(query)-- if work_packages.present?- ServiceResult.success(result: work_packages)- else- ServiceResult.failure- end- end-- protected-- def resolve_query(user, query_id)- Query- .visible(user) # authorization- .find(query_id)- end-- def resolve_work_packages(query)+ def perform(query:)unless(query.nil? ||- query.results.nil? ||- query.results.work_packages.nil?+ query.results.nil?)+ # TODO: check if the includes makes sense here in order to avoid n+1 querieswork_packages = query.results.work_packages.includes(:project, :assigned_to, :author, :priority, :status)end++ unless work_packages.nil?+ ServiceResult.success(result: work_packages)+ else+ # TODO: raise specific error+ raise ActiveRecord::RecordNotFound+ endendenddiff --git a/modules/calendar/config/routes.rb b/modules/calendar/config/routes.rbindex d54290698ea..f8197a07426 100644--- a/modules/calendar/config/routes.rb+++ b/modules/calendar/config/routes.rb@@ -6,7 +6,8 @@ OpenProject::Application.routes.draw doas: :calendars doget '/new' => 'calendar/calendars#show', on: :collection, as: 'new'# TODO: discuss if other controller should be used- get '/ical' => 'calendar/calendars#ical', on: :member, as: 'ical'+ get '/ical' => 'calendar/ical#ical', on: :member, as: 'ical'+ match '/ical' => 'calendar/ical#ical', :via => :propfindget '(/*state)' => 'calendar/calendars#show', on: :member, as: ''endenddiff --git a/modules/calendar/lib/open_project/calendar/engine.rb b/modules/calendar/lib/open_project/calendar/engine.rbindex 99cbb3f2979..c2d9d6f4ac9 100644--- a/modules/calendar/lib/open_project/calendar/engine.rb+++ b/modules/calendar/lib/open_project/calendar/engine.rb@@ -37,7 +37,6 @@ module OpenProject::Calendardependencies: %i[view_calendar add_work_packages edit_work_packages save_queries manage_public_queries],contract_actions: { calendar: %i[create update destroy] }permission :share_calendars,- { 'calendar/calendars': %i[generate_ical_url] },dependencies: %i[view_calendar],contract_actions: { calendar: %i[read] }end@@ -60,5 +59,11 @@ module OpenProject::Calendaradd_view :WorkPackagesCalendar,contract_strategy: 'Calendar::Views::ContractStrategy'++ initializer 'calendar.register_mimetypes' do+ # next if defined? Mime::XLS++ Mime::Type.register('text/calendar', :ics)+ endendenddiff --git a/modules/calendar/spec/controllers/ical_controller_spec.rb b/modules/calendar/spec/controllers/ical_controller_spec.rbnew file mode 100644index 00000000000..6e54705ee16--- /dev/null+++ b/modules/calendar/spec/controllers/ical_controller_spec.rb@@ -0,0 +1,117 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe Calendar::IcalController do+ let(:project) { create(:project) }+ let(:user) do+ create(:user,+ member_in_project: project,+ member_with_permissions: sufficient_permissions)+ end+ let(:sufficient_permissions) { %i[view_work_packages share_calendars] }+ let(:valid_ical_token_value) { Token::Ical.create_and_return_value user }+ let(:query) do+ create(:query,+ project: project,+ user: user,+ public: false)+ end++ # the ical urls are intended to be used without a logged in user from a calendar client app+ # before { login_as(user) }++ describe '#ical' do+ shared_examples_for 'ical#ical' do |expected|+ subject { response }++ if expected == :success+ it { is_expected.to be_successful }+ end+ if expected == :failure+ it { is_expected.not_to be_successful }+ end++ end++ context 'with valid params' do++ before do+ get :ical, params: {+ project_id: project.id,+ id: query.id,+ ical_token: valid_ical_token_value }++ end++ it_behaves_like 'ical#ical', :success+ end++ context 'with invalid token' do++ before do+ get :ical, params: {+ project_id: project.id,+ id: query.id,+ ical_token: SecureRandom.hex+ }+ end++ it_behaves_like 'ical#ical', :failure+ end++ context 'with invalid query' do++ before do+ get :ical, params: {+ project_id: project.id,+ id: SecureRandom.hex,+ ical_token: valid_ical_token_value+ }+ end++ it_behaves_like 'ical#ical', :failure+ end++ context 'with invalid project' do++ before do+ get :ical, 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 'ical#ical', :success+ end+ end+enddiff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rbnew file mode 100644index 00000000000..896d752f2a5--- /dev/null+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb@@ -0,0 +1,121 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'+require_relative './shared_context'++describe 'Calendar sharing via ical', js: true do+ include_context 'with calendar full access'++ let!(:user_with_sharing_permission) do+ create :user,+ firstname: 'Bernd',+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages view_calendar manage_calendar save_queries manage_public_queries share_calendars+ ]+ end++ let(:saved_query) do+ create(:query_with_view_work_packages_calendar,+ user: user_with_sharing_permission,+ project:,+ public: false)+ end++ context 'user with sufficient permissions' 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!+ end++ context 'on not persisted calendar query' do++ # it 'shows disabled sharing menu item' do+ # visit project_calendars_path(project)++ # click_link "Create new calendar"++ # # wait for settings button to become visible+ # expect(page).to have_selector("#work-packages-settings-button")++ # # click on settings button+ # page.find("#work-packages-settings-button").click++ # # expect disabled sharing menu item+ # within "#settingsDropdown" do+ # # expect(page).to have_button("Share calendar ...", disabled: true) # disabled selector not working+ # expect(page).to have_selector(".menu-item.inactive", text: "Share calendar ...")+ # page.click_button("Share calendar ...")++ # # modal should not be shown+ # expect(page).not_to have_selector('.spot-modal--header', text: "Share calendar")+ # end++ # end+ end++ context 'on persisted calendar query' do++ it 'shows sharing menu item and sharing modal if clicked' do+ saved_query++ visit project_calendars_path(project)++ within '#content' do+ click_link saved_query.name+ end++ loading_indicator_saveguard++ # wait for settings button to become visible+ expect(page).to have_selector("#work-packages-settings-button")++ # click on settings button+ page.find("#work-packages-settings-button").click++ # expect disabled sharing menu item+ within "#settingsDropdown" do+ # expect(page).to have_button("Share calendar ...", disabled: true) # disabled selector not working+ expect(page).to have_selector(".menu-item", text: "Share calendar ...")+ page.click_button("Share calendar ...")++ end++ expect(page).to have_selector('.spot-modal--header', text: "Share calendar")++ end+ end++ end++enddiff --git a/modules/calendar/spec/routing/calendar_routing_spec.rb b/modules/calendar/spec/routing/calendar_routing_spec.rbindex 3bf5593511c..6ec12551b98 100644--- a/modules/calendar/spec/routing/calendar_routing_spec.rb+++ b/modules/calendar/spec/routing/calendar_routing_spec.rb@@ -48,4 +48,11 @@ describe Calendar::CalendarsController doid: '2',project_id: '1')end++ it do+ expect(get('/projects/1/calendars/2/ical')).to route_to(controller: 'calendar/ical',+ action: 'ical',+ id: '2',+ project_id: '1')+ endenddiff --git a/modules/calendar/spec/routing/ical_routing_spec.rb b/modules/calendar/spec/routing/ical_routing_spec.rbnew file mode 100644index 00000000000..81235ab16c1--- /dev/null+++ b/modules/calendar/spec/routing/ical_routing_spec.rb@@ -0,0 +1,38 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe Calendar::IcalController do+ it do+ expect(get('/projects/1/calendars/2/ical')).to route_to(controller: 'calendar/ical',+ action: 'ical',+ id: '2',+ project_id: '1')+ end+enddiff --git a/modules/calendar/spec/services/create_ical_service_spec.rb b/modules/calendar/spec/services/create_ical_service_spec.rbindex 23327c57541..27df960e69d 100644--- a/modules/calendar/spec/services/create_ical_service_spec.rb+++ b/modules/calendar/spec/services/create_ical_service_spec.rb@@ -31,6 +31,7 @@ require 'spec_helper'describe Calendar::CreateIcalService, type: :model dolet(:project) { create(:project) }+ let(:user) { create(:user) }let(:work_package_without_dates) docreate(:work_package, project: project)@@ -43,11 +44,16 @@ describe Calendar::CreateIcalService, type: :model docreate(:work_package, project: project,start_date: Date.tomorrow, due_date: Date.today+7.days)end+ let(:work_package_with_due_date_and_assignee) do+ create(:work_package, project: project,+ due_date: Date.today+30.days, assigned_to: user )+ endlet(:work_packages) do[work_package_without_dates,work_package_with_due_date,- work_package_with_start_and_due_date+ work_package_with_start_and_due_date,+ work_package_with_due_date_and_assignee]end@@ -78,22 +84,31 @@ DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}ZUID:#{work_package_with_due_date.id}@localhost:3000DTSTART;VALUE=DATE:#{work_package_with_due_date.due_date.strftime('%Y%m%d')}DTEND;VALUE=DATE:#{(work_package_with_due_date.due_date+1.day).strftime('%Y%m%d')}-DESCRIPTION:Project: #{project.name}\nType: 🟩 None\nStatus: #{work_package_with_due_date.status.name}\nAssignee: \nPriority: 🟢 #{work_package_with_due_date.priority.name}\nWork package description: #{work_package_with_due_date.description}+DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_due_date.status.name}\nAssignee: \nPriority: #{work_package_with_due_date.priority.name}\nWork package description: #{work_package_with_due_date.description}LOCATION:http://localhost:3000/work_packages/#{work_package_with_due_date.id}ORGANIZER:Bob BobbitSUMMARY:#{work_package_with_due_date.name}-ATTENDEE:END:VEVENTBEGIN:VEVENTDTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}ZUID:#{work_package_with_start_and_due_date.id}@localhost:3000DTSTART;VALUE=DATE:#{work_package_with_start_and_due_date.start_date.strftime('%Y%m%d')}-DTEND;VALUE=DATE:#{work_package_with_start_and_due_date.due_date.strftime('%Y%m%d')}-DESCRIPTION:Project: #{project.name}\nType: 🟩 None\nStatus: #{work_package_with_start_and_due_date.status.name}\nAssignee: \nPriority: 🟢 #{work_package_with_start_and_due_date.priority.name}\nWork package description: #{work_package_with_start_and_due_date.description}+DTEND;VALUE=DATE:#{(work_package_with_start_and_due_date.due_date+1.day).strftime('%Y%m%d')}+DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_start_and_due_date.status.name}\nAssignee: \nPriority: #{work_package_with_start_and_due_date.priority.name}\nWork package description: #{work_package_with_start_and_due_date.description}LOCATION:http://localhost:3000/work_packages/#{work_package_with_start_and_due_date.id}ORGANIZER:Bob BobbitSUMMARY:#{work_package_with_start_and_due_date.name}-ATTENDEE:+END:VEVENT+BEGIN:VEVENT+DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z+UID:#{work_package_with_due_date_and_assignee.id}@localhost:3000+DTSTART;VALUE=DATE:#{work_package_with_due_date_and_assignee.due_date.strftime('%Y%m%d')}+DTEND;VALUE=DATE:#{(work_package_with_due_date_and_assignee.due_date+1.day).strftime('%Y%m%d')}+DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_due_date_and_assignee.status.name}\nAssignee: #{work_package_with_due_date_and_assignee.assigned_to.name}\nPriority: #{work_package_with_due_date_and_assignee.priority.name}\nWork package description: #{work_package_with_due_date_and_assignee.description}+LOCATION:http://localhost:3000/work_packages/#{work_package_with_due_date_and_assignee.id}+ORGANIZER:Bob Bobbit+SUMMARY:#{work_package_with_due_date_and_assignee.name}+ATTENDEE:#{work_package_with_due_date_and_assignee.assigned_to.name}END:VEVENTEND:VCALENDAREOICALdiff --git a/modules/calendar/spec/services/resolve_and_authorize_query_spec.rb b/modules/calendar/spec/services/resolve_and_authorize_query_spec.rbnew file mode 100644index 00000000000..11741eac1b6--- /dev/null+++ b/modules/calendar/spec/services/resolve_and_authorize_query_spec.rb@@ -0,0 +1,128 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe Calendar::ResolveAndAuthorizeQueryService, type: :model do+ let(:user_1) do+ create(:user,+ member_in_project: project,+ member_with_permissions: sufficient_permissions)+ end+ let(:user_2_without_permission) do+ create(:user,+ member_in_project: project,+ member_with_permissions: insufficient_permissions)+ end+ let(:user_3_not_member) do+ create(:user,+ member_in_project: nil)+ end+ let(:sufficient_permissions) { %i[view_work_packages share_calendars] }+ let(:insufficient_permissions) { %i[view_work_packages] }+ let(:project) { create(:project) }+ let(:query) do+ create(:query,+ project: project,+ user: user_1,+ public: false)+ end++ let(:instance) do+ described_class.new()+ end++ context 'resolves a query by a given query id if authenticated and permitted to share via ical url' do++ before do+ login_as(user_1)+ end++ subject { instance.call(user: user_1, query_id: query.id) }++ it 'returns query as result ' do+ expect(subject.result)+ .to eq query+ end++ it 'is a success' do+ expect(subject)+ .to be_success+ end++ end++ context 'does not a query by a given query id if not authenticated' do++ before do+ login_as(user_2_without_permission)+ end++ subject { instance.call(user: user_2_without_permission, query_id: query.id) }++ it 'raises ActiveRecord::RecordNotFound' do+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)+ end++ end++ context 'does not resolve a query by a given query id if not member of project' do++ before do+ login_as(user_3_not_member)+ end++ subject { instance.call(user: user_3_not_member, query_id: query.id) }++ it 'raises ActiveRecord::RecordNotFound' do+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)+ end++ end++ context 'does not resolve query id is' do++ before do+ login_as(user_1)+ end++ subject { instance.call(user: user_1, query_id: SecureRandom.hex) }++ it 'invalid and raises ActiveRecord::RecordNotFound' do+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)+ end++ subject { instance.call(user: user_1, query_id: nil) }++ it 'nil and raises ActiveRecord::RecordNotFound' do+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)+ end++ end++enddiff --git a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb b/modules/calendar/spec/services/resolve_work_packages_service_spec.rbindex 78e515859b6..9c015931c1a 100644--- a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb+++ b/modules/calendar/spec/services/resolve_work_packages_service_spec.rb@@ -34,15 +34,6 @@ describe Calendar::ResolveWorkPackagesService, type: :model domember_in_project: project,member_with_permissions: permissions)end- let(:user_2_without_permission) do- create(:user,- member_in_project: project,- member_with_permissions: [])- end- let(:user_3_not_member) do- create(:user,- member_in_project: nil)- endlet(:permissions) { %i[view_work_packages] }let(:project) { create(:project, work_packages: [work_package_1]) }let(:work_package_1) { create(:work_package) }@@ -57,13 +48,13 @@ describe Calendar::ResolveWorkPackagesService, type: :model dodescribed_class.new()end- context 'resolves work_packages of a query by a given query id if authenticated' do+ context 'resolves work_packages of a query' dobefore dologin_as(user_1)end- subject { instance.call(user: user_1, query_id: query.id) }+ subject { instance.call(query: query) }it 'returns work_packages of query as result ' doexpect(subject.result)@@ -76,48 +67,14 @@ describe Calendar::ResolveWorkPackagesService, type: :model doendend-- context 'does not resolve work_packages of a query by a given query id if not authenticated' do- before do- login_as(user_2_without_permission)- end-- subject { instance.call(user: user_2_without_permission, query_id: query.id) }-- it 'raises ActiveRecord::RecordNotFound' do- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)- end-- end-- context 'does not resolve work_packages of a query by a given query id if not member of project' do-- before do- login_as(user_3_not_member)- end-- subject { instance.call(user: user_3_not_member, query_id: query.id) }-- it 'raises ActiveRecord::RecordNotFound' do- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)- end-- end-- context 'does not resolve work_packages if query id is' do+ context 'does not resolve work_packages if query is' dobefore dologin_as(user_1)end- subject { instance.call(user: user_1, query_id: SecureRandom.hex) }-- it 'invalid and raises ActiveRecord::RecordNotFound' do- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)- end-- subject { instance.call(user: user_1, query_id: nil) }+ subject { instance.call(query: nil) }it 'nil and raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)diff --git a/spec/policies/query_policy_spec.rb b/spec/policies/query_policy_spec.rbindex be90d7303c3..380d0631c41 100644--- a/spec/policies/query_policy_spec.rb+++ b/spec/policies/query_policy_spec.rb@@ -378,6 +378,25 @@ describe QueryPolicy, type: :controller doendend+ shared_examples 'share via ical' do |global|+ context (global ? 'in global context' : 'in project context').to_s do+ if global+ let(:project) { nil }+ end++ it 'is false if the user has no permission in the project' do+ allow(user).to receive(:allowed_to?).with(+ :share_calendars,+ project,+ global: project.nil?+ )+ .and_return false++ expect(subject.allowed?(query, :share_via_ical)).to be_falsy+ end+ end+ end+it_behaves_like 'action on persisted', :update, global: trueit_behaves_like 'action on persisted', :update, global: falseit_behaves_like 'action on persisted', :destroy, global: true@@ -394,5 +413,9 @@ describe QueryPolicy, type: :controller doit_behaves_like 'action on persisted', :unstar, global: trueit_behaves_like 'viewing queries', global: trueit_behaves_like 'viewing queries', global: false+ # TODO: should this be better done in 'action on persisted' context?+ # I'm not sure if the action on persisted perrmission dependecies apply to the share via ical context+ it_behaves_like 'share via ical', global: true+ it_behaves_like 'share via ical', global: falseendend