diff --git a/app/controllers/user_configs_controller.rb b/app/controllers/user_configs_controller.rb new file mode 100644 index 00000000..124e5d63 --- /dev/null +++ b/app/controllers/user_configs_controller.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class UserConfigsController < ApplicationController + before_action :load_user_config + authorize_resource :user_config + + ALLOWED_KEYS = [ + UserConfig::RECEIVE_COMPLETED_EMAIL + ].freeze + + def create + @user_config.update!(user_config_params) + + head :ok + end + + private + + def load_user_config + return head :not_found 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!.tap do |attrs| + attrs[:value] = attrs[:value] == '1' if attrs[:value].in?(%w[1 0]) + end + end +end diff --git a/app/views/notifications_settings/index.html.erb b/app/views/notifications_settings/index.html.erb index bd880f00..632c145d 100644 --- a/app/views/notifications_settings/index.html.erb +++ b/app/views/notifications_settings/index.html.erb @@ -2,6 +2,20 @@ <%= render 'shared/settings_nav' %>

Email Notifications

+
+ <% user_config = UserConfig.find_or_initialize_by(user: current_user, key: UserConfig::RECEIVE_COMPLETED_EMAIL) %> + <% if can?(:manage, user_config) %> + <%= form_for user_config, url: user_configs_path, method: :post do |f| %> + <%= f.hidden_field :key %> +
+ + Receive notification emails on completed submission + + <%= f.check_box :value, class: 'toggle', checked: user_config.value != false, onchange: 'this.form.requestSubmit()' %> +
+ <% end %> + <% end %> +
<%= render 'email_stats' %> <%= render 'bcc_form', config: @bcc_config %>
diff --git a/config/routes.rb b/config/routes.rb index 9aef918c..1c88b723 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,6 +53,7 @@ Rails.application.routes.draw do resources :verify_pdf_signature, only: %i[create] resource :mfa_setup, only: %i[show new edit create destroy], controller: 'mfa_setup' resources :account_configs, only: %i[create] + resources :user_configs, only: %i[create] resources :encrypted_user_configs, only: %i[destroy] resources :timestamp_server, only: %i[create] resources :dashboard, only: %i[index]