Merge pull request #1115 from indentlabs/storage-fix

Storage fix
This commit is contained in:
Andrew Brown 2022-03-21 02:14:54 -05:00 committed by GitHub
commit e286b478d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 17 deletions

View File

@ -27,6 +27,10 @@ class PayPalPrepayProcessingJob < ApplicationJob
unless invoice.status == 'COMPLETED'
invoice.update(status: 'COMPLETED')
invoice.generate_promo_code!
# Add the extra Premium space
SubscriptionService.add_any_referral_bonuses(invoice.user, 'premium')
PremiumDowngradeJob.set(wait: (invoice.months).months).perform_later(invoice.user_id)
end
else

View File

@ -0,0 +1,15 @@
class PremiumDowngradeJob < ApplicationJob
queue_as :low_priority
def perform(*args)
user_id = args.shift
user = User.find_by(id: user_id)
raise "No user to downgrade; id=#{user_id}" if user.nil?
# Remove any bonus bandwidth granted by the plan
premium_bandwidth_bonus = BillingPlan.find(4).bonus_bandwidth_kb
user.update!(upload_bandwidth_kb: user.upload_bandwidth_kb - premium_bandwidth_bonus)
end
end

View File

@ -20,7 +20,7 @@ class Creature < ApplicationRecord
include Serendipitous::Concern
include Authority::Abilities
self.authorizer_name = 'CoreContentAuthorizer'
self.authorizer_name = 'ExtendedContentAuthorizer'
# Locations
relates :habitats, with: :wildlifeships

View File

@ -16,8 +16,7 @@ class Language < ApplicationRecord
self.authorizer_name = 'ExtendedContentAuthorizer'
def description
num_speakers = Lingualism.where(spoken_language_id: id).count
"Language spoken by #{ActionController::Base.helpers.pluralize num_speakers, 'character'}"
overview_field_value('Description')
end
def self.color

View File

@ -243,7 +243,7 @@ class ForumReplacementService < Service
'prison' => 'hoosegow locker',
'raccoon' => 'trash burgler',
'radio' => 'magic musicbox',
'rain' => 'cloudy waterdrops',
'rain' => 'cloudy juice',
'recursion' => 'recursion',
'replaced' => 'improved',
'reverse' => 'esrever',

View File

@ -7,6 +7,8 @@
:field_type: name
- :name: other_names
:label: Other names
- :name: description
:label: Description
- :name: universe_id
:label: Universe
:field_type: universe

View File

@ -14,12 +14,3 @@ if Date.current >= 'March 1, 2020'.to_date
Rails.application.config.content_types[:premium] -= [Lore]
end
end
# Lore free during the month of October
# Need to change Creature.rb authorizer at the end
if Date.current >= 'October 1, 2021'.to_date
if Date.current < 'November 1, 2021'.to_date
Rails.application.config.content_types[:free] << Creature
Rails.application.config.content_types[:premium] -= [Creature]
end
end

View File

@ -111,5 +111,42 @@ namespace :data_integrity do
end
end
desc "Ensure all users have the correct upload bandwidth amounts"
task correct_bandwidths: :environment do
base_bandwidth = User.new.upload_bandwidth_kb # 50_000
premium_bonus = BillingPlan.find(4).bonus_bandwidth_kb # 9_950_000
premium_total = base_bandwidth + premium_bonus # 10_000_000
referral_bonus = 100_000 # per referral
puts "Disabling SQL logging"
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
User.find_each do |user|
max_bandwidth = case user.selected_billing_plan_id
when nil, 1
base_bandwidth
when 2 # free-for-lifers
250_000
when 4, 5, 6 # premium
premium_total
else
raise "User with funky billing plan id: U=#{user.id} BP=#{user.selected_billing_plan_id}"
end
referral_bonus = user.referrals.count * referral_bonus
used_bandwidth = user.image_uploads.sum(:src_file_size)
remaining_bandwidth = max_bandwidth + referral_bonus - used_bandwidth
if user.upload_bandwidth_kb != remaining_bandwidth
puts "Correcting user #{user.id} bandwidth: #{user.upload_bandwidth_kb} --> #{remaining_bandwidth} (#{used_bandwidth} used)"
user.update(upload_bandwidth_kb: remaining_bandwidth)
end
end
puts "Re-enabling SQL logging"
ActiveRecord::Base.logger = old_logger
end
end

View File

@ -1,9 +1,5 @@
require 'test_helper'
class PageTagsControllerTest < ActionDispatch::IntegrationTest
test "should get remove" do
get page_tags_remove_url
assert_response :success
end
end