From d413dc31d8b089430d7f67a70268ae88f04f16cc Mon Sep 17 00:00:00 2001 From: tuuli Date: Tue, 12 Jun 2018 18:24:15 +0200 Subject: [PATCH] Use ERB::Util instead of CGI.escape to escape whatsapp strings to get the right encoding, use the whatsapp api url --- app/liquid/shares.rb | 2 +- app/services/share_variant_builder.rb | 3 ++- .../20180507153911_create_share_whatsapps.rb | 4 ++-- db/schema.rb | 15 +++++---------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/liquid/shares.rb b/app/liquid/shares.rb index c7e74395e..777f355c7 100644 --- a/app/liquid/shares.rb +++ b/app/liquid/shares.rb @@ -15,7 +15,7 @@ def get_all(page) variant = select_share_variant(button.sp_type, page) view_params[:variant_id] = variant.id # Prepend the desired query parameters (uri encoded) into the url we want to share - url = button.url << CGI.escape("?src=whatsapp&variant_id=#{variant.id}") + url = button.url << ERB::Util.url_encode("?src=whatsapp&variant_id=#{variant.id}") view_params[:link_html] = button.sp_button_html.gsub('%7BLINK%7D', url) end shares[button.sp_type] = view_params diff --git a/app/services/share_variant_builder.rb b/app/services/share_variant_builder.rb index b080a597a..bef0b7869 100644 --- a/app/services/share_variant_builder.rb +++ b/app/services/share_variant_builder.rb @@ -96,7 +96,8 @@ def update_button case @variant_type when :whatsapp @button.update( - sp_button_html: "", + sp_button_html: '", url: @url ) end diff --git a/db/migrate/20180507153911_create_share_whatsapps.rb b/db/migrate/20180507153911_create_share_whatsapps.rb index 9b8805762..e75e74858 100644 --- a/db/migrate/20180507153911_create_share_whatsapps.rb +++ b/db/migrate/20180507153911_create_share_whatsapps.rb @@ -4,8 +4,8 @@ def change t.references :page, index: true, foreign_key: true t.string :text t.integer :button_id - t.integer :click_count, default: 0 - t.integer :conversion_count, default: 0 + t.integer :click_count, default: 0, null: false + t.integer :conversion_count, default: 0, null: false t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index 4a3e419e4..661f6d66e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -46,8 +46,8 @@ t.text "body" t.string "resource_id", null: false t.string "resource_type", null: false - t.integer "author_id" t.string "author_type" + t.integer "author_id" t.datetime "created_at" t.datetime "updated_at" t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id" @@ -64,20 +64,13 @@ t.datetime "updated_at", null: false end - create_table "authentication_nonces", force: :cascade do |t| - t.string "nonce" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["nonce"], name: "index_authentication_nonces_on_nonce" - end - create_table "calls", id: :serial, force: :cascade do |t| t.integer "page_id" t.integer "member_id" t.string "member_phone_number" t.datetime "created_at" t.datetime "updated_at" - t.jsonb "target_call_info", default: {}, null: false + t.jsonb "target_call_info", default: "{}", null: false t.json "member_call_events", default: [], array: true t.integer "twilio_error_code" t.json "target" @@ -122,8 +115,8 @@ t.datetime "updated_at", null: false t.boolean "visible", default: false t.boolean "master", default: false - t.integer "formable_id" t.string "formable_type" + t.integer "formable_id" t.integer "position", default: 0, null: false t.index ["formable_type", "formable_id"], name: "index_forms_on_formable_type_and_formable_id" end @@ -618,6 +611,8 @@ t.bigint "page_id" t.string "text" t.integer "button_id" + t.integer "click_count", default: 0, null: false + t.integer "conversion_count", default: 0, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["page_id"], name: "index_share_whatsapps_on_page_id"