Update abilities for ckeditor4 images

Add the image controller to use the obsolete load_and_authorize_resource
and authorize_resource methods in the gem
This commit is contained in:
Raúl Fuentes
2018-08-14 14:21:27 +02:00
committed by Javi Martín
parent 424535c1ae
commit 8e68f4bbd0
3 changed files with 41 additions and 0 deletions

View File

@@ -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

View File

@@ -3,6 +3,10 @@ module Abilities
include CanCan::Ability include CanCan::Ability
def initialize(user) 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], Debate
can [:read, :map, :summary, :share], Proposal can [:read, :map, :summary, :share], Proposal
can :read, Comment can :read, Comment

View File

@@ -1,5 +1,6 @@
Rails.application.routes.draw do Rails.application.routes.draw do
mount Ckeditor::Engine => '/ckeditor'
if Rails.env.development? || Rails.env.staging? if Rails.env.development? || Rails.env.staging?
get '/sandbox' => 'sandbox#index' get '/sandbox' => 'sandbox#index'
get '/sandbox/*template' => 'sandbox#show' get '/sandbox/*template' => 'sandbox#show'