diff --git a/app/models/encrypted_user_config.rb b/app/models/encrypted_user_config.rb new file mode 100644 index 00000000..4bae8b7e --- /dev/null +++ b/app/models/encrypted_user_config.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: encrypted_user_configs +# +# id :bigint not null, primary key +# key :string not null +# value :text not null +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_encrypted_user_configs_on_user_id (user_id) +# index_encrypted_user_configs_on_user_id_and_key (user_id,key) UNIQUE +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# +class EncryptedUserConfig < ApplicationRecord + belongs_to :user + + encrypts :value + + serialize :value, JSON +end diff --git a/app/models/user.rb b/app/models/user.rb index 3ea3b1cf..2968c58b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -53,6 +53,7 @@ class User < ApplicationRecord has_one :access_token, dependent: :destroy has_many :templates, dependent: :destroy, foreign_key: :author_id, inverse_of: :author has_many :user_configs, dependent: :destroy + has_many :encrypted_configs, dependent: :destroy, class_name: 'EncryptedUserConfig' devise :two_factor_authenticatable, :recoverable, :rememberable, :validatable, :trackable devise :registerable, :omniauthable, omniauth_providers: [:google_oauth2] if Docuseal.multitenant? diff --git a/app/views/profile/_email_configs.html.erb b/app/views/profile/_email_configs.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/profile/index.html.erb b/app/views/profile/index.html.erb index 7eddb313..96db7027 100644 --- a/app/views/profile/index.html.erb +++ b/app/views/profile/index.html.erb @@ -21,6 +21,7 @@ <%= f.button button_title(title: 'Update', disabled_with: 'Updating'), class: 'base-button' %> <% end %> + <%= render 'email_configs' %>

Signature

<% signature = UserConfigs.load_signature(current_user) %> <% if signature %> diff --git a/app/views/submissions/_message_fields.html.erb b/app/views/submissions/_message_fields.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/submissions/_send_email.html.erb b/app/views/submissions/_send_email.html.erb index 8d61822a..e5372c84 100644 --- a/app/views/submissions/_send_email.html.erb +++ b/app/views/submissions/_send_email.html.erb @@ -41,6 +41,7 @@ <%= f.text_area :body, value: config.value['body'], required: true, class: 'base-textarea w-full', rows: 10 %> + <%= render 'message_fields' %> diff --git a/app/views/submissions/new.html.erb b/app/views/submissions/new.html.erb index c0241180..4f95ca7d 100644 --- a/app/views/submissions/new.html.erb +++ b/app/views/submissions/new.html.erb @@ -23,4 +23,5 @@ <%= render 'detailed_form', template: @template %> + <%= content_for(:modal_extra) %> <% end %> diff --git a/db/migrate/20230924184657_create_encrypted_user_configs.rb b/db/migrate/20230924184657_create_encrypted_user_configs.rb new file mode 100644 index 00000000..7c771d53 --- /dev/null +++ b/db/migrate/20230924184657_create_encrypted_user_configs.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CreateEncryptedUserConfigs < ActiveRecord::Migration[7.0] + def change + create_table :encrypted_user_configs do |t| + t.references :user, null: false, foreign_key: true, index: true + t.string :key, null: false + t.text :value, null: false + + t.index %i[user_id key], unique: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2b5ac2ee..fb0adfef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -91,6 +91,16 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_17_213639) do t.index ["account_id"], name: "index_encrypted_configs_on_account_id" end + create_table "encrypted_user_configs", force: :cascade do |t| + t.bigint "user_id", null: false + t.string "key", null: false + t.text "value", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id", "key"], name: "index_encrypted_user_configs_on_user_id_and_key", unique: true + t.index ["user_id"], name: "index_encrypted_user_configs_on_user_id" + end + create_table "submission_events", force: :cascade do |t| t.bigint "submission_id", null: false t.bigint "submitter_id" @@ -217,6 +227,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_17_213639) do add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "document_generation_events", "submitters" add_foreign_key "encrypted_configs", "accounts" + add_foreign_key "encrypted_user_configs", "users" add_foreign_key "submission_events", "submissions" add_foreign_key "submission_events", "submitters" add_foreign_key "submissions", "templates" diff --git a/lib/ability.rb b/lib/ability.rb index a5a77031..1d3f336b 100644 --- a/lib/ability.rb +++ b/lib/ability.rb @@ -10,6 +10,7 @@ class Ability can :manage, Submitter, template: { account_id: user.account_id } can :manage, User, account_id: user.account_id can :manage, EncryptedConfig, account_id: user.account_id + can :manage, EncryptedUserConfig, user_id: user.id can :manage, AccountConfig, account_id: user.account_id can :manage, UserConfig, user_id: user.id can :manage, Account, id: user.account_id