add user encrypted configs

pull/133/head
DocuSeal 2 years ago
parent 9da7463657
commit 11a90d797a

@ -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

@ -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?

@ -21,6 +21,7 @@
<%= f.button button_title(title: 'Update', disabled_with: 'Updating'), class: 'base-button' %>
</div>
<% end %>
<%= render 'email_configs' %>
<p class="text-2xl font-bold mt-8 mb-4">Signature</p>
<% signature = UserConfigs.load_signature(current_user) %>
<% if signature %>

@ -41,6 +41,7 @@
<%= f.text_area :body, value: config.value['body'], required: true, class: 'base-textarea w-full', rows: 10 %>
</autoresize-textarea>
</div>
<%= render 'message_fields' %>
</div>
</div>
</div>

@ -23,4 +23,5 @@
<%= render 'detailed_form', template: @template %>
</div>
</div>
<%= content_for(:modal_extra) %>
<% end %>

@ -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

@ -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"

@ -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

Loading…
Cancel
Save