diff --git a/app/assets/stylesheets/admin/pages/unattached_promo_registrations.scss b/app/assets/stylesheets/admin/pages/unattached_promo_registrations.scss index a9660df971..616ae6051e 100644 --- a/app/assets/stylesheets/admin/pages/unattached_promo_registrations.scss +++ b/app/assets/stylesheets/admin/pages/unattached_promo_registrations.scss @@ -10,7 +10,7 @@ } .panel { - background: aliceblue; + background: Lavender; flex: 1; border-width: 1px; border-radius: 15px; @@ -21,6 +21,10 @@ background: white; } + &--gray{ + background: whitesmoke; + } + .panel--header { font-size: 20px; font-weight: bold; @@ -145,4 +149,4 @@ } } } -} \ No newline at end of file +} diff --git a/app/controllers/admin/unattached_promo_registrations_controller.rb b/app/controllers/admin/unattached_promo_registrations_controller.rb index 6d9291e3b6..3fe0f9c4b2 100644 --- a/app/controllers/admin/unattached_promo_registrations_controller.rb +++ b/app/controllers/admin/unattached_promo_registrations_controller.rb @@ -5,17 +5,23 @@ def index filter = params[:filter] case filter when "All codes", nil, "" - @promo_registrations = PromoRegistration.unattached_only.order("created_at DESC") + @promo_registrations = PromoRegistration.unattached_only. + paginate(page: params[:page]). + order("created_at DESC") when "Not assigned" - @promo_registrations = PromoRegistration.unattached_only.where(promo_campaign_id: nil).order("created_at DESC") + @promo_registrations = PromoRegistration.unattached_only. + where(promo_campaign_id: nil). + paginate(page: params[:page]). + order("created_at DESC") else @promo_registrations = PromoRegistration.joins(:promo_campaign). unattached_only. where(promo_campaigns: {name: filter}). + paginate(page: params[:page]). order("created_at DESC") end @current_campaign = params[:filter] || "All codes" - @campaigns = PromoCampaign.all.map {|campaign| campaign.name} + @campaigns = PromoCampaign.pluck(:name).sort end def create @@ -37,7 +43,7 @@ def report return redirect_to admin_unattached_promo_registrations_path(filter: params[:filter]), alert: "Please check at least one of downloads, installs, or confirmations." end - + report_start_and_end_date = parse_report_dates(params[:referral_code_report_period], @reporting_interval) report_csv = Promo::RegistrationStatsReportGenerator.new(referral_codes: referral_codes, start_date: report_start_and_end_date[:start_date], @@ -96,4 +102,4 @@ def parse_report_dates(report_period, reporting_interval) def create_params params.require(:number_of_codes_to_create) end -end \ No newline at end of file +end diff --git a/app/controllers/promo_registrations_controller.rb b/app/controllers/promo_registrations_controller.rb index 0dedf59023..834699bb49 100644 --- a/app/controllers/promo_registrations_controller.rb +++ b/app/controllers/promo_registrations_controller.rb @@ -1,14 +1,17 @@ class PromoRegistrationsController < ApplicationController include PromosHelper - - before_action :find_publisher + before_action :authenticate_publisher! before_action :require_publisher_promo_disabled, only: %(create) before_action :require_promo_running, only: %i(create) def index + @publisher = current_publisher + @publisher_promo_status = @publisher.promo_status(promo_running?) + @promo_enabled_channels = @publisher.channels.joins(:promo_registration) end def create + @publisher = current_publisher @publisher.promo_enabled_2018q1 = true @publisher.save! @publisher_has_verified_channel = @publisher.has_verified_channel? @@ -31,39 +34,13 @@ def create def require_promo_running unless promo_running? - render(:index) + redirect_to promo_registrations_path, action: "index" end end def require_publisher_promo_disabled - if @publisher.promo_enabled_2018q1 - render(:index) - end - end - - def find_publisher - if current_publisher - @publisher = current_publisher - else - if params[:promo_token].present? - promo_token = params[:promo_token] - elsif params.dig(:publisher).dig(:promo_token).present? - promo_token = params[:publisher][:promo_token] - else - return redirect_to(root_path, alert: I18n.t("promo.publisher_not_found")) - end - if publisher = Publisher.find_by(promo_token_2018q1: promo_token) - @publisher = publisher - else - return redirect_to(root_path, alert: I18n.t("promo.publisher_not_found")) - end + if current_publisher.promo_enabled_2018q1 + redirect_to promo_registrations_path, action: "index" end - - @publisher_promo_status = @publisher.promo_status(promo_running?) - @promo_enabled_channels = @publisher.channels.joins(:promo_registration) - rescue => e - require "sentry-raven" - Raven.capture_exception(e) - return redirect_to(root_path, alert: I18n.t("promo.publisher_not_found")) end end diff --git a/app/controllers/publishers/cases_controller.rb b/app/controllers/publishers/cases_controller.rb index 0bcfbc59e7..8026eedc4b 100644 --- a/app/controllers/publishers/cases_controller.rb +++ b/app/controllers/publishers/cases_controller.rb @@ -10,7 +10,7 @@ def new def show @case = Case.find_by(publisher: current_publisher) - @notes = CaseNote.where(case: @case) + @notes = CaseNote.where(case: @case, public: true) redirect_to new_case_path if @case.blank? || @case.new? end diff --git a/app/jobs/sync/zendesk/ticket_comments_to_notes.rb b/app/jobs/sync/zendesk/ticket_comments_to_notes.rb index b5dc2ce227..069bd30715 100644 --- a/app/jobs/sync/zendesk/ticket_comments_to_notes.rb +++ b/app/jobs/sync/zendesk/ticket_comments_to_notes.rb @@ -10,14 +10,15 @@ def perform(zendesk_ticket_id, page_number = 0) config.url = "#{Rails.application.secrets[:zendesk_url]}/api/v2" # e.g. https://mydesk.zendesk.com/api/v2 # Basic / Token Authentication - config.username = Rails.application.secrets[:zendesk_username] + config.username = "#{Rails.application.secrets[:zendesk_username]}/token" # Choose one of the following depending on your authentication choice # config.token = "your zendesk token" + config.token = Rails.application.secrets[:zendesk_access_token] # config.password = "your zendesk password" # OAuth Authentication - config.access_token = Rails.application.secrets[:zendesk_access_token] + # config.access_token = "" # Optional: diff --git a/app/jobs/sync/zendesk/tickets_to_notes.rb b/app/jobs/sync/zendesk/tickets_to_notes.rb index 41f4256464..c381118c56 100644 --- a/app/jobs/sync/zendesk/tickets_to_notes.rb +++ b/app/jobs/sync/zendesk/tickets_to_notes.rb @@ -9,14 +9,14 @@ def perform(page_number = 0, start_date = nil) config.url = "#{Rails.application.secrets[:zendesk_url]}/api/v2" # e.g. https://mydesk.zendesk.com/api/v2 # Basic / Token Authentication - config.username = Rails.application.secrets[:zendesk_username] + config.username = "#{Rails.application.secrets[:zendesk_username]}/token" # Choose one of the following depending on your authentication choice - # config.token = "your zendesk token" + config.token = Rails.application.secrets[:zendesk_access_token] # config.password = "your zendesk password" # OAuth Authentication - config.access_token = Rails.application.secrets[:zendesk_access_token] + # config.access_token = "" # Optional: diff --git a/app/services/promo/registrations_stats_fetcher.rb b/app/services/promo/registrations_stats_fetcher.rb index 0f7650f28e..df365fa87c 100644 --- a/app/services/promo/registrations_stats_fetcher.rb +++ b/app/services/promo/registrations_stats_fetcher.rb @@ -22,7 +22,7 @@ def perform referral_code_events_by_date = JSON.parse(response.body) referral_code_batch.each do |referral_code| promo_registration = PromoRegistration.find_by_referral_code(referral_code) - next if referral_code.nil? + next if promo_registration.nil? promo_registration.stats = referral_code_events_by_date.select { |referral_code_event_date| referral_code_event_date["referral_code"] == referral_code }.to_json diff --git a/app/services/publisher_promo_token_generator.rb b/app/services/publisher_promo_token_generator.rb deleted file mode 100644 index bb5135cd6a..0000000000 --- a/app/services/publisher_promo_token_generator.rb +++ /dev/null @@ -1,36 +0,0 @@ -# Generates a token for a publisher for 2018q1 promotion -class PublisherPromoTokenGenerator < BaseService - include PromosHelper - - attr_reader :publisher - - def initialize(publisher:, promo_id: active_promo_id, force: false) - @publisher = publisher - @promo_id = promo_id - @force = force - end - - def perform - require "sentry-raven" - case @promo_id - when "free-bats-2018q1" - return perform_2018q1 - else - raise InvalidPromoIdError.new("#{@promo_id} is an invalid promo id") # Rescued and reported in launch promo rake task - end - end - - def perform_2018q1 - already_has_promo_token = publisher.promo_token_2018q1.present? - - if already_has_promo_token && !@force - Rails.logger.info("Publisher #{@publisher.owner_identifier} already has a promo token, use force=true to overwrite.") - nil - else - publisher.promo_token_2018q1 = SecureRandom.hex(32) - publisher.save! - publisher.promo_token_2018q1 - end - end - class InvalidPromoIdError < RuntimeError; end -end \ No newline at end of file diff --git a/app/views/admin/unattached_promo_registrations/index.html.slim b/app/views/admin/unattached_promo_registrations/index.html.slim index b1b2d3b752..cf3e1ca46c 100644 --- a/app/views/admin/unattached_promo_registrations/index.html.slim +++ b/app/views/admin/unattached_promo_registrations/index.html.slim @@ -18,7 +18,7 @@ = text_field_tag "campaign_name", nil, placeholder: "Campaign name" = submit_tag "Create", class: "btn btn-info", style: "float: right" .row - .panel.panel--white.panel--table + .panel.panel--gray.panel--table .panel--header = "Manage" . style="color: darkgrey; font-size: 14px; margin-bottom: 5px;" - if Rails.cache.fetch('unattached_promo_registration_stats_last_synced_at').nil? @@ -31,7 +31,7 @@ = form_tag admin_unattached_promo_registrations_path, method: :patch, id: "unattached-referral-code-form" do table.table tr - th + th th = "Code" th = "Campaign" th = "Installer Type" @@ -70,6 +70,8 @@ td = promo_registration_aggregate_stats[PromoRegistration::RETRIEVALS] || 0 td = promo_registration_aggregate_stats[PromoRegistration::FIRST_RUNS] || 0 td = promo_registration_aggregate_stats[PromoRegistration::FINALIZED] || 0 + = will_paginate @promo_registrations + hr .flex .unattached-referral-code-form--submissions .panel diff --git a/app/views/promo_registrations/create.html.slim b/app/views/promo_registrations/create.html.slim index 94ef8f7937..1ae0e726c3 100644 --- a/app/views/promo_registrations/create.html.slim +++ b/app/views/promo_registrations/create.html.slim @@ -1,4 +1,4 @@ - if @publisher_has_verified_channel = render "activated_verified", locals: @publisher - else - = render "activated_unverified", locals: @publisher \ No newline at end of file + = render "activated_unverified", locals: @publisher diff --git a/config/excluded_site_channels.yml b/config/excluded_site_channels.yml index e79ad43694..dfc5462bd5 100644 --- a/config/excluded_site_channels.yml +++ b/config/excluded_site_channels.yml @@ -13389,6 +13389,7 @@ - "updateworkfreshandnew.space" # commerce - "upfifacoins.com" # commerce - "uphe.com" # commerce +- "uphold.com" # services - "uplay.it" # services - "uplds.com" # services - "uploads.to" # services diff --git a/config/sidekiq.yml b/config/sidekiq.yml index bebd62d2c6..c84e910b3e 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -36,6 +36,10 @@ cron: "0 1 * * *" description: "Syncs the channel stats via youtube and twitch apis" queue: low + Sync::Zendesk::StartJob: + cron: "0 1 * * *" + description: "Syncs zendesk tickets" + queue: low Cache::PiwikDataJob: cron: "45 2 * * *" description: "Refreshes the redis cache for piwik information everyday at 2:45 AM" diff --git a/lib/tasks/launch_promo.rake b/lib/tasks/launch_promo.rake deleted file mode 100644 index 5984d0804f..0000000000 --- a/lib/tasks/launch_promo.rake +++ /dev/null @@ -1,25 +0,0 @@ -require "#{Rails.root}/app/helpers/promos_helper" -namespace :promo do - # Generates the promo tokens and sends emails - task :launch_promo => :environment do - include PromosHelper - begin - unless promo_running? - puts "Promo is not running, check the active_promo_id config var." - end - - publishers = Publisher.where(promo_token_2018q1: nil).where(promo_enabled_2018q1: false).where.not(email: nil) - - publishers.find_each do |publisher| - token = PublisherPromoTokenGenerator.new(publisher: publisher).perform - next unless token - PromoMailer.activate_promo_2018q1(publisher).deliver_later(queue: :low) - end - - rescue PublisherPromoTokenGenerator::InvalidPromoIdError => error - require "raven" - Raven.capture_exception(error) - puts "Did not launch promo because of invalid promo id. Check the active_promo_id config var." - end - end -end \ No newline at end of file diff --git a/public/creators-landing/src/style/style.css b/public/creators-landing/src/style/style.css index afe414534d..3f1ed001bb 100644 --- a/public/creators-landing/src/style/style.css +++ b/public/creators-landing/src/style/style.css @@ -78,7 +78,7 @@ h4 { .top-swoop { position: absolute; top: -2px; - width: 100vw !important; + width: 100% !important; } .bottom-swoop { diff --git a/test/controllers/promo_registrations_controller_test.rb b/test/controllers/promo_registrations_controller_test.rb index f555f6d012..c05bcb03b4 100644 --- a/test/controllers/promo_registrations_controller_test.rb +++ b/test/controllers/promo_registrations_controller_test.rb @@ -37,6 +37,7 @@ class PromoRegistrationsControllerTest < ActionDispatch::IntegrationTest # verify _over is rendered post promo_registrations_path + follow_redirect! assert_select("[data-test=promo-over]") # verify publisher has not enabled promo @@ -52,6 +53,7 @@ class PromoRegistrationsControllerTest < ActionDispatch::IntegrationTest # verify _over is rendered post promo_registrations_path + follow_redirect! assert_select("[data-test=promo-active]") # verify publisher has not enabled promo @@ -131,38 +133,6 @@ class PromoRegistrationsControllerTest < ActionDispatch::IntegrationTest assert_select("[data-test=promo-active]") end - test "publisher can activate/visit promo without being signed in using promo token from email" do - publisher = publishers(:completed) - - # ensure we use token, not session for promo auth - sign_out publisher - - promo_token = PublisherPromoTokenGenerator.new(publisher: publisher).perform - - # verify promo token auth takes you to _activate page - url = promo_registrations_path(promo_token: promo_token) - get url - assert_response 200 - assert_select("[data-test=promo-activate]") - - # verify the above does not enable the promo - assert_equal publisher.promo_enabled_2018q1, false - - # verify promo auth allows promo activation, takes publisher to _activated_verified - post url - publisher.reload - assert_equal publisher.promo_enabled_2018q1, true - assert_select("[data-test=promo-activated-verified]") - - # verify promo auth allows users to view active page once authorized - get url - assert_select("[data-test=promo-active]") - - # verify publisher is not must reauth to visit dashboard - get home_publishers_path(publisher) - assert_response 401 # Unauthorized # TO DO: See screen this takes you to, ideally dashboard - end - test "all requests with no promo_token in params or publisher in the session redirect homepage" do publisher = publishers(:completed) sign_out publisher diff --git a/test/services/publisher_promo_token_generator_test.rb b/test/services/publisher_promo_token_generator_test.rb deleted file mode 100644 index e72247e1b0..0000000000 --- a/test/services/publisher_promo_token_generator_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require "test_helper" -require "webmock/minitest" - -class PublisherPromoTokenGeneratorTest < ActiveJob::TestCase - include PromosHelper - - test "generator generates 2018q1 token" do - publisher = publishers(:completed) - PublisherPromoTokenGenerator.any_instance.stubs(:active_promo_id).returns("free-bats-2018q1") - PublisherPromoTokenGenerator.new(publisher: publisher).perform - - assert_not_nil publisher.promo_token_2018q1 - end - - test "generator doesn't overwrite existing 2018q1 token" do - publisher = publishers(:completed) - PublisherPromoTokenGenerator.any_instance.stubs(:active_promo_id).returns("free-bats-2018q1") - generator = PublisherPromoTokenGenerator.new(publisher: publisher) - - # generate token - generator.perform - promo_token = publisher.promo_token_2018q1 - - # verify generator doesn't overwrite existing token - generator.perform - assert_equal promo_token, publisher.promo_token_2018q1 - end - - test "generator will overwrite existing 2018q1 token with param force=true" do - publisher = publishers(:completed) - PublisherPromoTokenGenerator.any_instance.stubs(:active_promo_id).returns("free-bats-2018q1") - PublisherPromoTokenGenerator.new(publisher: publisher).perform - - first_promo_token = publisher.promo_token_2018q1 - PublisherPromoTokenGenerator.new(publisher: publisher, force: true).perform - second_promo_token = publisher.promo_token_2018q1 - - assert_not_equal first_promo_token, second_promo_token - end - - test "generator raises error if promo_id is invalid, no 2018q1 tokens are generated" do - publisher = publishers(:completed) - - # use invalid active_promo_id - PublisherPromoTokenGenerator.any_instance.stubs(:active_promo_id).returns("invalid-promo-id") - - assert_raise PublisherPromoTokenGenerator::InvalidPromoIdError do - PublisherPromoTokenGenerator.new(publisher: publisher).perform - end - end -end \ No newline at end of file diff --git a/test/tasks/launch_promo_test.rb b/test/tasks/launch_promo_test.rb deleted file mode 100644 index 8aaa314271..0000000000 --- a/test/tasks/launch_promo_test.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'test_helper' - -class LaunchPromoTest < ActiveJob::TestCase - - before do - require 'rake' - Rake::Task.define_task :environment - Rails.application.load_tasks - end - - test "generates a promo token and sends email to each publisher" do - assert_difference("Publisher.where.not(promo_token_2018q1: nil).count", Publisher.where.not(email: nil, promo_enabled_2018q1: true).count) do - assert_enqueued_jobs(Publisher.where.not(email: nil, promo_enabled_2018q1: true).count) do - Rake::Task["promo:launch_promo"].invoke - Rake::Task["promo:launch_promo"].reenable - end - end - end - - test "only sends one email to each publisher if run twice (idempotence)" do - publisher_one = publishers(:completed).dup - publisher_two = publishers(:verified).dup - - PublisherNote.destroy_all - Publisher.delete_all - - publisher_one.save! - assert_equal Publisher.count, 1 # sanity check - - # run task once and store publisher_one's promo token - assert_difference("Publisher.where.not(promo_token_2018q1: nil).count", 1) do - assert_enqueued_jobs(1) do - Rake::Task["promo:launch_promo"].invoke - Rake::Task["promo:launch_promo"].reenable - end - end - publisher_one.reload - promo_token_one = publisher_one.promo_token_2018q1 - - # add a second publisher - publisher_two.save! - assert_equal Publisher.count, 2 - - # run task again and verify it has no effect on publisher_one - assert_difference("Publisher.where.not(promo_token_2018q1: nil).count", 1) do - assert_enqueued_jobs(1) do - Rake::Task["promo:launch_promo"].invoke - Rake::Task["promo:launch_promo"].reenable - end - end - - # verify promo_token_one matches after rake task run twice - assert_equal promo_token_one, publisher_one.promo_token_2018q1 - end -end