mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
786 B
34 lines
786 B
# frozen_string_literal: true
|
|
|
|
class UserConfigsController < ApplicationController
|
|
before_action :load_user_config
|
|
authorize_resource :user_config
|
|
|
|
ALLOWED_KEYS = [
|
|
UserConfig::RECEIVE_COMPLETED_EMAIL
|
|
].freeze
|
|
|
|
InvalidKey = Class.new(StandardError)
|
|
|
|
def create
|
|
@user_config.update!(user_config_params)
|
|
|
|
head :ok
|
|
end
|
|
|
|
private
|
|
|
|
def load_user_config
|
|
raise InvalidKey unless ALLOWED_KEYS.include?(user_config_params[:key])
|
|
|
|
@user_config =
|
|
UserConfig.find_or_initialize_by(user: current_user, key: user_config_params[:key])
|
|
end
|
|
|
|
def user_config_params
|
|
params.required(:user_config).permit(:key, :value, { value: {} }, { value: [] }).tap do |attrs|
|
|
attrs[:value] = attrs[:value] == '1' if attrs[:value].in?(%w[1 0])
|
|
end
|
|
end
|
|
end
|