Reapply changes to how disabling modeling works
```shell
git cherry-pick d82c7f817a
--no-commit
```
This commit is contained in:
parent
54b25ef08e
commit
3242981eb2
6 changed files with 17 additions and 5 deletions
|
@ -1,12 +1,10 @@
|
||||||
class PetsController < ApplicationController
|
class PetsController < ApplicationController
|
||||||
rescue_from Neopets::CustomPets::PetNotFound, with: :pet_not_found
|
rescue_from Neopets::CustomPets::PetNotFound, with: :pet_not_found
|
||||||
rescue_from Neopets::CustomPets::DownloadError, with: :pet_download_error
|
rescue_from Neopets::CustomPets::DownloadError, with: :pet_download_error
|
||||||
|
rescue_from Pet::ModelingDisabled, with: :modeling_disabled
|
||||||
rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format
|
rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format
|
||||||
|
|
||||||
def load
|
def load
|
||||||
# Uncomment this to temporarily disable modeling for most users.
|
|
||||||
# return modeling_disabled unless user_signed_in? && current_user.admin?
|
|
||||||
|
|
||||||
raise Neopets::CustomPets::PetNotFound unless params[:name]
|
raise Neopets::CustomPets::PetNotFound unless params[:name]
|
||||||
@pet = Pet.load(params[:name])
|
@pet = Pet.load(params[:name])
|
||||||
points = contribute(current_user, @pet)
|
points = contribute(current_user, @pet)
|
||||||
|
|
|
@ -4,6 +4,8 @@ class Pet < ApplicationRecord
|
||||||
attr_reader :items, :pet_state, :alt_style
|
attr_reader :items, :pet_state, :alt_style
|
||||||
|
|
||||||
def load!(timeout: nil)
|
def load!(timeout: nil)
|
||||||
|
raise ModelingDisabled unless Rails.configuration.modeling_enabled
|
||||||
|
|
||||||
viewer_data_hash = Neopets::CustomPets.fetch_viewer_data(name, timeout:)
|
viewer_data_hash = Neopets::CustomPets.fetch_viewer_data(name, timeout:)
|
||||||
use_viewer_data(ViewerData.new(viewer_data_hash))
|
use_viewer_data(ViewerData.new(viewer_data_hash))
|
||||||
end
|
end
|
||||||
|
@ -59,6 +61,7 @@ class Pet < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
class UnexpectedDataFormat < RuntimeError;end
|
class UnexpectedDataFormat < RuntimeError;end
|
||||||
|
class ModelingDisabled < RuntimeError;end
|
||||||
|
|
||||||
# A representation of a Neopets::CustomPets viewer data response, translated
|
# A representation of a Neopets::CustomPets viewer data response, translated
|
||||||
# to DTI's database models!
|
# to DTI's database models!
|
||||||
|
@ -153,4 +156,3 @@ class Pet < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,10 @@ Rails.application.configure do
|
||||||
# Allow connections on Vagrant's private network.
|
# Allow connections on Vagrant's private network.
|
||||||
config.web_console.permissions = '10.0.2.2'
|
config.web_console.permissions = '10.0.2.2'
|
||||||
|
|
||||||
|
# Allow pets to model new data. (If modeling is ever broken, disable this in
|
||||||
|
# production while we fix it!)
|
||||||
|
config.modeling_enabled = true
|
||||||
|
|
||||||
# Use a local copy of Impress 2020, presumably running on port 4000. (Can
|
# Use a local copy of Impress 2020, presumably running on port 4000. (Can
|
||||||
# override this with the IMPRESS_2020_ORIGIN environment variable!)
|
# override this with the IMPRESS_2020_ORIGIN environment variable!)
|
||||||
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",
|
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",
|
||||||
|
|
|
@ -122,6 +122,10 @@ Rails.application.configure do
|
||||||
# Skip DNS rebinding protection for the default health check endpoint.
|
# Skip DNS rebinding protection for the default health check endpoint.
|
||||||
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
|
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
|
||||||
|
|
||||||
|
# Allow pets to model new data. (If modeling is ever broken, disable this
|
||||||
|
# here while we fix it!)
|
||||||
|
config.modeling_enabled = false
|
||||||
|
|
||||||
# Use the live copy of Impress 2020. (Can override this with the
|
# Use the live copy of Impress 2020. (Can override this with the
|
||||||
# IMPRESS_2020_ORIGIN environment variable!)
|
# IMPRESS_2020_ORIGIN environment variable!)
|
||||||
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",
|
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",
|
||||||
|
|
|
@ -62,6 +62,10 @@ Rails.application.configure do
|
||||||
# Raise error when a before_action's only/except options reference missing actions
|
# Raise error when a before_action's only/except options reference missing actions
|
||||||
config.action_controller.raise_on_missing_callback_actions = true
|
config.action_controller.raise_on_missing_callback_actions = true
|
||||||
|
|
||||||
|
# Allow pets to model new data. (If modeling is ever broken, disable this in
|
||||||
|
# production while we fix it!)
|
||||||
|
config.modeling_enabled = true
|
||||||
|
|
||||||
# Use a local copy of Impress 2020, presumably running on port 4000. (Can
|
# Use a local copy of Impress 2020, presumably running on port 4000. (Can
|
||||||
# override this with the IMPRESS_2020_ORIGIN environment variable!)
|
# override this with the IMPRESS_2020_ORIGIN environment variable!)
|
||||||
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",
|
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",
|
||||||
|
|
|
@ -605,7 +605,7 @@ RSpec.describe Pet, type: :model do
|
||||||
context "when modeling is disabled" do
|
context "when modeling is disabled" do
|
||||||
before { allow(Rails.configuration).to receive(:modeling_enabled) { false } }
|
before { allow(Rails.configuration).to receive(:modeling_enabled) { false } }
|
||||||
|
|
||||||
pending("raises an error") do
|
it("raises an error") do
|
||||||
expect { Pet.load("matts_bat") }.to raise_error(Pet::ModelingDisabled)
|
expect { Pet.load("matts_bat") }.to raise_error(Pet::ModelingDisabled)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue