feat: Email signature API support (#3874)
This commit is contained in:
parent
193a531e49
commit
e99ea0b582
8 changed files with 93 additions and 55 deletions
|
@ -38,6 +38,8 @@ class Api::V1::ProfilesController < Api::BaseController
|
||||||
:name,
|
:name,
|
||||||
:display_name,
|
:display_name,
|
||||||
:avatar,
|
:avatar,
|
||||||
|
:message_signature,
|
||||||
|
:message_signature_enabled,
|
||||||
ui_settings: {}
|
ui_settings: {}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,33 +2,35 @@
|
||||||
#
|
#
|
||||||
# Table name: users
|
# Table name: users
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# availability :integer default("online")
|
# availability :integer default("online")
|
||||||
# confirmation_sent_at :datetime
|
# confirmation_sent_at :datetime
|
||||||
# confirmation_token :string
|
# confirmation_token :string
|
||||||
# confirmed_at :datetime
|
# confirmed_at :datetime
|
||||||
# current_sign_in_at :datetime
|
# current_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string
|
# current_sign_in_ip :string
|
||||||
# custom_attributes :jsonb
|
# custom_attributes :jsonb
|
||||||
# display_name :string
|
# display_name :string
|
||||||
# email :string
|
# email :string
|
||||||
# encrypted_password :string default(""), not null
|
# encrypted_password :string default(""), not null
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# last_sign_in_ip :string
|
# last_sign_in_ip :string
|
||||||
# name :string not null
|
# message_signature :text
|
||||||
# provider :string default("email"), not null
|
# message_signature_enabled :boolean default(FALSE), not null
|
||||||
# pubsub_token :string
|
# name :string not null
|
||||||
# remember_created_at :datetime
|
# provider :string default("email"), not null
|
||||||
# reset_password_sent_at :datetime
|
# pubsub_token :string
|
||||||
# reset_password_token :string
|
# remember_created_at :datetime
|
||||||
# sign_in_count :integer default(0), not null
|
# reset_password_sent_at :datetime
|
||||||
# tokens :json
|
# reset_password_token :string
|
||||||
# type :string
|
# sign_in_count :integer default(0), not null
|
||||||
# ui_settings :jsonb
|
# tokens :json
|
||||||
# uid :string default(""), not null
|
# type :string
|
||||||
# unconfirmed_email :string
|
# ui_settings :jsonb
|
||||||
# created_at :datetime not null
|
# uid :string default(""), not null
|
||||||
# updated_at :datetime not null
|
# unconfirmed_email :string
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|
|
@ -2,33 +2,35 @@
|
||||||
#
|
#
|
||||||
# Table name: users
|
# Table name: users
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# availability :integer default("online")
|
# availability :integer default("online")
|
||||||
# confirmation_sent_at :datetime
|
# confirmation_sent_at :datetime
|
||||||
# confirmation_token :string
|
# confirmation_token :string
|
||||||
# confirmed_at :datetime
|
# confirmed_at :datetime
|
||||||
# current_sign_in_at :datetime
|
# current_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string
|
# current_sign_in_ip :string
|
||||||
# custom_attributes :jsonb
|
# custom_attributes :jsonb
|
||||||
# display_name :string
|
# display_name :string
|
||||||
# email :string
|
# email :string
|
||||||
# encrypted_password :string default(""), not null
|
# encrypted_password :string default(""), not null
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# last_sign_in_ip :string
|
# last_sign_in_ip :string
|
||||||
# name :string not null
|
# message_signature :text
|
||||||
# provider :string default("email"), not null
|
# message_signature_enabled :boolean default(FALSE), not null
|
||||||
# pubsub_token :string
|
# name :string not null
|
||||||
# remember_created_at :datetime
|
# provider :string default("email"), not null
|
||||||
# reset_password_sent_at :datetime
|
# pubsub_token :string
|
||||||
# reset_password_token :string
|
# remember_created_at :datetime
|
||||||
# sign_in_count :integer default(0), not null
|
# reset_password_sent_at :datetime
|
||||||
# tokens :json
|
# reset_password_token :string
|
||||||
# type :string
|
# sign_in_count :integer default(0), not null
|
||||||
# ui_settings :jsonb
|
# tokens :json
|
||||||
# uid :string default(""), not null
|
# type :string
|
||||||
# unconfirmed_email :string
|
# ui_settings :jsonb
|
||||||
# created_at :datetime not null
|
# uid :string default(""), not null
|
||||||
# updated_at :datetime not null
|
# unconfirmed_email :string
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|
|
@ -4,6 +4,8 @@ json.available_name resource.available_name
|
||||||
json.avatar_url resource.avatar_url
|
json.avatar_url resource.avatar_url
|
||||||
json.confirmed resource.confirmed?
|
json.confirmed resource.confirmed?
|
||||||
json.display_name resource.display_name
|
json.display_name resource.display_name
|
||||||
|
json.message_signature_enabled resource.message_signature_enabled
|
||||||
|
json.message_signature resource.message_signature
|
||||||
json.email resource.email
|
json.email resource.email
|
||||||
json.hmac_identifier resource.hmac_identifier if GlobalConfig.get('CHATWOOT_INBOX_HMAC_KEY')['CHATWOOT_INBOX_HMAC_KEY'].present?
|
json.hmac_identifier resource.hmac_identifier if GlobalConfig.get('CHATWOOT_INBOX_HMAC_KEY')['CHATWOOT_INBOX_HMAC_KEY'].present?
|
||||||
json.id resource.id
|
json.id resource.id
|
||||||
|
|
|
@ -4,6 +4,8 @@ json.available_name resource.available_name
|
||||||
json.avatar_url resource.avatar_url
|
json.avatar_url resource.avatar_url
|
||||||
json.confirmed resource.confirmed?
|
json.confirmed resource.confirmed?
|
||||||
json.display_name resource.display_name
|
json.display_name resource.display_name
|
||||||
|
json.message_signature_enabled resource.message_signature_enabled
|
||||||
|
json.message_signature resource.message_signature
|
||||||
json.email resource.email
|
json.email resource.email
|
||||||
json.id resource.id
|
json.id resource.id
|
||||||
json.name resource.name
|
json.name resource.name
|
||||||
|
|
8
db/migrate/20220131081750_add_email_signature_to_user.rb
Normal file
8
db/migrate/20220131081750_add_email_signature_to_user.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class AddEmailSignatureToUser < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
change_table :users, bulk: true do |t|
|
||||||
|
t.boolean :message_signature_enabled, null: false, default: false
|
||||||
|
t.text :message_signature, null: true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2022_01_21_055444) do
|
ActiveRecord::Schema.define(version: 2022_01_31_081750) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_stat_statements"
|
enable_extension "pg_stat_statements"
|
||||||
|
@ -747,6 +747,8 @@ ActiveRecord::Schema.define(version: 2022_01_21_055444) do
|
||||||
t.jsonb "ui_settings", default: {}
|
t.jsonb "ui_settings", default: {}
|
||||||
t.jsonb "custom_attributes", default: {}
|
t.jsonb "custom_attributes", default: {}
|
||||||
t.string "type"
|
t.string "type"
|
||||||
|
t.boolean "message_signature_enabled", default: false, null: false
|
||||||
|
t.text "message_signature"
|
||||||
t.index ["email"], name: "index_users_on_email"
|
t.index ["email"], name: "index_users_on_email"
|
||||||
t.index ["pubsub_token"], name: "index_users_on_pubsub_token", unique: true
|
t.index ["pubsub_token"], name: "index_users_on_pubsub_token", unique: true
|
||||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||||
|
|
|
@ -26,6 +26,8 @@ RSpec.describe 'Profile API', type: :request do
|
||||||
expect(json_response['email']).to eq(agent.email)
|
expect(json_response['email']).to eq(agent.email)
|
||||||
expect(json_response['access_token']).to eq(agent.access_token.token)
|
expect(json_response['access_token']).to eq(agent.access_token.token)
|
||||||
expect(json_response['custom_attributes']['test']).to eq('test')
|
expect(json_response['custom_attributes']['test']).to eq('test')
|
||||||
|
expect(json_response['message_signature']).to be_nil
|
||||||
|
expect(json_response['message_signature_enabled']).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,6 +58,22 @@ RSpec.describe 'Profile API', type: :request do
|
||||||
expect(agent.name).to eq('test')
|
expect(agent.name).to eq('test')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'updates the message_signature' do
|
||||||
|
put '/api/v1/profile',
|
||||||
|
params: { profile: { name: 'test', message_signature: 'Thanks\nMy Signature', message_signature_enabled: true } },
|
||||||
|
headers: agent.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
json_response = JSON.parse(response.body)
|
||||||
|
agent.reload
|
||||||
|
expect(json_response['id']).to eq(agent.id)
|
||||||
|
expect(json_response['name']).to eq(agent.name)
|
||||||
|
expect(agent.name).to eq('test')
|
||||||
|
expect(json_response['message_signature']).to eq('Thanks\nMy Signature')
|
||||||
|
expect(json_response['message_signature_enabled']).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
it 'updates the password when current password is provided' do
|
it 'updates the password when current password is provided' do
|
||||||
put '/api/v1/profile',
|
put '/api/v1/profile',
|
||||||
params: { profile: { current_password: 'Test123!', password: 'Test1234!', password_confirmation: 'Test1234!' } },
|
params: { profile: { current_password: 'Test123!', password: 'Test1234!', password_confirmation: 'Test1234!' } },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue