add cancan for authorization

This commit is contained in:
Alex Turchyn
2023-09-17 00:45:57 +03:00
parent f89c50d096
commit 2f1843151d
58 changed files with 343 additions and 186 deletions
@@ -1,15 +1,12 @@
# frozen_string_literal: true
class WebhookSettingsController < ApplicationController
def show
@encrypted_config =
current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
end
before_action :load_encrypted_config
authorize_resource :encrypted_config, parent: false
def show; end
def create
@encrypted_config =
current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
@encrypted_config.update!(encrypted_config_params)
redirect_back(fallback_location: settings_webhooks_path, notice: 'Webhook URL has been saved.')
@@ -25,6 +22,11 @@ class WebhookSettingsController < ApplicationController
private
def load_encrypted_config
@encrypted_config =
current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
end
def encrypted_config_params
params.require(:encrypted_config).permit(:value)
end