Sha256: 35fc9dde6c29d60b38a001f575e86aea384c27bc13907f8decfab250ef6b5706

Contents?: true

Size: 1.96 KB

Versions: 128

Compression:

Stored size: 1.96 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]

  ## Alphabetized : )

  def destroy
    @photo = Photo.unscoped.find params[:id]
    authorize! :destroy, @photo
    @photo.gallery.touch if @photo.gallery
    @photo.is_trash = true
    flag = @photo.save
    if flag
      flash[:notice] = "Success"
    else
      flash[:alert] = "No luck: #{@photo.errors.messages}"
    end
    redirect_to request.referrer || root_path
  end

  def index
    authorize! :index, Photo
    @photos = Photo.where( user_profile: @current_profile ).page( params[:photos_page] )
  end

  def j_create
    if params[:slug]
      gallery = Gallery.unscoped.where( :slug => params[:slug] ).first
      gallery ||= Gallery.unscoped.find params[:slug]
    elsif params[:gallery_id]
      gallery = Gallery.unscoped.find( params[:gallery_id] )
      gallery ||= Gallery.unscoped.where( :slug => params[:gallery_id] ).first
    end
    authorize! :create_photo, gallery

    @photo = Photo.new params[:photo].permit!
    @photo.is_public = true
    @photo.gallery = gallery

    @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 => {
        message: @photo.errors.full_messages.join(", "),
        filename: @photo.photo.original_filename,
      }, status: 400
    end
  end

  def new
    authorize! :new, Photo
    @photo = Photo.new
  end

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

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

end

Version data entries

128 entries across 128 versions & 1 rubygems

Version Path
ish_manager-0.1.8.513 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.512 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.511 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.510 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.509 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.508 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.507 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.506 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.505 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.504 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.503 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.500 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.499 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.498 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.497 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.496 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.495 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.494 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.493 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.492 app/controllers/ish_manager/photos_controller.rb