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
Remove many case statements and move ical token into meetings module
Klaus Zanders676651afd849
diff --git a/app/components/my/access_token/access_token_created_dialog_component.html.erb b/app/components/my/access_token/access_token_created_dialog_component.html.erbindex f1b37b71ac2..89ea8ac967d 100644--- a/app/components/my/access_token/access_token_created_dialog_component.html.erb+++ b/app/components/my/access_token/access_token_created_dialog_component.html.erb@@ -55,10 +55,10 @@ See COPYRIGHT and LICENSE files for more details.name: :openproject_api_access_token,label: token.model_name.human,visually_hide_label: false,- value: private_token_value+ value: token.display_value)input_group.with_trailing_action_clipboard_copy_button(- value: private_token_value,+ value: token.display_value,aria: {label: I18n.t("button_copy_to_clipboard")}diff --git a/app/components/my/access_token/access_token_created_dialog_component.rb b/app/components/my/access_token/access_token_created_dialog_component.rbindex b1770045710..396c13ea5f4 100644--- a/app/components/my/access_token/access_token_created_dialog_component.rb+++ b/app/components/my/access_token/access_token_created_dialog_component.rb@@ -47,23 +47,8 @@ module My"#{token.model_name.element}-created-dialog"end- def private_token_value- case token- when Token::API- token.plain_value- when Token::ICalMeeting- ical_feed_meetings_url(token: token.plain_value, format: :ics)- else- raise ArgumentError, "Unknown token type: #{token.class}"- end- end-def i18n_scope- case token- when Token::API then "my.access_token.created_dialog.api"- when Token::ICalMeeting then "my.access_token.created_dialog.ical_meeting"- else raise ArgumentError, "Unknown token type: #{token_type}"- end+ [:my, :access_token, :created_dialog, token.model_name.i18n_key]endendenddiff --git a/app/components/my/access_token/api_tokens_section_component.rb b/app/components/my/access_token/api_tokens_section_component.rbindex 2893e7f3275..23cb48834f0 100644--- a/app/components/my/access_token/api_tokens_section_component.rb+++ b/app/components/my/access_token/api_tokens_section_component.rb@@ -51,11 +51,7 @@ module Myenddef i18n_scope- case token_type.to_s- when "Token::API" then "my_account.access_tokens.api"- when "Token::ICalMeeting" then "my_account.access_tokens.ical_meeting"- else raise ArgumentError, "Unknown token type: #{token_type}"- end+ [:my_account, :access_tokens, token_type.model_name.i18n_key]enddef token_available?@@ -68,9 +64,8 @@ module Mydef add_button_iconcase token_type.to_s- when "Token::API" then :pluswhen "Token::ICalMeeting" then :rss- else raise ArgumentError, "Unknown token type: #{token_type}"+ else :plusendendenddiff --git a/app/components/my/access_token/new_access_token_dialog_component.rb b/app/components/my/access_token/new_access_token_dialog_component.rbindex d5295f8dd94..a9bc0fb7661 100644--- a/app/components/my/access_token/new_access_token_dialog_component.rb+++ b/app/components/my/access_token/new_access_token_dialog_component.rb@@ -52,11 +52,7 @@ module Myenddef i18n_scope- case new_token- when Token::API then "my.access_token.dialog.api"- when Token::ICalMeeting then "my.access_token.dialog.ical_meeting"- else raise ArgumentError, "Unknown token type: #{token_type}"- end+ [:my, :access_token, :dialog, new_token.model_name.i18n_key]endendenddiff --git a/app/components/my/access_token/new_access_token_form.rb b/app/components/my/access_token/new_access_token_form.rbindex b1327b6d593..8e58b929a7b 100644--- a/app/components/my/access_token/new_access_token_form.rb+++ b/app/components/my/access_token/new_access_token_form.rb@@ -46,11 +46,7 @@ module Myprivatedef i18n_scope- case model- when Token::API then "my.access_token.dialog.api"- when Token::ICalMeeting then "my.access_token.dialog.ical_meeting"- else raise ArgumentError, "Unknown token type: #{token_type}"- end+ [:my, :access_token, :dialog, model.model_name.i18n_key]endendenddiff --git a/app/components/my/access_token/new_access_token_form_component.html.erb b/app/components/my/access_token/new_access_token_form_component.html.erbindex 30f1489aaa7..df404d8d205 100644--- a/app/components/my/access_token/new_access_token_form_component.html.erb+++ b/app/components/my/access_token/new_access_token_form_component.html.erb@@ -42,7 +42,7 @@ See COPYRIGHT and LICENSE files for more details.)) doflex_layout(mb: 3) do |body|- if show_warning?+ if I18n.t(:attention_text, scope: i18n_scope, default: nil).present?body.with_row(mb: 3) dorender(Primer::Alpha::Banner.new(scheme: :warning)) doI18n.t(:attention_text, scope: i18n_scope)diff --git a/app/components/my/access_token/new_access_token_form_component.rb b/app/components/my/access_token/new_access_token_form_component.rbindex a6fe9fe682f..969dc15f03f 100644--- a/app/components/my/access_token/new_access_token_form_component.rb+++ b/app/components/my/access_token/new_access_token_form_component.rb@@ -45,20 +45,7 @@ module Myprivatedef i18n_scope- case token- when Token::API then "my.access_token.dialog.api"- when Token::ICalMeeting then "my.access_token.dialog.ical_meeting"- else raise ArgumentError, "Unknown token type: #{token_type}"- end- end-- def show_warning?- case token- when Token::API then true- when Token::ICalMeeting then false- else- raise ArgumentError, "Unknown token type: #{token_type}"- end+ [:my, :access_token, :dialog, token.model_name.i18n_key]endendenddiff --git a/app/models/token/base.rb b/app/models/token/base.rbindex 61b79f18b5b..415cd6ca11b 100644--- a/app/models/token/base.rb+++ b/app/models/token/base.rb@@ -82,6 +82,12 @@ module TokenSecureRandom.hex(32)end+ ##+ # Get the value for the token.+ def display_value+ value+ end+protected##diff --git a/app/models/token/hashed_token.rb b/app/models/token/hashed_token.rbindex c153833bcfd..45dfe842f0a 100644--- a/app/models/token/hashed_token.rb+++ b/app/models/token/hashed_token.rb@@ -67,6 +67,10 @@ module Tokenendend+ def display_value+ plain_value.presence || I18n.t("token.hashed_token.display_value_placeholder")+ end+### Validate the user input on the token# 1. The token is still validdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 4b08d5915bf..23f0f3dccab 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -616,30 +616,16 @@ en:my:access_token:dialog:- api:+ token/api:dialog_title: "Create new API token"attention_text: "Treat API tokens like passwords. Anyone with this token will have access to information from this instance, share it only with trusted users."dialog_body: "This token will allow third-party applications to communicate with your instance. To differentiate the new API token, please give it a name."create_button: "Create"name_label: "Token name"- ical_meeting:- dialog_title: "New iCal subscription token for meetings"- dialog_body: "This token will generate an iCal subscription URL that lets you view all your meetings in an external calendar application."- create_button: "Create subscription"- name_label: "Token name"- name_caption: 'You can name it after where you will use it, such as"My phone" or "Work computer.'created_dialog:- api:+ token/api:title: "The API token has been generated"warning: "This is the only time you will see this token. Make sure to copy it now."- ical_meeting:- title: "An iCal meeting subscription token has been generated"- body: "Treat the following URL as you would a password. Anyone who has access to it can view all your meetings."- warning: "This is the only time you will see this token. Make sure to copy it now."- revocation:- ical_meeting:- notice_success: "The iCalendar meeting subscription has been revoked successfully."- notice_failure: "Failed to revoke iCalendar meeting subscription: %{error}"errors:token_name_blank: "Please provide an API token name"token_name_in_use: "This API token name is already in use, please select a different one"@@ -648,11 +634,10 @@ en:failed_to_revoke_token: "Failed to revoke access token: %{error}"notice_reset_token: "A new %{type} token has been generated. Your access token is:"token_value_warning: "Note: This is the only time you will see this token, make sure to copy it now."- no_results_title_text: There are currently no access tokens available.+ no_results_title_text: "There are currently no access tokens available."notice_api_token_revoked: "The API token has been deleted. To create a new token please use the button in the API section."notice_rss_token_revoked: "The RSS token has been deleted. To create a new token please use the link in the RSS section."notice_ical_token_revoked: 'iCalendar token "%{token_name}" for calendar "%{calendar_name}" of project "%{project_name}" has been revoked. The iCalendar URL with this token is now invalid.'- new_ical_meeting_token_dialog_show_button_text: "iCalendar subscription"news:index:@@ -1756,9 +1741,6 @@ en:token/api:one: Access tokenother: Access tokens- token/ical_meeting:- one: "iCal Meeting subscription"- other: "iCal Meeting subscription"type: "Type"user: "User"version: "Version"@@ -2728,7 +2710,7 @@ en:expiration: "Expires"indefinite_expiration: "Never"simple_revoke_confirmation: "Are you sure you want to revoke this token?"- api:+ token/api:title: "API"text_hint: "API tokens allow third-party applications to communicate with this OpenProject instance via REST APIs."static_token_name: "API token"@@ -2739,12 +2721,6 @@ en:text_hint: 'iCalendar tokens allow users to <a href="%{path}" target="_blank">subscribe to OpenProject calendars</a> and view up-to-date work package information from external clients.'disabled_text: "iCalendar subscriptions are not enabled by the administrator. Please contact your administrator to use this feature."empty_text_hint: "To add an iCalendar token, subscribe to a new or existing calendar from within the Calendar module of a project. You must have the necessary permissions."- ical_meeting:- title: "iCalendar for meetings"- text_hint: "iCalendar meeting tokens allow users to subscribe to all their meetings and view up-to-date meeting information in external clients."- disabled_text: "iCalendar meeting subscriptions are not enabled by the administrator. Please contact your administrator to use this feature."- empty_text_hint: 'To add an iCalendar meeting token, go to the <a href="%{path}">meetings section</a> and subscribe from there.'- add_button: "Subscribe to calendar"oauth:title: "OAuth"text_hint: "OAuth tokens allow third-party applications to connect with this OpenProject instance."@@ -5074,3 +5050,7 @@ en:enterprise_plans:legacy_enterprise: "Enterprise Plan"++ token:+ hashed_token:+ display_value_placeholder: "***"diff --git a/app/models/token/ical_meeting.rb b/modules/meeting/app/models/token/ical_meeting.rbsimilarity index 76%rename from app/models/token/ical_meeting.rbrename to modules/meeting/app/models/token/ical_meeting.rbindex e3f238a153d..e433662cfd2 100644--- a/app/models/token/ical_meeting.rb+++ b/modules/meeting/app/models/token/ical_meeting.rb@@ -30,12 +30,27 @@module Tokenclass ICalMeeting < HashedToken+ include OpenProject::StaticRouting::UrlHelpers+ include ActionView::Helpers::UrlHelper+store_attribute :data, :token_name, :string+ def display_value+ if plain_value.present?+ url_helpers.ical_feed_meetings_url(token: plain_value, format: :ics)+ else+ I18n.t("token.hashed_token.display_value_placeholder")+ end+ end+privatedef single_value?falseend++ def url_helpers+ @url_helpers ||= OpenProject::StaticRouting::StaticUrlHelpers.new+ endendenddiff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.ymlindex c319580b226..b06fee0891d 100644--- a/modules/meeting/config/locales/en.yml+++ b/modules/meeting/config/locales/en.yml@@ -86,6 +86,9 @@ en:meeting_agenda_item: "Agenda item"meeting_agenda: "Agenda"meeting_section: "Section"+ token/ical_meeting:+ one: "iCal Meeting subscription"+ other: "iCal Meeting subscription"activity:filter:@@ -595,3 +598,31 @@ en:text_email_updates_muted: "Email calendar updates are muted. Participants will not receive updated invites via email when you make changes."text_email_updates_enabled: "Email calendar updates are enabled. All participants will receive updated invites via email when you make changes."++ my_account:+ access_tokens:+ token/ical_meeting:+ title: "iCalendar for meetings"+ text_hint: "iCalendar meeting tokens allow users to subscribe to all their meetings and view up-to-date meeting information in external clients."+ disabled_text: "iCalendar meeting subscriptions are not enabled by the administrator. Please contact your administrator to use this feature."+ empty_text_hint: 'To add an iCalendar meeting token, go to the <a href="%{path}">meetings section</a> and subscribe from there.'+ add_button: "Subscribe to calendar"++ my:+ access_token:+ dialog:+ token/ical_meeting:+ dialog_title: "New iCal subscription token for meetings"+ dialog_body: "This token will generate an iCal subscription URL that lets you view all your meetings in an external calendar application."+ create_button: "Create subscription"+ name_label: "Token name"+ name_caption: 'You can name it after where you will use it, such as"My phone" or "Work computer.'+ created_dialog:+ token/ical_meeting:+ title: "An iCal meeting subscription token has been generated"+ body: "Treat the following URL as you would a password. Anyone who has access to it can view all your meetings."+ warning: "This is the only time you will see this token. Make sure to copy it now."+ revocation:+ token/ical_meeting:+ notice_success: "The iCalendar meeting subscription has been revoked successfully."+ notice_failure: "Failed to revoke iCalendar meeting subscription: %{error}"diff --git a/modules/meeting/spec/factories/token_factory.rb b/modules/meeting/spec/factories/token_factory.rbnew file mode 100644index 00000000000..8fb73eeb129--- /dev/null+++ b/modules/meeting/spec/factories/token_factory.rb@@ -0,0 +1,38 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 "securerandom"++FactoryBot.define do+ factory :ical_meeting_token, class: "::Token::ICalMeeting" do+ user+ sequence(:token_name) { |n| "My Meetings Calendar #{n}" }+ end+enddiff --git a/spec/factories/token_factory.rb b/spec/factories/token_factory.rbindex 05489917388..9aa865b828d 100644--- a/spec/factories/token_factory.rb+++ b/spec/factories/token_factory.rb@@ -85,9 +85,4 @@ FactoryBot.define doical_token: token)endend-- factory :ical_meeting_token, class: "::Token::ICalMeeting" do- user- token_name { "My Meetings Calendar" }- endend