diff --git a/app/controllers/ckeditor/pictures_controller.rb b/app/controllers/ckeditor/pictures_controller.rb new file mode 100644 index 000000000..1dded38f3 --- /dev/null +++ b/app/controllers/ckeditor/pictures_controller.rb @@ -0,0 +1,36 @@ +class Ckeditor::PicturesController < Ckeditor::ApplicationController + load_and_authorize_resource + def index + @pictures = Ckeditor.picture_adapter.find_all(ckeditor_pictures_scope) + @pictures = Ckeditor::Paginatable.new(@pictures).page(params[:page]) + + respond_to do |format| + format.html { render :layout => @pictures.first_page? } + end + end + + def create + @picture = Ckeditor.picture_model.new + respond_with_asset(@picture) + end + + def destroy + @picture.destroy + + respond_to do |format| + format.html { redirect_to pictures_path } + format.json { render :nothing => true, :status => 204 } + end + end + + protected + + def find_asset + @picture = Ckeditor.picture_adapter.get!(params[:id]) + end + + def authorize_resource + model = (@picture || Ckeditor.picture_model) + @authorization_adapter.try(:authorize, params[:action], model) + end +end \ No newline at end of file diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 23cfdc971..dcc430cdd 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -3,6 +3,10 @@ module Abilities include CanCan::Ability def initialize(user) + can :access, :ckeditor # needed to access Ckeditor filebrowser + can [:access, :read, :create, :destroy], Ckeditor::Picture + can [:access, :read, :create, :destroy], Ckeditor::AttachmentFile + can [:read, :map], Debate can [:read, :map, :summary, :share], Proposal can :read, Comment diff --git a/config/routes.rb b/config/routes.rb index f3739c922..1eb129a21 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do + mount Ckeditor::Engine => '/ckeditor' if Rails.env.development? || Rails.env.staging? get '/sandbox' => 'sandbox#index' get '/sandbox/*template' => 'sandbox#show'