Sha256: c03dfd1af019a8cb563fffb380f90e6193a308e299c35fb5c25a2c3211102444

Contents?: true

Size: 1.72 KB

Versions: 33

Compression:

Stored size: 1.72 KB

Contents

class IshManager::PhotosController < IshManager::ApplicationController

  # @TODO: this is bad? _vp_ 20170513
  skip_authorization_check :only => [ :j_create ]
  protect_from_forgery :except => [ :j_create] 

  def without_gallery
    @photos = Photo.unscoped.where( :gallery => nil, :is_trash => false )
  end

  def destroy
    @photo = Photo.unscoped.find params[:id]
    authorize! :destroy, @photo
    @photo.is_trash = true
    @photo.save
    @photo.gallery.touch
    redirect_to request.referrer || root_path
  end

  def show
    @photo = Photo.unscoped.find params[:id]
  end

  def j_create
    @photo = Photo.new params[:photo].permit!
    authorize! :create, @photo
    @photo.is_public = true
   
    # find this gallery
    if params[:galleryname]
      gallery = Gallery.unscoped.where( :galleryname => params[:galleryname] ).first
      gallery ||= Gallery.unscoped.find params[:galleryname]
    elsif params[:gallery_id] # this one, let's normalize on id everywhere in manager.
      gallery = Gallery.unscoped.find( params[:gallery_id] )
      gallery ||= Gallery.unscoped.where( :galleryname => params[:gallery_id] ).first
    end
    @photo.gallery = gallery
    
    # cache
    @photo.gallery.site.touch if @photo.gallery.site
    @photo.gallery.city.touch if @photo.gallery.city
    @photo.gallery.touch

    if @photo.save
      j = { :name => @photo.photo.original_filename,
        :size => @photo.photo.size,
        :url => @photo.photo.url( :large ),
        :thumbnail_url => @photo.photo.url( :thumb ),
        :delete_url => photo_path(@photo),
        :delete_type => 'DELETE',
        :name => @photo.name
      }
      render :json => [ j ]
    else
      render :json => { "errors" => @photo.errors } 
    end
  end

end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ish_manager-0.1.8.37 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.36 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.35 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.34 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.33 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.32 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.31 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.30 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.29 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.28 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.27 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.26 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.25 app/controllers/ish_manager/photos_controller.rb