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
Initial mess
Marcello Rocha22d128a8f70d
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rbindex 68c532e24b8..ef582c2df53 100644--- a/app/controllers/my_controller.rb+++ b/app/controllers/my_controller.rb@@ -78,7 +78,27 @@ class MyController < ApplicationControllerend# Administer access tokens- def access_token; end+ def access_token+ @storage_tokens = OAuthClientToken+ .preload(:oauth_client)+ .joins(:oauth_client)+ .where(user: @user, oauth_client: { integration_type: 'Storages::Storage' })+ end++ def delete_storage_token+ token = OAuthClientToken+ .preload(:oauth_client)+ .joins(:oauth_client)+ .where(user: @user, oauth_client: { integration_type: 'Storages::Storage' }).find_by(id: params[:id])++ if token&.destroy+ # TODO i18n this+ flash[:notice] = I18n.t('my.access_tokens.storages.removed')+ else+ flash[:error] = I18n.t('my.access_tokens.storages.failed')+ end+ redirect_to action: :access_token+ end# Configure user's in app notificationsdef notificationsdiff --git a/app/views/my/access_token.html.erb b/app/views/my/access_token.html.erbindex 6b777d72257..226f212728f 100644--- a/app/views/my/access_token.html.erb+++ b/app/views/my/access_token.html.erb@@ -46,6 +46,9 @@ See COPYRIGHT and LICENSE files for more details.<%= render partial: 'my/access_token_partials/rss_tokens_section',locals: { rss_token: @user.rss_token }%>+ <%= render partial: 'my/access_token_partials/storage_tokens_section',+ locals: { storage_tokens: @storage_tokens }+ %><div class="generic-table--container"><div class="generic-table--results-container"><table class="generic-table">diff --git a/app/views/my/access_token_partials/_oauth_tokens_section.html.erb b/app/views/my/access_token_partials/_oauth_tokens_section.html.erbindex 9d45c581275..1b8cb30840b 100644--- a/app/views/my/access_token_partials/_oauth_tokens_section.html.erb+++ b/app/views/my/access_token_partials/_oauth_tokens_section.html.erb@@ -85,5 +85,3 @@ See COPYRIGHT and LICENSE files for more details.<% end %></div></div>--diff --git a/app/views/my/access_token_partials/_storage_tokens_section.html.erb b/app/views/my/access_token_partials/_storage_tokens_section.html.erbnew file mode 100644index 00000000000..1edb509c75f--- /dev/null+++ b/app/views/my/access_token_partials/_storage_tokens_section.html.erb@@ -0,0 +1,83 @@+<%#-- 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.++++#%>+<div class="attributes-group" id="storage-token-section">+ <div class="attributes-group--header">+ <div class="attributes-group--header-container">+ <h3 class="attributes-group--header-text"><%= t("my_account.access_tokens.storages.title") %></h3>+ </div>+ </div>+ <div>+ <p>+ <%= t("my_account.access_tokens.storages.text_hint") %>+ </p>+ <% if @storage_tokens.any? %>+ <div class="generic-table--container">+ <div class="generic-table--results-container">+ <table class="generic-table">+ <%= render partial: "my/access_token_partials/token_table_header",+ locals: {+ column_headers: [+ t('attributes.name'),+ User.human_attribute_name(:created_at),+ t('my_account.access_tokens.headers.expiration')+ ]+ }+ %>+ <tbody>+ <% storage_tokens.each do |token| %>+ <tr id="storage-oauth-token-<%= token.id %>">+ <td class="-w-rel-60" data-qa-selector="oauth-token-row-<%= token.oauth_client.integration.id %>-name">+ <%= token.oauth_client.integration.name %>+ </td>+ <td>+ <span><%= format_time(token.created_at) %></span>+ </td>+ <td>+ <span><%= format_time(token.created_at + token.expires_in.seconds) %></span>+ </td>+ <td class="buttons">+ <%= link_to "",+ storage_token_delete_path(token.id),+ data: { confirm: t('my_account.access_tokens.storages.revoke_token', storage: token.oauth_client.integration.name),+ qa_selector: "storages-token-row-#{token.id}-revoke" },+ method: :delete,+ class: 'icon icon-delete' %>+ </td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+ </div>+ <% else %>+ <span class="spot-icon spot-icon_inline spot-icon_info1"></span>+ <i><%= t('my_account.access_tokens.storages.empty_text_hint') %></i>+ <% end %>+ </div>+</div>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 5280a0232e0..78feffa54c8 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1562,6 +1562,12 @@ en:text_hint: "RSS tokens allow users to keep up with the latest changes in this OpenProject instance via an external RSS reader."static_token_name: "RSS token"disabled_text: "RSS tokens are not enabled by the administrator. Please contact your administrator to use this feature."+ storages:+ title: "File Storages"+ text_hint: "File Storage tokens connect this OpenProject instance with an external File Storage."+ empty_text_hint: "There is no storage access linked to your account."+ revoke_token: "Do you really want to remove this token? You will need to login again on %{storage}"+notifications:send_notifications: "Send notifications for this action"diff --git a/config/routes.rb b/config/routes.rbindex 1b53e7197d7..5f4cad2e22c 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -552,6 +552,7 @@ OpenProject::Application.routes.draw doscope 'my' doget '/deletion_info' => 'users#deletion_info', as: 'delete_my_account_info'post '/oauth/revoke_application/:application_id' => 'oauth/grants#revoke_application', as: 'revoke_my_oauth_application'+ delete '/storage_token/:id' => 'my#delete_storage_token', as: 'storage_token_delete'resources :sessions, controller: 'my/sessions', as: 'my_sessions', only: %i[index show destroy]enddiff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rbindex 808223bbb34..aabd7911424 100644--- a/spec/controllers/my_controller_spec.rb+++ b/spec/controllers/my_controller_spec.rb@@ -345,5 +345,21 @@ RSpec.describe MyController doendendend++ describe 'file storage' do+ let(:client) { create(:oauth_client, integration: create(:nextcloud_storage)) }+ let(:token) { create(:oauth_client_token, oauth_client: client, scope: nil, user:, expires_in: 3_600) }++ render_views++ before { token }++ it 'list the tokens' do+ get :access_token+ expect(response.body).to have_selector("#storage-oauth-token-#{token.id}")+ end++ it 'can remove the token'+ endendend