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
introducing a new ical token which may exist n times per user
Jonas Jabaria21e6c620743
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rbindex f6711bd12b4..c6b504036ab 100644--- a/app/controllers/my_controller.rb+++ b/app/controllers/my_controller.rb@@ -129,6 +129,15 @@ class MyController < ApplicationControllerredirect_to action: 'access_token'end+ def revoke_all_ical_tokens+ Token::Ical.where(user: current_user).destroy_all+ rescue StandardError => e+ Rails.logger.error "Failed to revoke all ical tokens for ##{current_user.id}: #{e}"+ flash[:error] = t('my.access_token.failed_to_reset_token', error: e.message)+ ensure+ redirect_to action: 'access_token'+ end+def default_breadcrumbI18n.t(:label_my_account)end@@ -169,7 +178,7 @@ class MyController < ApplicationControllerhelper_method :has_tokens?def has_tokens?- Setting.feeds_enabled? || Setting.rest_api_enabled?+ Setting.feeds_enabled? || Setting.rest_api_enabled? || Token::Ical.where(user: current_user).any?enddef set_current_userdiff --git a/app/models/token/ical.rb b/app/models/token/ical.rbnew file mode 100644index 00000000000..24331672b9b--- /dev/null+++ b/app/models/token/ical.rb@@ -0,0 +1,41 @@+#-- 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 Token+ class Ical < HashedToken++ # Prevent deleting previous tokens+ # Every time an ical url is generated, a new ical token will be generated for this url as well+ # the existing ical tokens (and thus urls) should still be valid+ # until the user decides to revert all existing ical tokens (and urls)+ def delete_previous_token+ nil+ end++ end+enddiff --git a/app/views/my/access_token.html.erb b/app/views/my/access_token.html.erbindex dea686742fb..f760fc58184 100644--- a/app/views/my/access_token.html.erb+++ b/app/views/my/access_token.html.erb@@ -109,6 +109,23 @@ See COPYRIGHT and LICENSE files for more details.</tr><% end %><% end %>+ <% if Token::Ical.where(user: current_user).any? %>+ <tr>+ <td>iCal</td>+ <td>+ <span title="<%= format_time(Token::Ical.where(user: current_user).last.created_at) %>">+ <%= format_time(Token::Ical.where(user: current_user).last.created_at.to_s) %> (latest)+ </span>+ </td>+ <td><%= I18n.t('my_account.access_tokens.indefinite_expiration') %></td>+ <td>+ <%= link_to 'Revoke all',+ { action: 'revoke_all_ical_tokens' },+ method: :delete,+ class: 'icon icon-delete' %>+ </td>+ </tr>+ <% end %><% if Setting.rest_api_enabled? %><% if @user.api_token %><tr>diff --git a/config/routes.rb b/config/routes.rbindex 81ddcaa63a6..4f8f5f05900 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -551,6 +551,7 @@ OpenProject::Application.routes.draw dopost '/my/generate_rss_key', action: 'generate_rss_key'post '/my/generate_api_key', action: 'generate_api_key'+ delete '/my/revoke_all_ical_tokens', action: 'revoke_all_ical_tokens'get '/my/access_token', action: 'access_token'end