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
starting UI implementation towards generating the ical url
Jonas Jabarib9ac4d594771
diff --git a/modules/calendar/app/cells/calendar/row_cell.rb b/modules/calendar/app/cells/calendar/row_cell.rbindex ca2b5fad5da..0c638bbc145 100644--- a/modules/calendar/app/cells/calendar/row_cell.rb+++ b/modules/calendar/app/cells/calendar/row_cell.rb@@ -46,7 +46,19 @@ module Calendarenddef button_links- [delete_link].compact+ [share_link, delete_link].compact+ end++ def share_link+ if table.current_user.allowed_to?(:share_calendars, project)+ link_to(+ '',+ generate_ical_url_project_calendar_path(project, query.id),+ method: :post,+ class: 'icon icon-link', # TODO: use proper share icon+ title: "Share via iCal" # TODO: use translations+ )+ endenddef delete_linkdiff --git a/modules/calendar/app/controllers/calendar/calendars_controller.rb b/modules/calendar/app/controllers/calendar/calendars_controller.rbindex e9b920f091c..8075ef26011 100644--- a/modules/calendar/app/controllers/calendar/calendars_controller.rb+++ b/modules/calendar/app/controllers/calendar/calendars_controller.rb@@ -42,6 +42,30 @@ module ::Calendarrender layout: 'angular/angular'end+ def generate_ical_url+ begin+ call = ::Calendar::GenerateIcalUrl.new().call(+ user: current_user,+ query_id: params[:id],+ project_id: @project.id+ )+ rescue ActiveRecord::RecordNotFound+ render_404+ return+ end++ if call.present? && call.success?+ # TODO: Use translations+ flash[:info] = "+ You can share and import this calendar by using the following iCalendar URL:+ #{call.result}+ "+ redirect_to action: :index+ else+ render_404+ end+ end+def icalbegincall = ::Calendar::IcalResponseService.new().call(@@ -58,7 +82,6 @@ module ::Calendarelserender_404end-enddef destroydiff --git a/modules/calendar/app/services/calendar/generate_ical_url.rb b/modules/calendar/app/services/calendar/generate_ical_url.rbnew file mode 100644index 00000000000..cfc36111392--- /dev/null+++ b/modules/calendar/app/services/calendar/generate_ical_url.rb@@ -0,0 +1,79 @@+#-- 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 GenerateIcalUrl < ::BaseServices::BaseCallable+ include OpenProject::StaticRouting::UrlHelpers++ def perform(user:, query_id:, project_id:)+ new_ical_token = create_ical_token(user)+ new_ical_url = create_ical_url(query_id, project_id, new_ical_token)++ ServiceResult.success(result: new_ical_url)+ end++ protected++ def create_ical_token(user)+ Token::Ical.create_and_return_value(user)+ end++ def create_ical_url(query_id, project_id, ical_token)+ url_for(+ controller: "calendar/calendars",+ action: :ical,+ id: query_id,+ project_id: project_id,+ ical_token: ical_token,+ only_path: false,+ protocol: protocol,+ host: host+ )+ end+ # implementation taken from application_mailer+ def host+ if OpenProject::Configuration.rails_relative_url_root.blank?+ Setting.host_name+ else+ Setting.host_name.to_s.gsub(%r{/.*\z}, '')+ end+ end++ # implementation taken from application_mailer+ def protocol+ Setting.protocol+ end++ # # url_for wants to access the controller method, which we do not have in our service class.+ # # see: http://stackoverflow.com/questions/3659455/is-there-a-new-syntax-for-url-for-in-rails-3+ # def controller+ # nil+ # 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 febf31f6058..18fdf32f95d 100644--- a/modules/calendar/app/services/calendar/resolve_ical_user_service.rb+++ b/modules/calendar/app/services/calendar/resolve_ical_user_service.rb@@ -34,8 +34,7 @@ module Calendarraise ActiveRecord::RecordNotFoundend- # TODO: do it properly with new ICAL token- token = Token::API.find_by_plaintext_value(ical_token)+ token = Token::Ical.find_by_plaintext_value(ical_token)if token.present?user = token.userServiceResult.success(result: user)diff --git a/modules/calendar/config/locales/en.yml b/modules/calendar/config/locales/en.ymlindex fea0e704a98..5dbeefcf815 100644--- a/modules/calendar/config/locales/en.yml+++ b/modules/calendar/config/locales/en.yml@@ -3,4 +3,5 @@ en:label_calendar_plural: "Calendars"permission_view_calendar: "View calendars"permission_manage_calendars: "Manage calendars"+ permission_share_calendars: "Share calendars"project_module_calendar_view: "Calendar"diff --git a/modules/calendar/config/routes.rb b/modules/calendar/config/routes.rbindex c4a09221a2e..f249ee25172 100644--- a/modules/calendar/config/routes.rb+++ b/modules/calendar/config/routes.rb@@ -6,8 +6,10 @@ OpenProject::Application.routes.draw doas: :calendars doget '/new' => 'calendar/calendars#show', on: :collection, as: 'new'# TODO: discuss if other controller should be used- get '/ics' => 'calendar/calendars#ical', on: :member, as: 'ical'+ post '/generate_ical_url' => 'calendar/calendars#generate_ical_url', on: :member, as: 'generate_ical_url'+ # TODO: discuss if other controller should be used+ get '/ical' => 'calendar/calendars#ical', on: :member, as: 'ical'get '(/*state)' => 'calendar/calendars#show', on: :member, as: ''endend-end+end\ No newline at end of filediff --git a/modules/calendar/lib/open_project/calendar/engine.rb b/modules/calendar/lib/open_project/calendar/engine.rbindex 249a4128964..99cbb3f2979 100644--- a/modules/calendar/lib/open_project/calendar/engine.rb+++ b/modules/calendar/lib/open_project/calendar/engine.rb@@ -36,6 +36,10 @@ module OpenProject::Calendar{ 'calendar/calendars': %i[index show new destroy] },dependencies: %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] }endmenu :project_menu,diff --git a/modules/calendar/spec/services/create_ical_service_spec.rb b/modules/calendar/spec/services/create_ical_service_spec.rbindex c49c3ada564..23327c57541 100644--- a/modules/calendar/spec/services/create_ical_service_spec.rb+++ b/modules/calendar/spec/services/create_ical_service_spec.rb@@ -50,7 +50,6 @@ describe Calendar::CreateIcalService, type: :model dowork_package_with_start_and_due_date]end-let(:instance) dodescribed_class.new()