Memorize config options instead of reading them from file over and over again
This commit is contained in:
@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
|
|||||||
include Pundit::Authorization
|
include Pundit::Authorization
|
||||||
|
|
||||||
MEMBER_ACTIONS = %i[destroy edit show update].freeze
|
MEMBER_ACTIONS = %i[destroy edit show update].freeze
|
||||||
|
RENDER_HOST = CodeOcean::Config.new(:code_ocean).read[:render_host]
|
||||||
|
|
||||||
after_action :verify_authorized, except: %i[welcome]
|
after_action :verify_authorized, except: %i[welcome]
|
||||||
around_action :mnemosyne_trace
|
around_action :mnemosyne_trace
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
module ExerciseHelper
|
module ExerciseHelper
|
||||||
include LtiHelper
|
include LtiHelper
|
||||||
|
|
||||||
|
CODEPILOT_CONFIG = CodeOcean::Config.new(:code_ocean).read[:code_pilot]
|
||||||
|
|
||||||
def embedding_parameters(exercise)
|
def embedding_parameters(exercise)
|
||||||
"locale=#{I18n.locale}&token=#{exercise.token}"
|
"locale=#{I18n.locale}&token=#{exercise.token}"
|
||||||
end
|
end
|
||||||
@ -12,11 +14,6 @@ module ExerciseHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def qa_url
|
def qa_url
|
||||||
config = CodeOcean::Config.new(:code_ocean)
|
CODEPILOT_CONFIG[:url] if CODEPILOT_CONFIG[:enabled]
|
||||||
enabled = config.read[:code_pilot][:enabled]
|
|
||||||
|
|
||||||
if enabled
|
|
||||||
config.read[:code_pilot][:url]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CodeharborLinkPolicy < ApplicationPolicy
|
class CodeharborLinkPolicy < ApplicationPolicy
|
||||||
|
CODEHARBOR_CONFIG = CodeOcean::Config.new(:code_ocean).read[:codeharbor]
|
||||||
|
|
||||||
def index?
|
def index?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -30,7 +32,7 @@ class CodeharborLinkPolicy < ApplicationPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enabled?
|
def enabled?
|
||||||
CodeOcean::Config.new(:code_ocean).read[:codeharbor][:enabled]
|
CODEHARBOR_CONFIG[:enabled]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -5,12 +5,9 @@ require 'rails_helper'
|
|||||||
describe CodeharborLinksController do
|
describe CodeharborLinksController do
|
||||||
let(:user) { create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
|
|
||||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
|
||||||
let(:codeharbor_config) { {codeharbor: {enabled: true, url: 'https://test.url'}} }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
|
allow(CodeharborLinkPolicy::CODEHARBOR_CONFIG).to receive(:[]).with(:enabled).and_return(true)
|
||||||
allow(codeocean_config).to receive(:read).and_return(codeharbor_config)
|
allow(CodeharborLinkPolicy::CODEHARBOR_CONFIG).to receive(:[]).with(:url).and_return('https://test.url')
|
||||||
allow(controller).to receive(:current_user).and_return(user)
|
allow(controller).to receive(:current_user).and_return(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,12 +8,8 @@ describe CodeharborLinkPolicy do
|
|||||||
let(:codeharbor_link) { create(:codeharbor_link) }
|
let(:codeharbor_link) { create(:codeharbor_link) }
|
||||||
|
|
||||||
context 'when CodeHarbor link is enabled' do
|
context 'when CodeHarbor link is enabled' do
|
||||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
|
||||||
let(:codeharbor_config) { {codeharbor: {enabled: true}} }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
|
allow(CodeharborLinkPolicy::CODEHARBOR_CONFIG).to receive(:[]).with(:enabled).and_return(true)
|
||||||
allow(codeocean_config).to receive(:read).and_return(codeharbor_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
%i[index? show?].each do |action|
|
%i[index? show?].each do |action|
|
||||||
@ -64,12 +60,8 @@ describe CodeharborLinkPolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when CodeHabor link is disabled' do
|
context 'when CodeHabor link is disabled' do
|
||||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
|
||||||
let(:codeharbor_config) { {codeharbor: {enabled: false}} }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
|
allow(CodeharborLinkPolicy::CODEHARBOR_CONFIG).to receive(:[]).with(:enabled).and_return(false)
|
||||||
allow(codeocean_config).to receive(:read).and_return(codeharbor_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
permissions :enabled? do
|
permissions :enabled? do
|
||||||
|
Reference in New Issue
Block a user