Chore: Add display name to the user (#1067)

* Chore: Adding browser info to web widget triggered event

fixes: #970

* Chore: Rename nickname to display name

references: #972

* Chore: Change nickname in code

* chore: fix errors

* Chore: update nginx config

fixes: #1057

* Chore: Fix specs
This commit is contained in:
Sojan Jose 2020-07-20 18:28:14 +05:30 committed by GitHub
parent 29838f9424
commit d800b55ac6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 34 additions and 23 deletions

View file

@ -30,4 +30,14 @@ class Api::V1::Widget::BaseController < ApplicationController
)
@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

View file

@ -11,7 +11,8 @@ class Api::V1::Widget::EventsController < Api::V1::Widget::BaseController
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

View file

@ -66,16 +66,6 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
}
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]

View file

@ -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,
@ -53,7 +53,7 @@ class UserDashboard < Administrate::BaseDashboard
avatar_url
unconfirmed_email
name
nickname
display_name
email
created_at
updated_at
@ -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

View file

@ -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
@ -96,6 +96,10 @@ class User < ApplicationRecord
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

View file

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

View file

@ -0,0 +1,5 @@
class RenameNickNameToDisplayName < ActiveRecord::Migration[6.0]
def change
rename_column :users, :nickname, :display_name
end
end

View file

@ -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"
@ -407,7 +407,7 @@ ActiveRecord::Schema.define(version: 2020_07_09_145000) do
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

View file

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

View file

@ -32,7 +32,7 @@ RSpec.describe '/api/v1/widget/events', type: :request do
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

View file

@ -12,8 +12,8 @@ FactoryBot.define do
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|

View file

@ -15,5 +15,5 @@ properties:
enum: ['agent', 'administrator']
confirmed:
type: boolean
nickname:
display_name:
type: string

View file

@ -1087,7 +1087,7 @@
"confirmed": {
"type": "boolean"
},
"nickname": {
"display_name": {
"type": "string"
}
}