Skip to content

Commit

Permalink
feat: Email signature API support (#3874)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswinichile committed Feb 2, 2022
1 parent 193a531 commit e99ea0b
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 55 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/v1/profiles_controller.rb
Expand Up @@ -38,6 +38,8 @@ def profile_params
:name,
:display_name,
:avatar,
:message_signature,
:message_signature_enabled,
ui_settings: {}
)
end
Expand Down
56 changes: 29 additions & 27 deletions app/models/super_admin.rb
Expand Up @@ -2,33 +2,35 @@
#
# Table name: users
#
# id :integer not null, primary key
# availability :integer default("online")
# confirmation_sent_at :datetime
# confirmation_token :string
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# custom_attributes :jsonb
# display_name :string
# email :string
# encrypted_password :string default(""), not null
# last_sign_in_at :datetime
# last_sign_in_ip :string
# name :string not null
# provider :string default("email"), not null
# pubsub_token :string
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# tokens :json
# type :string
# ui_settings :jsonb
# uid :string default(""), not null
# unconfirmed_email :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# availability :integer default("online")
# confirmation_sent_at :datetime
# confirmation_token :string
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# custom_attributes :jsonb
# display_name :string
# email :string
# encrypted_password :string default(""), not null
# last_sign_in_at :datetime
# last_sign_in_ip :string
# message_signature :text
# message_signature_enabled :boolean default(FALSE), not null
# name :string not null
# provider :string default("email"), not null
# pubsub_token :string
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# tokens :json
# type :string
# ui_settings :jsonb
# uid :string default(""), not null
# unconfirmed_email :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
Expand Down
56 changes: 29 additions & 27 deletions app/models/user.rb
Expand Up @@ -2,33 +2,35 @@
#
# Table name: users
#
# id :integer not null, primary key
# availability :integer default("online")
# confirmation_sent_at :datetime
# confirmation_token :string
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# custom_attributes :jsonb
# display_name :string
# email :string
# encrypted_password :string default(""), not null
# last_sign_in_at :datetime
# last_sign_in_ip :string
# name :string not null
# provider :string default("email"), not null
# pubsub_token :string
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# tokens :json
# type :string
# ui_settings :jsonb
# uid :string default(""), not null
# unconfirmed_email :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# availability :integer default("online")
# confirmation_sent_at :datetime
# confirmation_token :string
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# custom_attributes :jsonb
# display_name :string
# email :string
# encrypted_password :string default(""), not null
# last_sign_in_at :datetime
# last_sign_in_ip :string
# message_signature :text
# message_signature_enabled :boolean default(FALSE), not null
# name :string not null
# provider :string default("email"), not null
# pubsub_token :string
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# tokens :json
# type :string
# ui_settings :jsonb
# uid :string default(""), not null
# unconfirmed_email :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
Expand Down
2 changes: 2 additions & 0 deletions app/views/api/v1/models/_user.json.jbuilder
Expand Up @@ -4,6 +4,8 @@ json.available_name resource.available_name
json.avatar_url resource.avatar_url
json.confirmed resource.confirmed?
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.hmac_identifier resource.hmac_identifier if GlobalConfig.get('CHATWOOT_INBOX_HMAC_KEY')['CHATWOOT_INBOX_HMAC_KEY'].present?
json.id resource.id
Expand Down
2 changes: 2 additions & 0 deletions app/views/platform/api/v1/models/_user.json.jbuilder
Expand Up @@ -4,6 +4,8 @@ json.available_name resource.available_name
json.avatar_url resource.avatar_url
json.confirmed resource.confirmed?
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.id resource.id
json.name resource.name
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20220131081750_add_email_signature_to_user.rb
@@ -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
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# 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
enable_extension "pg_stat_statements"
Expand Down Expand Up @@ -747,6 +747,8 @@
t.jsonb "ui_settings", default: {}
t.jsonb "custom_attributes", default: {}
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 ["pubsub_token"], name: "index_users_on_pubsub_token", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/api/v1/profiles_controller_spec.rb
Expand Up @@ -26,6 +26,8 @@
expect(json_response['email']).to eq(agent.email)
expect(json_response['access_token']).to eq(agent.access_token.token)
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
Expand Down Expand Up @@ -56,6 +58,22 @@
expect(agent.name).to eq('test')
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
put '/api/v1/profile',
params: { profile: { current_password: 'Test123!', password: 'Test1234!', password_confirmation: 'Test1234!' } },
Expand Down

0 comments on commit e99ea0b

Please sign in to comment.