Introduce new enabled
option for CodeHarbor
* Fix tests to ensure they work independent of config option
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
|
||||
class CodeharborLinksController < ApplicationController
|
||||
include CommonBehavior
|
||||
before_action :verify_codeharbor_activation
|
||||
before_action :set_codeharbor_link, only: %i[show edit update destroy]
|
||||
|
||||
def new
|
||||
base_url = CodeOcean::Config.new(:code_ocean).read[:codeharbor][:url]
|
||||
base_url = CodeOcean::Config.new(:code_ocean).read[:codeharbor][:url] || ''
|
||||
@codeharbor_link = CodeharborLink.new(push_url: base_url + '/import_exercise', check_uuid_url: base_url + '/import_uuid_check')
|
||||
authorize!
|
||||
end
|
||||
@@ -36,6 +37,10 @@ class CodeharborLinksController < ApplicationController
|
||||
authorize @codeharbor_link
|
||||
end
|
||||
|
||||
def verify_codeharbor_activation
|
||||
raise Pundit::NotAuthorizedError unless policy(CodeharborLink).enabled?
|
||||
end
|
||||
|
||||
def set_codeharbor_link
|
||||
@codeharbor_link = CodeharborLink.find(params[:id])
|
||||
@codeharbor_link.user = current_user
|
||||
|
@@ -8,23 +8,27 @@ class CodeharborLinkPolicy < ApplicationPolicy
|
||||
end
|
||||
|
||||
def new?
|
||||
teacher? || admin?
|
||||
enabled? && (teacher? || admin?)
|
||||
end
|
||||
|
||||
def create?
|
||||
teacher? || admin?
|
||||
enabled? && (teacher? || admin?)
|
||||
end
|
||||
|
||||
def edit?
|
||||
owner?
|
||||
enabled? && owner?
|
||||
end
|
||||
|
||||
def update?
|
||||
owner?
|
||||
enabled? && owner?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
owner?
|
||||
enabled? && owner?
|
||||
end
|
||||
|
||||
def enabled?
|
||||
CodeOcean::Config.new(:code_ocean).read[:codeharbor][:enabled]
|
||||
end
|
||||
|
||||
private
|
||||
|
Reference in New Issue
Block a user