parent
2869ee24be
commit
38ef24a9cf
@ -0,0 +1,5 @@ |
||||
class AddPolymorphicIntegrationToOAuthApplication < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_reference :oauth_applications, :integration, polymorphic: true |
||||
end |
||||
end |
@ -0,0 +1,33 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2022 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. |
||||
#++ |
||||
|
||||
# This patch adds an optional polymorphic relation to OAuth applications. |
||||
|
||||
Doorkeeper::Application.class_eval do |
||||
belongs_to :integration, polymorphic: true |
||||
end |
@ -0,0 +1,58 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2022 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. |
||||
#++ |
||||
|
||||
# The logic for creating storage was extracted from the controller and put into |
||||
# a service: https://dev.to/joker666/ruby-on-rails-pattern-service-objects-b19 |
||||
# Purpose: create and persist a Storages::Storage record |
||||
# Used by: Storages::Admin::StoragesController#create, could also be used by the |
||||
# API in the future. |
||||
# Reference: https://www.openproject.org/docs/development/concepts/contracted-services/ |
||||
# The comments here are also valid for the other *_service.rb files |
||||
module Storages::OAuthApplications |
||||
class CreateService |
||||
attr_accessor :user, :storage |
||||
|
||||
def initialize(storage:, user:) |
||||
@storage = storage |
||||
@user = user |
||||
end |
||||
|
||||
def call |
||||
::OAuth::PersistApplicationService |
||||
.new(::Doorkeeper::Application.new, user:) |
||||
.call({ |
||||
name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage.provider_type}")})", |
||||
redirect_uri: File.join(storage.host, "apps/integration_openproject/oauth-redirect"), |
||||
scopes: '', |
||||
confidential: true, |
||||
owner: storage.creator, |
||||
integration: storage |
||||
}) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,46 @@ |
||||
<!-- Standard Ruby view, please see the controller for comments --> |
||||
<% html_title t(:label_administration), t("project_module_storages"), @object.name, "#{t("storages.provider_types.#{@object.provider_type}")} #{t("storages.label_oauth_application_details")}" %> |
||||
<% local_assigns[:additional_breadcrumb] = "#{t("storages.provider_types.#{@object.provider_type}")} #{t("storages.label_oauth_application_details")}" %> |
||||
<%= toolbar title: "#{t("storages.provider_types.#{@object.provider_type}")} #{t("storages.label_oauth_application_details")}" %> |
||||
|
||||
<%= labelled_tabular_form_for @oauth_application, url: '/' do |f| -%> |
||||
<div class="form--field"> |
||||
<%= f.text_field :uid, |
||||
label: t('storages.label_oauth_client_id'), |
||||
size: 40, |
||||
container_class: '-wide', |
||||
disabled: true, |
||||
id: 'client_id' %> |
||||
<% csp_onclick('this.focus(); this.select();', '#client_id') %> |
||||
<copy-to-clipboard click-target=".client-id-copy-button" |
||||
clipboard-target="#client_id"> |
||||
</copy-to-clipboard> |
||||
<button class="client-id-copy-button toolbar-input--affix toolbar-input-group--affix -append" |
||||
title="<%= t(:label_copy_to_clipboard) %>"> |
||||
<%= op_icon('icon-copy') %> |
||||
<span class="hidden-for-sighted"><%= t(:label_copy_to_clipboard) %></span> |
||||
</button> |
||||
</div> |
||||
<div class="form--field"> |
||||
<%= f.text_field :plaintext_secret, |
||||
label: t('storages.label_oauth_client_secret'), |
||||
size: 40, |
||||
container_class: '-wide', |
||||
disabled: true, |
||||
id: 'secret' %> |
||||
<% csp_onclick('this.focus(); this.select();', '#secret') %> |
||||
<copy-to-clipboard click-target=".secret-copy-button" |
||||
clipboard-target="#secret"> |
||||
</copy-to-clipboard> |
||||
<button class="secret-copy-button toolbar-input--affix toolbar-input-group--affix -append" |
||||
title="<%= t(:label_copy_to_clipboard) %>"> |
||||
<%= op_icon('icon-copy') %> |
||||
<span class="hidden-for-sighted"><%= t(:label_copy_to_clipboard) %></span> |
||||
</button> |
||||
</div> |
||||
<% if @object.oauth_client %> |
||||
<%= link_to t("storages.buttons.done_continue_setup"), admin_settings_storage_path(@object), class: "-highlight -with-icon icon-checkmark button" %> |
||||
<% else %> |
||||
<%= link_to t("storages.buttons.done_continue_setup"), new_admin_settings_storage_oauth_client_path(@object), class: "-highlight -with-icon icon-checkmark button" %> |
||||
<% end %> |
||||
<% end %> |
Loading…
Reference in new issue