Skip to content

Commit

Permalink
Chore: Add display name to the user (chatwoot#1067)
Browse files Browse the repository at this point in the history
* Chore: Adding browser info to web widget triggered event

fixes: chatwoot#970

* Chore: Rename nickname to display name

references: chatwoot#972

* Chore: Change nickname in code

* chore: fix errors

* Chore: update nginx config

fixes: chatwoot#1057

* Chore: Fix specs
  • Loading branch information
sojan-official authored Jul 20, 2020
1 parent 29838f9 commit d800b55
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 23 deletions.
10 changes: 10 additions & 0 deletions app/controllers/api/v1/widget/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ def set_contact
)
@contact = @contact_inbox.contact
end

def browser_params
{
browser_name: browser.name,
browser_version: browser.full_version,
device_name: browser.device.name,
platform_name: browser.platform.name,
platform_version: browser.platform.version
}
end
end
3 changes: 2 additions & 1 deletion app/controllers/api/v1/widget/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def create
def event_info
{
widget_language: params[:locale],
browser_language: browser.accept_language.first&.code
browser_language: browser.accept_language.first&.code,
browser: browser_params
}
end

Expand Down
10 changes: 0 additions & 10 deletions app/controllers/api/v1/widget/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ def conversation_params
}
end

def browser_params
{
browser_name: browser.name,
browser_version: browser.full_version,
device_name: browser.device.name,
platform_name: browser.platform.name,
platform_version: browser.platform.version
}
end

def timestamp_params
{
timestamp: permitted_params[:message][:timestamp]
Expand Down
6 changes: 3 additions & 3 deletions app/dashboards/user_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UserDashboard < Administrate::BaseDashboard
confirmation_sent_at: Field::DateTime,
unconfirmed_email: Field::String,
name: Field::String,
nickname: Field::String,
display_name: Field::String,
email: Field::String,
tokens: Field::String.with_options(searchable: false),
created_at: Field::DateTime,
Expand Down Expand Up @@ -53,7 +53,7 @@ class UserDashboard < Administrate::BaseDashboard
avatar_url
unconfirmed_email
name
nickname
display_name
email
created_at
updated_at
Expand All @@ -65,7 +65,7 @@ class UserDashboard < Administrate::BaseDashboard
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[
name
nickname
display_name
email
password
].freeze
Expand Down
6 changes: 5 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# 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
# nickname :string
# provider :string default("email"), not null
# pubsub_token :string
# remember_created_at :datetime
Expand Down Expand Up @@ -96,6 +96,10 @@ def current_account_user
account_users.find_by(account_id: Current.account.id) if Current.account
end

def display_name
self[:display_name].presence || name
end

def account
current_account_user&.account
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v1/models/_user.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ json.id resource.id
json.provider resource.provider
json.uid resource.uid
json.name resource.name
json.nickname resource.nickname
json.display_name resource.display_name
json.email resource.email
json.account_id resource.active_account_user&.account_id
json.pubsub_token resource.pubsub_token
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200719171437_rename_nick_name_to_display_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameNickNameToDisplayName < ActiveRecord::Migration[6.0]
def change
rename_column :users, :nickname, :display_name
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_07_09_145000) do
ActiveRecord::Schema.define(version: 2020_07_19_171437) do

# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
Expand Down Expand Up @@ -407,7 +407,7 @@
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "name", null: false
t.string "nickname"
t.string "display_name"
t.string "email"
t.json "tokens"
t.datetime "created_at", null: false
Expand Down
1 change: 1 addition & 0 deletions docs/deployment/production/linux-vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ server {
server_name yourdomain.com;
# where rails app is running
set $upstream 127.0.0.1:3000;
underscores_in_headers on;

# Here we define the web-root for our SSL proof
location /.well-known {
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/widget/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
expect(response).to have_http_status(:success)
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
.with(params[:name], anything, contact_inbox: contact_inbox,
event_info: { browser_language: nil, widget_language: nil })
event_info: { browser_language: nil, widget_language: nil, browser: anything })
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
provider { 'email' }
uid { SecureRandom.uuid }
name { Faker::Name.name }
nickname { Faker::Name.first_name }
email { nickname + "@#{SecureRandom.uuid}.com" }
display_name { Faker::Name.first_name }
email { display_name + "@#{SecureRandom.uuid}.com" }
password { 'password' }

after(:build) do |user, evaluator|
Expand Down
2 changes: 1 addition & 1 deletion swagger/definitions/resource/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ properties:
enum: ['agent', 'administrator']
confirmed:
type: boolean
nickname:
display_name:
type: string
2 changes: 1 addition & 1 deletion swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@
"confirmed": {
"type": "boolean"
},
"nickname": {
"display_name": {
"type": "string"
}
}
Expand Down

0 comments on commit d800b55

Please sign in to comment.