【问题标题】:Is it possible to restrict the access to assets by business logic?是否可以通过业务逻辑限制对资产的访问?
【发布时间】:2012-07-20 19:36:22
【问题描述】:

我创建了账单,应该可以从管理员打开,但不能作为普通用户打开。此账单pdf将在app/assets/pdfs中的某些业务流程之后创建。

 assets_pdf_url if user_signed_in?

是否可以通过某些规则限制特定资产?

【问题讨论】:

  • 您使用的是 apache 还是 IIS?这可以在网络服务器级别进行配置
  • apache ...但只有rails知道用户权限

标签: ruby-on-rails-3 permissions assets


【解决方案1】:

将受限资产存储在公用文件夹之外的某个文件夹中,以便仅通过访问 URL 无法访问它们,然后创建使用 send_file 或 send_data 的操作。这样你就可以用任何你想要的逻辑来包装它。

# in controller
def show
  @bill = Bill.find(params[:id])
  if user_signed_in?
    send_file Rails.root.join('bill_pdfs',"#{@bill.id}.pdf")
  else
    redirect_to '/', :error => "Only logged in users may download"
  end
end

【讨论】:

    猜你喜欢
    • 2019-05-07
    • 2018-06-08
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 2022-11-18
    • 2012-04-25
    相关资源
    最近更新 更多