Created
April 16, 2014 20:00
-
-
Save mintuhouse/f452b372f98d9c643c30 to your computer and use it in GitHub Desktop.
Ckeditor Custom Authorization Hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ckeditor.setup do |config| | |
config.current_user_method do | |
current_user | |
end | |
config.authorize_with :chronus | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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