`file_key` is a random 9-character base-62 string that will be used as the image filename in the future. `is_public` is whether the image can be viewed without authentication or not. Users running downstream boorus must run `bin/rails db:migrate` and `script/fixes/109_generate_media_asset_file_keys.rb` after this commit.
20 lines
305 B
Ruby
20 lines
305 B
Ruby
# frozen_string_literal: true
|
|
|
|
class MediaAssetPolicy < ApplicationPolicy
|
|
def index?
|
|
true
|
|
end
|
|
|
|
def can_see_image?
|
|
record.post.blank? || record.post.visible?(user)
|
|
end
|
|
|
|
def api_attributes
|
|
if can_see_image?
|
|
super
|
|
else
|
|
super.excluding(:md5, :file_key)
|
|
end
|
|
end
|
|
end
|