From 351816c15428fe19ee74e3a0104167b4c20df9cf Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Mon, 3 Aug 2015 22:33:35 -0700 Subject: [PATCH 1/6] Flush cache on surf pages --- models/site.rb | 6 +++++- tests/site_file_tests.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/models/site.rb b/models/site.rb index 44a95f60..eeeb89d2 100644 --- a/models/site.rb +++ b/models/site.rb @@ -591,7 +591,11 @@ class Site < Sequel::Model # We gotta flush the dirname too if it's an index file. if relative_path != '' && relative_path.match(/\/$|index\.html?$/i) PurgeCacheOrderWorker.perform_async username, relative_path - PurgeCacheOrderWorker.perform_async username, Pathname(relative_path).dirname.to_s + + purge_file_path = Pathname(relative_path).dirname.to_s + + PurgeCacheOrderWorker.perform_async username, '/?surf=1' if purge_file_path == '/' + PurgeCacheOrderWorker.perform_async username, purge_file_path else PurgeCacheOrderWorker.perform_async username, relative_path end diff --git a/tests/site_file_tests.rb b/tests/site_file_tests.rb index f2aee5ee..28eb95b7 100644 --- a/tests/site_file_tests.rb +++ b/tests/site_file_tests.rb @@ -107,13 +107,17 @@ describe 'site_files' do @site.title.must_equal 'Hello?' # Purge cache needs to flush / and index.html for either scenario. - PurgeCacheOrderWorker.jobs.length.must_equal 2 + PurgeCacheOrderWorker.jobs.length.must_equal 3 first_purge = PurgeCacheOrderWorker.jobs.first + surf_purge = PurgeCacheOrderWorker.jobs[1] dirname_purge = PurgeCacheOrderWorker.jobs.last username, pathname = first_purge['args'] username.must_equal @site.username pathname.must_equal '/index.html' + + surf_purge['args'].last.must_equal '/?surf=1' + username, pathame = nil username, pathname = dirname_purge['args'] username.must_equal @site.username From 6e0b21bfd2a7ee3564f73947034dafb71d0383af Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 5 Aug 2015 11:39:46 -0700 Subject: [PATCH 2/6] Change upgrade copy, initial site files prime code --- Rakefile | 24 +++++++++++++++++++++ views/templates/email/supporter_upgrade.erb | 6 ++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 4ac5badd..b28ad941 100644 --- a/Rakefile +++ b/Rakefile @@ -216,6 +216,30 @@ task :hash_ips => [:environment] do end end +desc 'prime_site_files' +task :prime_site_files => [:environment] do + Site.where(is_banned: false).select(:id, :username).all.each do |site| + Dir.glob(File.join(site.files_path, '**/*')).each do |file| + next unless site.username == 'kyledrake' + path = file.gsub(site.base_files_path, '').sub(/^\//, '') + + site_file = site.site_files_dataset[path: path] + + if site_file.nil? + next if File.directory? file + mtime = File.mtime file + site.add_site_file( + path: path, + size: File.size(file), + sha1_hash: Digest::SHA1.file(file).hexdigest, + updated_at: mtime, + created_at: mtime + ) + end + end + end +end + =begin desc 'Update screenshots' task :update_screenshots => [:environment] do diff --git a/views/templates/email/supporter_upgrade.erb b/views/templates/email/supporter_upgrade.erb index bee094af..2d257019 100644 --- a/views/templates/email/supporter_upgrade.erb +++ b/views/templates/email/supporter_upgrade.erb @@ -1,8 +1,6 @@ Hi there! -A Neocities administrator has upgraded your account to supporter! Someone at Neocities must really like you (or your site). :) - -We won't charge you for the upgrade, so no worries on that. You can see some of the new features you can use by visiting our supporter page at https://neocities.org/plan +A Neocities administrator has upgraded your account to supporter! You can see some of the new features you can use by visiting our supporter page at https://neocities.org/plan We're looking forward to seeing the awesome things you will do with it. @@ -12,4 +10,4 @@ If you have any questions or comments, or just want to say hi, feel free to cont From Penelope (the Neocities' cat/sysadmin), everyone that's helped work on Neocities, and on behalf of all our sites, our very best wishes for you (and your awesome web site). -- The Neocities Team \ No newline at end of file +- The Neocities Team From b6686531c79b1145cefcb239f32987a204fb5252 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Fri, 7 Aug 2015 10:26:50 -0500 Subject: [PATCH 3/6] site reporting csrf token --- views/admin/reports.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/views/admin/reports.erb b/views/admin/reports.erb index 3b6c0801..4fc8ceff 100644 --- a/views/admin/reports.erb +++ b/views/admin/reports.erb @@ -6,6 +6,7 @@
+ <%== csrf_token_input_html %> From ec306f9059881116db806a6323f3dd6c314ad3d7 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 12 Aug 2015 15:04:47 -0500 Subject: [PATCH 4/6] Ability to change stored credit card --- app/plan.rb | 3 ++ app/settings.rb | 26 +++++++++++++++++ models/site.rb | 4 +++ views/plan/_signupcode.erb | 4 --- views/settings/account.erb | 8 ++++++ views/settings/account/billing.erb | 45 ++++++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 views/settings/account/billing.erb diff --git a/app/plan.rb b/app/plan.rb index ee225d81..b79febd6 100644 --- a/app/plan.rb +++ b/app/plan.rb @@ -35,6 +35,9 @@ post '/plan/update' do end end + # Do not create customer if there is already a customer. Is this necessary? + redirect request.referrer if current_site.stripe_subscription_id + site ||= parent_site DB.transaction do diff --git a/app/settings.rb b/app/settings.rb index 74249cd1..2d91c3e1 100644 --- a/app/settings.rb +++ b/app/settings.rb @@ -334,3 +334,29 @@ get '/settings/unsubscribe_email/?' do end erb :'settings/account/unsubscribe' end + +post '/settings/update_card' do + require_login + + customer = Stripe::Customer.retrieve current_site.stripe_customer_id + + old_card_ids = customer.sources.collect {|s| s.id} + + begin + customer.sources.create source: params[:stripe_token] + rescue Stripe::InvalidRequestError => e + if e.message.match /cannot use a.+token more than once/ + flash[:error] = 'Card is already being used.' + redirect '/settings#billing' + else + raise e + end + end + + old_card_ids.each do |card_id| + customer.sources.retrieve(card_id).delete + end + + flash[:success] = 'Card information updated.' + redirect '/settings#billing' +end diff --git a/models/site.rb b/models/site.rb index eeeb89d2..6b9fc9e7 100644 --- a/models/site.rb +++ b/models/site.rb @@ -980,6 +980,10 @@ class Site < Sequel::Model PLAN_FEATURES[plan_type.to_sym][:name] end + def stripe_paying_supporter? + stripe_customer_id && !plan_ended && values[:plan_type].match(/free|special/).nil? + end + def unconverted_legacy_supporter? stripe_customer_id && !plan_ended && values[:plan_type].nil? && stripe_subscription_id.nil? end diff --git a/views/plan/_signupcode.erb b/views/plan/_signupcode.erb index 168c8656..1928f470 100644 --- a/views/plan/_signupcode.erb +++ b/views/plan/_signupcode.erb @@ -13,10 +13,6 @@ var signupform = $(event.target) - <% if current_site && parent_site.stripe_subscription_id %> - return true - <% end %> - var planError = $('#plan_error') planError.css('display', 'none') signupform.find(':submit').prop('disabled', true) diff --git a/views/settings/account.erb b/views/settings/account.erb index a6c305c1..0558abe2 100644 --- a/views/settings/account.erb +++ b/views/settings/account.erb @@ -27,6 +27,9 @@
  • Sites
  • Password
  • Email
  • + <% if current_site.stripe_paying_supporter? %> +
  • Billing
  • + <% end %>
    @@ -41,6 +44,11 @@
    <%== erb :'settings/account/email' %>
    + <% if current_site.stripe_paying_supporter? %> +
    + <%== erb :'settings/account/billing' %> +
    + <% end %>
    diff --git a/views/settings/account/billing.erb b/views/settings/account/billing.erb new file mode 100644 index 00000000..a9378954 --- /dev/null +++ b/views/settings/account/billing.erb @@ -0,0 +1,45 @@ +

    Change Credit Card

    +

    This allows you to change your currently stored credit card. You will be charged at the regular monthly cycle.

    + +
    + + + + + + +
    +

    + + + + + + + + + + + + +
    + + + Update Card +
    + +<%== erb :'plan/_signupcode', layout: false %> + + From 1efe0d486be3b1dd16f93c190a238fff595f12af Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 12 Aug 2015 15:33:29 -0500 Subject: [PATCH 5/6] Fix for plan update --- app/plan.rb | 3 --- views/plan/_signupcode.erb | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/plan.rb b/app/plan.rb index b79febd6..ee225d81 100644 --- a/app/plan.rb +++ b/app/plan.rb @@ -35,9 +35,6 @@ post '/plan/update' do end end - # Do not create customer if there is already a customer. Is this necessary? - redirect request.referrer if current_site.stripe_subscription_id - site ||= parent_site DB.transaction do diff --git a/views/plan/_signupcode.erb b/views/plan/_signupcode.erb index 1928f470..903e69de 100644 --- a/views/plan/_signupcode.erb +++ b/views/plan/_signupcode.erb @@ -13,6 +13,10 @@ var signupform = $(event.target) + <% if current_site && parent_site.stripe_subscription_id && !request.path.match(/\/settings/) %> + return true + <% end %> + var planError = $('#plan_error') planError.css('display', 'none') signupform.find(':submit').prop('disabled', true) From b5920d8ba8d5e9c55ffff23d6dbdeb3bf590535e Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Thu, 13 Aug 2015 19:01:13 -0500 Subject: [PATCH 6/6] Dedupe follows --- Rakefile | 13 +++++++++++++ migrations/073_add_follow_uniqueness.rb | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 migrations/073_add_follow_uniqueness.rb diff --git a/Rakefile b/Rakefile index b28ad941..ccb0c34e 100644 --- a/Rakefile +++ b/Rakefile @@ -240,6 +240,19 @@ task :prime_site_files => [:environment] do end end +desc 'dedupe_follows' +task :dedupe_follows => [:environment] do + follows = Follow.all + deduped_follows = Follow.all.uniq {|f| "#{f.site_id}_#{f.actioning_site_id}"} + + follows.each do |follow| + unless deduped_follows.include?(follow) + puts "deleting dedupe: #{follow.inspect}" + follow.delete + end + end +end + =begin desc 'Update screenshots' task :update_screenshots => [:environment] do diff --git a/migrations/073_add_follow_uniqueness.rb b/migrations/073_add_follow_uniqueness.rb new file mode 100644 index 00000000..4e80ff28 --- /dev/null +++ b/migrations/073_add_follow_uniqueness.rb @@ -0,0 +1,9 @@ +Sequel.migration do + up { + DB['alter table follows add constraint one_follow_per_site unique (site_id, actioning_site_id)'].first + } + + down { + DB['alter table follows drop constraint one_follow_per_site'].first + } +end
    Site