mirror of https://github.com/docusealco/docuseal
parent
3dcb7c813f
commit
6253e80a70
@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TestingAccountsController < ApplicationController
|
||||
skip_authorization_check only: :destroy
|
||||
|
||||
def show
|
||||
authorize!(:manage, current_account)
|
||||
authorize!(:manage, current_user)
|
||||
|
||||
impersonate_user(Accounts.find_or_create_testing_user(current_account))
|
||||
|
||||
redirect_back(fallback_location: root_path)
|
||||
end
|
||||
|
||||
def destroy
|
||||
stop_impersonating_user
|
||||
|
||||
redirect_back(fallback_location: root_path)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TestingApiSettingsController < ApplicationController
|
||||
def index
|
||||
authorize!(:manage, current_user.access_token)
|
||||
|
||||
@webhook_config =
|
||||
current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
|
||||
|
||||
authorize!(:manage, @webhook_config)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: account_linked_accounts
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# account_type :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
# linked_account_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# idx_on_account_id_linked_account_id_48ab9f79d2 (account_id,linked_account_id) UNIQUE
|
||||
# index_account_linked_accounts_on_account_id (account_id)
|
||||
# index_account_linked_accounts_on_linked_account_id (linked_account_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (account_id => accounts.id)
|
||||
# fk_rails_... (linked_account_id => accounts.id)
|
||||
#
|
||||
class AccountLinkedAccount < ApplicationRecord
|
||||
belongs_to :account
|
||||
belongs_to :linked_account, class_name: 'Account'
|
||||
|
||||
attribute :account_type, :string, default: 'testing'
|
||||
|
||||
scope :testing, -> { where(account_type: :testing) }
|
||||
|
||||
def testing?
|
||||
account_type == 'testing'
|
||||
end
|
||||
end
|
||||
|
After Width: | Height: | Size: 439 B |
|
After Width: | Height: | Size: 458 B |
@ -1,4 +1,8 @@
|
||||
<%= link_to Docuseal.multitenant? ? console_redirect_index_path(redir: "#{Docuseal::CONSOLE_URL}/plans") : "#{Docuseal::CONSOLE_URL}/on_premise", class: 'hidden md:inline-flex btn btn-warning btn-sm', data: { prefetch: false } do %>
|
||||
Upgrade
|
||||
<% end %>
|
||||
<% if signed_in? && current_user != true_user %>
|
||||
<span class="hidden md:inline-flex h-3 border-r border-base-content"></span>
|
||||
<%= render 'shared/test_alert' %>
|
||||
<% end %>
|
||||
<span class="hidden md:inline-flex h-3 border-r border-base-content"></span>
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<% if signed_in? && current_user != true_user && current_account.testing? %>
|
||||
<div class="alert py-1 text-sm font-medium gap-x-2">
|
||||
<a href="<%= testing_api_settings_path %>" data-turbo-frame="modal" class="link font-semibold flex">
|
||||
<%= svg_icon('code_circle', class: 'w-5 h-5 mr-1') %>Testing Environment
|
||||
</a>
|
||||
<span>
|
||||
|
|
||||
</span>
|
||||
<%= button_to testing_account_path, method: :delete, class: 'inline flex' do %>
|
||||
<% title = capture do %>
|
||||
<span class="link">Exit</span>
|
||||
<span>×</span>
|
||||
<% end %>
|
||||
<%= button_title(title:, disabled_with: 'Leave') %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
@ -0,0 +1,10 @@
|
||||
<% if can?(:manage, EncryptedConfig) || (current_user != true_user && current_account.testing?) %>
|
||||
<%= form_for '', url: testing_account_path, method: current_account.testing? ? :delete : :get, html: { class: 'flex' } do |f| %>
|
||||
<label class="flex items-center justify-between py-2.5" for="testing_toggle">
|
||||
<span class="mr-2 text-lg">
|
||||
Test Environment
|
||||
</span>
|
||||
<%= f.check_box :testing_toggle, class: 'toggle', checked: current_account.testing?, onchange: 'this.form.requestSubmit()' %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@ -0,0 +1,18 @@
|
||||
<%= render 'shared/turbo_modal', title: 'Testing Environment' do %>
|
||||
<div>
|
||||
<label class="text-sm font-semibold" for="api_key">
|
||||
x-Auth-Token
|
||||
</label>
|
||||
<div class="flex gap-2 mb-4 mt-2">
|
||||
<input id="api_key" type="text" value="<%= current_user.access_token.token %>" class="base-input w-full" autocomplete="off" readonly>
|
||||
<%= render 'shared/clipboard_copy', icon: 'copy', text: current_user.access_token.token, class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy', copied_title: 'Copied' %>
|
||||
</div>
|
||||
</div>
|
||||
<%= form_for @webhook_config, url: settings_webhooks_path, method: :post, html: { autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %>
|
||||
<%= f.label :value, 'Webhook URL', class: 'text-sm font-semibold' %>
|
||||
<div class="space-y-2 md:flex-nowrap mt-2">
|
||||
<%= f.url_field :value, class: 'base-input w-full', placeholder: 'https://example.com/hook' %>
|
||||
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button w-full' %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateAccountLinkedAccounts < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :account_linked_accounts do |t|
|
||||
t.references :account, null: false, foreign_key: true
|
||||
t.references :linked_account, null: false, foreign_key: { to_table: :accounts }
|
||||
t.text :account_type, null: false
|
||||
|
||||
t.index %i[account_id linked_account_id], unique: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue