Sha256: b3e38c9cb173646c353225404ff4242424b6ff9eea8f7ba8b96d0d9b9fcbcd5a

Contents?: true

Size: 1.74 KB

Versions: 40

Compression:

Stored size: 1.74 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
    g = @photo.gallery
    @photo.is_trash = true
    @photo.save
    g.touch
    redirect_to request.referrer || root_path
  end

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

  def j_create
    # 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
    authorize! :create_photo, gallery

    @photo = Photo.new params[:photo].permit!
    @photo.is_public = true   
    @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'
      }
      render :json => [ j ]
    else
      render :json => { "errors" => @photo.errors } 
    end
  end

end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ish_manager-0.1.8.217 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.216 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.215 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.214 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.213 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.212 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.211 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.210 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.209 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.208 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.207 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.206 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.205 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.204 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.203 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.202 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.201 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.200 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.199 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.198 app/controllers/ish_manager/photos_controller.rb