mirror of https://github.com/docusealco/docuseal
				
				
				
			
							parent
							
								
									6b1c3bba19
								
							
						
					
					
						commit
						478167ea4f
					
				| @ -0,0 +1,29 @@ | |||||||
|  | # frozen_string_literal: true | ||||||
|  | 
 | ||||||
|  | class WebhookSecretController < ApplicationController | ||||||
|  |   before_action :load_encrypted_config | ||||||
|  |   authorize_resource :encrypted_config, parent: false | ||||||
|  | 
 | ||||||
|  |   def index; end | ||||||
|  | 
 | ||||||
|  |   def create | ||||||
|  |     @encrypted_config.assign_attributes(value: { | ||||||
|  |       encrypted_config_params[:key] => encrypted_config_params[:value] | ||||||
|  |     }.compact_blank) | ||||||
|  | 
 | ||||||
|  |     @encrypted_config.value.present? ? @encrypted_config.save! : @encrypted_config.delete | ||||||
|  | 
 | ||||||
|  |     redirect_back(fallback_location: settings_webhooks_path, notice: 'Webhook Secret has been saved.') | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   private | ||||||
|  | 
 | ||||||
|  |   def load_encrypted_config | ||||||
|  |     @encrypted_config = | ||||||
|  |       current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_SECRET_KEY) | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   def encrypted_config_params | ||||||
|  |     params.require(:encrypted_config).permit(value: %i[key value]).fetch(:value, {}) | ||||||
|  |   end | ||||||
|  | end | ||||||
| @ -0,0 +1,19 @@ | |||||||
|  | <%= render 'shared/turbo_modal', title: 'Webhook Secret' do %> | ||||||
|  |   <%= form_for @encrypted_config, url: webhook_secret_index_path, method: :post, html: { class: 'space-y-4' }, data: { turbo_frame: :_top } do |f| %> | ||||||
|  |     <div class="space-y-2"> | ||||||
|  |       <%= f.fields_for :value, Struct.new(:key, :value).new(*@encrypted_config.value.to_a.first) do |ff| %> | ||||||
|  |         <div class="form-control"> | ||||||
|  |           <%= ff.label :key, class: 'label' %> | ||||||
|  |           <%= ff.text_field :key, class: 'base-input', placeholder: 'X-Example-Header' %> | ||||||
|  |         </div> | ||||||
|  |         <div class="form-control"> | ||||||
|  |           <%= ff.label :value, class: 'label' %> | ||||||
|  |           <%= ff.text_field :value, class: 'base-input' %> | ||||||
|  |         </div> | ||||||
|  |       <% end %> | ||||||
|  |     </div> | ||||||
|  |     <div class="form-control pt-2"> | ||||||
|  |       <%= f.button button_title, class: 'base-button' %> | ||||||
|  |     </div> | ||||||
|  |   <% end %> | ||||||
|  | <% end %> | ||||||
					Loading…
					
					
				
		Reference in new issue