diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb index b915f0775440..c810500f99ff 100644 --- a/app/controllers/api/v1/profiles_controller.rb +++ b/app/controllers/api/v1/profiles_controller.rb @@ -38,6 +38,8 @@ def profile_params :name, :display_name, :avatar, + :message_signature, + :message_signature_enabled, ui_settings: {} ) end diff --git a/app/models/super_admin.rb b/app/models/super_admin.rb index acc5f28dde39..2ce658000efd 100644 --- a/app/models/super_admin.rb +++ b/app/models/super_admin.rb @@ -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 # diff --git a/app/models/user.rb b/app/models/user.rb index 773277e1508d..4a1fa249ea16 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 # diff --git a/app/views/api/v1/models/_user.json.jbuilder b/app/views/api/v1/models/_user.json.jbuilder index 39c552c40400..a2f80e1f4e45 100644 --- a/app/views/api/v1/models/_user.json.jbuilder +++ b/app/views/api/v1/models/_user.json.jbuilder @@ -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 diff --git a/app/views/platform/api/v1/models/_user.json.jbuilder b/app/views/platform/api/v1/models/_user.json.jbuilder index 4c50efaaaee9..fcc151e026b9 100644 --- a/app/views/platform/api/v1/models/_user.json.jbuilder +++ b/app/views/platform/api/v1/models/_user.json.jbuilder @@ -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 diff --git a/db/migrate/20220131081750_add_email_signature_to_user.rb b/db/migrate/20220131081750_add_email_signature_to_user.rb new file mode 100644 index 000000000000..54edc049e509 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index b963cae8d545..27da2435dbb3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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 diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb index 39a936a90810..27763aa12e5f 100644 --- a/spec/controllers/api/v1/profiles_controller_spec.rb +++ b/spec/controllers/api/v1/profiles_controller_spec.rb @@ -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 @@ -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!' } },