Skip to content

Instantly share code, notes, and snippets.

@mintuhouse
Created April 16, 2014 20:00
Show Gist options
  • Save mintuhouse/f452b372f98d9c643c30 to your computer and use it in GitHub Desktop.
Save mintuhouse/f452b372f98d9c643c30 to your computer and use it in GitHub Desktop.
Ckeditor Custom Authorization Hook
Ckeditor.setup do |config|
config.current_user_method do
current_user
end
config.authorize_with :chronus
end
module Ckeditor
module Hooks
class ChronusAuthorization
include Ckeditor::Helpers::Controllers
def initialize(controller)
@controller = controller
@controller.extend ControllerExtension
end
def authorize(action, model_object = nil)
raise Authorization::PermissionDenied unless authorized?(action, model_object)
end
def authorized?(action, model_object = nil)
if action
if @controller.current_user_for_chronus.is_admin?
[:index, :create, :destroy].include? action
else
[:create].include? action
end
end
end
private
module ControllerExtension
def current_user_for_chronus
ckeditor_current_user
end
end
end
end
end
Ckeditor::AUTHORIZATION_ADAPTERS[:chronus] = Ckeditor::Hooks::ChronusAuthorization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment