From 2c0c86328c4a6472f2543d1259620d25f4436620 Mon Sep 17 00:00:00 2001 From: Justin Ball Date: Wed, 26 Oct 2022 15:58:10 -0600 Subject: [PATCH] Removed bundles --- .../api/canvas_proxy_controller.rb | 6 +--- app/controllers/application_controller.rb | 21 +----------- app/models/application.rb | 5 +-- app/models/application_bundle.rb | 4 --- app/models/application_instance.rb | 1 - app/models/bundle.rb | 6 ---- app/models/bundle_instance.rb | 30 ---------------- config/environments/development.rb | 1 + config/initializers/apartment.rb | 3 -- db/migrate/20221025213143_remove_bundles.rb | 9 +++++ db/seeds.rb | 34 ------------------- .../application_controller_spec.rb | 10 ------ spec/factories/application_bundles.rb | 6 ---- spec/factories/application_instances.rb | 1 - spec/factories/bundle_instance.rb | 6 ---- spec/factories/bundles.rb | 6 ---- spec/models/application_bundle_spec.rb | 13 ------- spec/models/bundle_instance_spec.rb | 17 ---------- spec/models/bundle_spec.rb | 18 ---------- spec/support/application_instance_helper.rb | 8 ----- 20 files changed, 13 insertions(+), 192 deletions(-) delete mode 100644 app/models/application_bundle.rb delete mode 100644 app/models/bundle.rb delete mode 100644 app/models/bundle_instance.rb create mode 100644 db/migrate/20221025213143_remove_bundles.rb delete mode 100644 spec/factories/application_bundles.rb delete mode 100644 spec/factories/bundle_instance.rb delete mode 100644 spec/factories/bundles.rb delete mode 100644 spec/models/application_bundle_spec.rb delete mode 100644 spec/models/bundle_instance_spec.rb delete mode 100644 spec/models/bundle_spec.rb diff --git a/app/controllers/api/canvas_proxy_controller.rb b/app/controllers/api/canvas_proxy_controller.rb index 9a44b326b..ceae06707 100644 --- a/app/controllers/api/canvas_proxy_controller.rb +++ b/app/controllers/api/canvas_proxy_controller.rb @@ -5,11 +5,7 @@ class Api::CanvasProxyController < Api::ApiApplicationController before_action :protect_canvas_api def proxy - api = if params[:bundle_instance_token].present? - canvas_api(application_instance: targeted_app_instance) - else - canvas_api - end + api = canvas_api result = api.proxy(params[:lms_proxy_call_type], params.to_unsafe_h, request.body.read, params[:get_all]) allowed_headers = %w{ content-type link p3p x-canvas-meta x-canvas-user-id diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 04bf72056..6ca535691 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,10 +8,8 @@ class ApplicationController < ActionController::Base helper_method :current_application_instance, :current_application, - :current_bundle_instance, :current_canvas_course, :canvas_url, - :targeted_app_instance, :current_user_roles protected @@ -145,8 +143,7 @@ def setup_will_paginate def canvas_url @canvas_url ||= session[:canvas_url] || custom_canvas_api_domain || - current_application_instance&.site&.url || - current_bundle_instance&.site&.url + current_application_instance&.site&.url end def custom_canvas_api_domain @@ -178,13 +175,6 @@ def current_application Application.find_by(key: request.subdomains.first) end - def current_bundle_instance - @current_bundle ||= BundleInstance. - where(id_token: params[:bundle_instance_token]). - or(BundleInstance.where(id: params[:bundle_instance_id])). - first - end - def current_ability @current_ability ||= Ability.new(current_user, params[:context_id]) end @@ -220,13 +210,4 @@ def set_i18n_locale end end - def targeted_app_instance - key = request.subdomains.first - application = Application.find_by(key: key) - return nil if current_bundle_instance.nil? - current_bundle_instance. - application_instances. - find_by(application_id: application.id) - end - end diff --git a/app/models/application.rb b/app/models/application.rb index fd81a0cee..0543cf52b 100644 --- a/app/models/application.rb +++ b/app/models/application.rb @@ -9,8 +9,6 @@ class Application < ApplicationRecord validates :name, presence: true, uniqueness: true validates :key, presence: true, uniqueness: true - has_many :application_bundles - has_many :bundles, through: :application_bundles has_many :jwks has_many :lti_installs @@ -33,10 +31,9 @@ class Application < ApplicationRecord AUTH = "auth".freeze HELLOWORLD = "helloworld".freeze - def create_instance(site: nil, bundle_instance: nil, tenant: nil, lti_key: nil) + def create_instance(site: nil, tenant: nil, lti_key: nil) application_instance = application_instances.find_or_create_by( site: site, - bundle_instance: bundle_instance, lti_key: lti_key, ) if tenant.present? diff --git a/app/models/application_bundle.rb b/app/models/application_bundle.rb deleted file mode 100644 index 35ea24a7a..000000000 --- a/app/models/application_bundle.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ApplicationBundle < ApplicationRecord - belongs_to :application - belongs_to :bundle -end diff --git a/app/models/application_instance.rb b/app/models/application_instance.rb index e58d880cb..9b47926c6 100644 --- a/app/models/application_instance.rb +++ b/app/models/application_instance.rb @@ -5,7 +5,6 @@ class ApplicationInstance < ApplicationRecord belongs_to :application, counter_cache: true belongs_to :site - belongs_to :bundle_instance, required: false has_many :authentications, dependent: :destroy, inverse_of: :application_instance has_many :lti_deployments, dependent: :destroy diff --git a/app/models/bundle.rb b/app/models/bundle.rb deleted file mode 100644 index 11103a63c..000000000 --- a/app/models/bundle.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Bundle < ApplicationRecord - has_many :application_bundles - has_many :applications, through: :application_bundles - validates :key, presence: true, uniqueness: true - scope :by_application_id, ->(application_id) { where(applications: { id: application_id }) } -end diff --git a/app/models/bundle_instance.rb b/app/models/bundle_instance.rb deleted file mode 100644 index f24235c3c..000000000 --- a/app/models/bundle_instance.rb +++ /dev/null @@ -1,30 +0,0 @@ -class BundleInstance < ApplicationRecord - belongs_to :bundle - belongs_to :site - has_many :application_instances - has_many :applications, through: :bundle - has_secure_token :id_token - before_save :fix_entity_key - - def self.entity_key_from_url(url) - UrlHelper.host(url) - end - - def create_application_instances - bundle&.applications&.map do |app| - app.create_instance( - site: site, - bundle_instance: self, - tenant: bundle.shared_tenant ? tenant : nil, - ) - end - end - - def fix_entity_key - self.entity_key = BundleInstance.entity_key_from_url(entity_key) - end - - def tenant - "#{site.key}-#{bundle.key}" - end -end diff --git a/config/environments/development.rb b/config/environments/development.rb index 1c3921ea8..495e81c21 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -110,4 +110,5 @@ # This removes whitelisting of domains allowed to front the application # config.hosts.clear config.hosts << ".atomicjolt.win" + config.hosts << ".atomicjolt.xyz" end diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index b39fac814..ff1e30ba4 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -19,9 +19,6 @@ ApplicationInstance OauthState Site - Bundle - BundleInstance - ApplicationBundle ImsExport RequestStatistic RequestUserStatistic diff --git a/db/migrate/20221025213143_remove_bundles.rb b/db/migrate/20221025213143_remove_bundles.rb new file mode 100644 index 000000000..193bb4281 --- /dev/null +++ b/db/migrate/20221025213143_remove_bundles.rb @@ -0,0 +1,9 @@ +class RemoveBundles < ActiveRecord::Migration[7.0] + def change + drop_table :bundles + drop_table :bundle_instances + drop_table :application_bundles + + remove_column :application_instances, :bundle_instance_id, :integer + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 4a0a58c61..7df6e5d4e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -57,15 +57,6 @@ HELPER_ALL_ACCOUNTS: [], } -bundles = [ - { - name: "Hello World", - key: Application::HELLOWORLD, - applications: [Application::HELLOWORLD], - shared_tenant: true, - }, -] - file_path = Rails.root.join("db/lti_advantage_configs/hello_world_lti_advantage_config.json") hello_lti_advantage_config = JSON.parse(File.read(file_path)) @@ -312,31 +303,6 @@ def setup_application_instances(application, application_instances) setup_application_instances(application, application_instances) end - bundles.each do |attrs| - current_bundle = Bundle.find_or_create_by(key: attrs[:key]) - current_bundle.update!(name: attrs[:name], shared_tenant: attrs[:shared_tenant] == true) - - attrs[:applications].reduce(current_bundle) do |bundle, key| - app = Application.find_by!(key: key) - bundle.application_bundles.find_or_create_by(bundle_id: bundle.id, application_id: app.id) - bundle - end - end - - ApplicationInstance.where(bundle_instance_id: nil).find_each do |instance| - bundle = Bundle.includes(:applications).by_application_id(instance.application.id).last - BundleInstance.create(site: instance.site, bundle: bundle) - end - - BundleInstance.find_each do |bundle_instance| - site = bundle_instance.site - bundle_instance.applications.each do |app| - if instance = app.application_instances.find_by(site: site) - instance.update(bundle_instance: bundle_instance) if instance.bundle_instance_id.nil? - end - end - end - begin Apartment::Tenant.create Application::AUTH rescue Apartment::TenantExists diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 9e9a0f3d5..1434fe3ca 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -19,16 +19,6 @@ end end - describe "#current_bundle_instance" do - it "returns the canvas url" do - bundle_instance = FactoryBot.create(:bundle_instance) - subject.params = { - bundle_instance_token: bundle_instance.id_token, - } - expect(subject.send(:current_bundle_instance)).to eq(bundle_instance) - end - end - describe "#current_user_roles" do it "returns the roles for the current user when context is nil" do role = "admin" diff --git a/spec/factories/application_bundles.rb b/spec/factories/application_bundles.rb deleted file mode 100644 index 1233d016f..000000000 --- a/spec/factories/application_bundles.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryBot.define do - factory :application_bundle do - application - bundle - end -end diff --git a/spec/factories/application_instances.rb b/spec/factories/application_instances.rb index 3bc779c56..478e8e1f2 100644 --- a/spec/factories/application_instances.rb +++ b/spec/factories/application_instances.rb @@ -5,6 +5,5 @@ lti_secret { FactoryBot.generate(:password) } site canvas_token { FactoryBot.generate(:password) } - bundle_instance end end diff --git a/spec/factories/bundle_instance.rb b/spec/factories/bundle_instance.rb deleted file mode 100644 index 5c33b971b..000000000 --- a/spec/factories/bundle_instance.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryBot.define do - factory :bundle_instance do - bundle - site - end -end diff --git a/spec/factories/bundles.rb b/spec/factories/bundles.rb deleted file mode 100644 index 6c6c45a42..000000000 --- a/spec/factories/bundles.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryBot.define do - factory :bundle do - name { FactoryBot.generate(:name) } - key { ::SecureRandom::hex(15) } - end -end diff --git a/spec/models/application_bundle_spec.rb b/spec/models/application_bundle_spec.rb deleted file mode 100644 index b284a502c..000000000 --- a/spec/models/application_bundle_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "rails_helper" - -RSpec.describe ApplicationBundle, type: :model do - it "creates an application bundle" do - application = FactoryBot.create(:application) - bundle = FactoryBot.create(:bundle) - application_bundle = ApplicationBundle.create!( - application: application, - bundle: bundle, - ) - expect(application_bundle).to be - end -end diff --git a/spec/models/bundle_instance_spec.rb b/spec/models/bundle_instance_spec.rb deleted file mode 100644 index 91b3b3b3f..000000000 --- a/spec/models/bundle_instance_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require "rails_helper" - -RSpec.describe BundleInstance, type: :model do - describe "entity_key" do - it "should fix entity_key before_save" do - bundle = Bundle.create!(key: SecureRandom.uuid) - site = Site.create!(url: "https://bundle.example.com") - subject = BundleInstance.new( - entity_key: "https://example.com", - bundle: bundle, - site: site, - ) - subject.save! - expect(subject.entity_key).to eq("example.com") - end - end -end diff --git a/spec/models/bundle_spec.rb b/spec/models/bundle_spec.rb deleted file mode 100644 index 5e06b0556..000000000 --- a/spec/models/bundle_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "rails_helper" - -RSpec.describe Bundle, type: :model do - it "creates an application bundle" do - key = "test" - bundle = Bundle.create!(key: key) - expect(bundle).to be - end - - it "finds bundles by application id" do - key = "test" - bundle = Bundle.create!(key: key) - attrs = FactoryBot.attributes_for(:application) - application = bundle.applications.create!(attrs) - bundles = Bundle.includes(:applications).by_application_id(application.id) - expect(bundles.first.id).to eq(bundle.id) - end -end diff --git a/spec/support/application_instance_helper.rb b/spec/support/application_instance_helper.rb index 2ddc20c1f..41f6d3257 100644 --- a/spec/support/application_instance_helper.rb +++ b/spec/support/application_instance_helper.rb @@ -43,20 +43,12 @@ def self.make_application_instance default_config = {} - bundle = Bundle.find_or_create_by(key: GLOBAL_LTI_KEY) - - bundle_instance = FactoryBot.create( - :bundle_instance, - bundle: bundle, - ) - FactoryBot.create( :application_instance, application: application, lti_key: GLOBAL_LTI_KEY, tenant: GLOBAL_LTI_KEY, config: default_config, - bundle_instance: bundle_instance, ) end