Skip to content

Commit

Permalink
Merge pull request #2314 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-10-15
  • Loading branch information
yachtcaptain23 authored Oct 15, 2019
2 parents caaf9af + 9968bc2 commit 40920cf
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
12 changes: 9 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ class ApplicationController < ActionController::Base

newrelic_ignore_enduser


rescue_from Ability::AdminNotOnIPWhitelistError do |e|
render file: "admin/errors/whitelist.html", layout: false
end

around_action :switch_locale
def switch_locale(&action)
locale = nil
return I18n.with_locale(I18n.default_locale, &action) if params['controller'].split("/")[0] == 'admin'
locale = params[:locale] if params[:locale].present?

if locale.nil? && extract_locale_from_accept_language_header == 'ja'
if locale.nil? && extract_locale_from_accept_language_header == 'ja' && request.get?
new_query = URI(request.original_url).query.present? ? "&locale=ja" : "?locale=ja"
redirect_to(request.original_url + new_query) and return
end

locale = I18n.default_locale if locale.nil? || !locale.in?(I18n.available_locales)
locale = I18n.default_locale if locale.nil? || !locale.to_sym.in?(I18n.available_locales)
I18n.with_locale(locale, &action)
end

Expand All @@ -54,7 +56,11 @@ def user_for_paper_trail

def redirect_if_suspended
# Redirect to suspended page if they're logged in
redirect_to(suspended_error_publishers_path) and return if current_publisher.present? && current_publisher.suspended?
redirect_to(suspended_error_publishers_path) and return if current_publisher&.suspended? && !request.fullpath.split("?")[0].in?(valid_suspended_paths)
end

def valid_suspended_paths
[suspended_error_publishers_path.split("?")[0], log_out_publishers_path.split("?")[0]]
end

def current_ability
Expand Down
33 changes: 23 additions & 10 deletions app/jobs/sync/zendesk/ticket_comments_to_notes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,40 @@ def perform(zendesk_ticket_id, page_number = 0)

publisher_notes = []
publisher = nil
admin_id = Publisher.find_by(email: Rails.application.secrets[:zendesk_admin_email]).id
admin = Publisher.find_by(email: Rails.application.secrets[:zendesk_admin_email])
zendesk_comments = client.ticket.find(id: zendesk_ticket_id).comments
for index in (0...zendesk_comments.count)
from_email = nil
to_email = nil

# The first email should be the publisher's email. Would be surprising otherwise
comment = zendesk_comments[index]
publisher_email = comment&.via&.source&.from&.address
from_email = comment&.via&.source&.from&.address
to_email = comment&.via&.source&.to&.address

if publisher_email.present? && publisher.nil?
publisher = Publisher.find_by(email: publisher_email)
if (from_email.present? || to_email.present?) && publisher.nil?
publisher = Publisher.find_by(email: from_email)
publisher = Publisher.find_by(email: to_email) if publisher.nil?
end
publisher_notes << PublisherNote.new(note: comment.plain_body, zendesk_ticket_id: zendesk_ticket_id, zendesk_comment_id: comment.id, created_at: comment.created_at)

publisher_note = PublisherNote.find_or_initialize_by(zendesk_ticket_id: zendesk_ticket_id, zendesk_comment_id: comment.id)
publisher_note.created_at = comment.created_at
publisher_note.created_by_id = admin.id
publisher_note.note = comment.plain_body
publisher_note.zendesk_from_email = from_email
publisher_note.zendesk_to_email = to_email
publisher_notes << publisher_note
end
return if publisher.nil?

# Don't lock this in a transaction as we might need to parse over to update the ticket
publisher_notes.each do |publisher_note|
publisher_notes.each do |pn|
begin
publisher_note.publisher_id = publisher.id
publisher_note.created_by_id = admin_id
publisher_note.save
pn.publisher_id = publisher.id
pn.save
rescue ActiveRecord::RecordNotUnique
end
end

Rails.logger.info "Done with zendesk ticket #{zendesk_ticket_id}"
end
end
2 changes: 2 additions & 0 deletions app/models/publisher_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class PublisherNote < ApplicationRecord
has_many :comments, class_name: "PublisherNote", foreign_key: "thread_id"

validates :note, presence: true, allow_blank: false

UNKNOWN_PUBLISHER_ID = "00000000-0000-0000-0000-000000000000".freeze
end
3 changes: 3 additions & 0 deletions app/services/publisher_statement_getter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def get_uphold_transactions
end

uphold
rescue Faraday::ClientError
Rails.logger.info("Couldn't access publisher #{@publisher.id} Uphold Transaction History")
[]
end

def channel_name(identifier)
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/publishers/_note.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- unless condense
.note-header
/ The name of the person
strong= note.created_by.name
strong= note.zendesk_from_email.present? ? note.zendesk_from_email : note.created_by.name

- if note.zendesk_ticket_id.present?
.text-muted.mx-2 Note ported from Zendesk
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSenderEmailToPublisherNotes < ActiveRecord::Migration[5.2]
def change
add_column :publisher_notes, :zendesk_to_email, :string, index: true
add_column :publisher_notes, :zendesk_from_email, :string, index: true
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.uuid "created_by_id", null: false
t.uuid "thread_id"
t.bigint "zendesk_ticket_id"
t.bigint "zendesk_comment_id"
t.uuid "thread_id"
t.string "zendesk_to_email"
t.string "zendesk_from_email"
t.index ["created_by_id"], name: "index_publisher_notes_on_created_by_id"
t.index ["publisher_id"], name: "index_publisher_notes_on_publisher_id"
t.index ["thread_id"], name: "index_publisher_notes_on_thread_id"
Expand Down

0 comments on commit 40920cf

Please sign in to comment.