diff --git a/Rakefile b/Rakefile index 4ac5badd..ccb0c34e 100644 --- a/Rakefile +++ b/Rakefile @@ -216,6 +216,43 @@ 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 + +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/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/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 diff --git a/models/site.rb b/models/site.rb index 44a95f60..6b9fc9e7 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 @@ -976,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/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 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 %> diff --git a/views/plan/_signupcode.erb b/views/plan/_signupcode.erb index 168c8656..903e69de 100644 --- a/views/plan/_signupcode.erb +++ b/views/plan/_signupcode.erb @@ -13,7 +13,7 @@ var signupform = $(event.target) - <% if current_site && parent_site.stripe_subscription_id %> + <% if current_site && parent_site.stripe_subscription_id && !request.path.match(/\/settings/) %> return true <% end %> 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 %> + + 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
    Site