diff --git a/app/jobs/pay_pal_prepay_processing_job.rb b/app/jobs/pay_pal_prepay_processing_job.rb index 3ca107af..5b025b37 100644 --- a/app/jobs/pay_pal_prepay_processing_job.rb +++ b/app/jobs/pay_pal_prepay_processing_job.rb @@ -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 diff --git a/app/jobs/premium_downgrade_job.rb b/app/jobs/premium_downgrade_job.rb new file mode 100644 index 00000000..c4ad07e2 --- /dev/null +++ b/app/jobs/premium_downgrade_job.rb @@ -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 \ No newline at end of file diff --git a/app/models/page_types/creature.rb b/app/models/page_types/creature.rb index 19ad5da3..61925486 100644 --- a/app/models/page_types/creature.rb +++ b/app/models/page_types/creature.rb @@ -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 diff --git a/app/models/page_types/language.rb b/app/models/page_types/language.rb index c2e94f6e..0ff155b0 100644 --- a/app/models/page_types/language.rb +++ b/app/models/page_types/language.rb @@ -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 diff --git a/app/services/forum_replacement_service.rb b/app/services/forum_replacement_service.rb index 7d0576f9..139941d6 100644 --- a/app/services/forum_replacement_service.rb +++ b/app/services/forum_replacement_service.rb @@ -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', diff --git a/app/services/technical_debt_service.rb b/app/services/technical_debt_service.rb deleted file mode 100644 index e69de29b..00000000 diff --git a/config/attributes/language.yml b/config/attributes/language.yml index 0db82303..f4b9d605 100644 --- a/config/attributes/language.yml +++ b/config/attributes/language.yml @@ -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 diff --git a/config/initializers/promos.rb b/config/initializers/promos.rb index 560d1547..b1b5cb9b 100644 --- a/config/initializers/promos.rb +++ b/config/initializers/promos.rb @@ -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 diff --git a/lib/tasks/data_integrity.rake b/lib/tasks/data_integrity.rake index 0f738259..77a6bd2e 100644 --- a/lib/tasks/data_integrity.rake +++ b/lib/tasks/data_integrity.rake @@ -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 diff --git a/test/controllers/page_tags_controller_test.rb b/test/controllers/page_tags_controller_test.rb index 2f89a08a..a3f2da9f 100644 --- a/test/controllers/page_tags_controller_test.rb +++ b/test/controllers/page_tags_controller_test.rb @@ -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