1

管理者がログインしてプロジェクトに関連するチケットを作成し、添付ファイルをエラーなしで正しくアップロードした後、ダウンロードしようとすると、誤った状態になり、代わりcan?cannot?彼がアセットをダウンロードできたので、作成に必要なもの管理者は、現在のコントローラーの表示アクションを変更せずにダウンロードできますか?

注:ユーザーがアセットを表示する権限を持っていない場合に発生するはずの誤った状態ですが、管理者にこれがどのように発生するかは本にもありません。誰もこれを経験していますか?

class FilesController < ApplicationController
    before_filter :authenticate_user!

    def show
        asset = Asset.find(params[:id])
        if  can?(:view, asset.ticket.project)
            send_file asset.asset.path, :filename => asset.asset_file_name,
                                        :content_type => asset.asset_content_type
        else
            flash[:alert] = "The asset you were looking for could not be found."
            redirect_to root_path
        end
    end
end

アビリティ.rb

class Ability
    include CanCan::Ability

    def initialize(user)
        user.permissions.each do |permission|
            can permission.action.to_sym, permission.thing_type.constantize do |thing|
                thing.nil? || permission.thing_id.nil? || permission.thing_id == thing.id
            end
        end
    end
end
4

0 に答える 0