diff options
Diffstat (limited to 'app/models/asset.rb')
| -rw-r--r-- | app/models/asset.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/asset.rb b/app/models/asset.rb index 8cec4371..b256b929 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb | |||
| @@ -41,6 +41,13 @@ class Asset < ApplicationRecord | |||
| 41 | :ids => page_ids).distinct | 41 | :ids => page_ids).distinct |
| 42 | end | 42 | end |
| 43 | 43 | ||
| 44 | # An asset's reach is the reach of the pages carrying it: destroying one | ||
| 45 | # removes it from every live page at once, so a single restricted | ||
| 46 | # attachment makes the destruction a restricted act. | ||
| 47 | def restricted? | ||
| 48 | attached_nodes.any?(&:restricted?) | ||
| 49 | end | ||
| 50 | |||
| 44 | # Witnessed destruction. Destroying an asset is a public-facing act | 51 | # Witnessed destruction. Destroying an asset is a public-facing act |
| 45 | # even when unattached. The original and its variants are publicly | 52 | # even when unattached. The original and its variants are publicly |
| 46 | # reachable under /system/uploads, so an entry is always written, | 53 | # reachable under /system/uploads, so an entry is always written, |
| @@ -49,6 +56,11 @@ class Asset < ApplicationRecord | |||
| 49 | # participates as the first non-Node subject (its participant row | 56 | # participates as the first non-Node subject (its participant row |
| 50 | # dangles after destroy, by design, the name lives on in metadata). | 57 | # dangles after destroy, by design, the name lives on in metadata). |
| 51 | def destroy_witnessed! user: | 58 | def destroy_witnessed! user: |
| 59 | if user && !user.may_change_live?(self) | ||
| 60 | errors.add(:base, :not_permitted) | ||
| 61 | raise ActiveRecord::RecordInvalid.new(self) | ||
| 62 | end | ||
| 63 | |||
| 52 | ActiveRecord::Base.transaction do | 64 | ActiveRecord::Base.transaction do |
| 53 | affected = attached_nodes.to_a | 65 | affected = attached_nodes.to_a |
| 54 | headline_losses = affected.select do |node| | 66 | headline_losses = affected.select do |node| |
