Aggiunge data personalizzata e pulsanti rapidi nell'archivio admin così il job di purge non elimina i video fino alla nuova scadenza. Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
1006 B
Ruby
40 lines
1006 B
Ruby
module Recordings
|
|
class ExtendExpiry
|
|
class Error < StandardError; end
|
|
|
|
def initialize(recording)
|
|
@recording = recording
|
|
end
|
|
|
|
def to_time(expires_at)
|
|
raise Error, "Data scadenza obbligatoria" if expires_at.blank?
|
|
|
|
parsed = expires_at.is_a?(Time) || expires_at.is_a?(ActiveSupport::TimeWithZone) ? expires_at : Time.zone.parse(expires_at.to_s)
|
|
raise Error, "Data non valida" unless parsed
|
|
|
|
apply(parsed)
|
|
end
|
|
|
|
def by_days(days)
|
|
count = days.to_i
|
|
raise Error, "Giorni non validi" if count <= 0
|
|
|
|
base = [@recording.expires_at, Time.current].compact.max
|
|
apply(base + count.days)
|
|
end
|
|
|
|
private
|
|
|
|
def apply(new_expires_at)
|
|
raise Error, "Replay già eliminato" if @recording.deleted?
|
|
raise Error, "La scadenza deve essere nel futuro" unless new_expires_at > Time.current
|
|
|
|
@recording.update!(
|
|
expires_at: new_expires_at,
|
|
expiry_warning_sent_at: nil
|
|
)
|
|
@recording
|
|
end
|
|
end
|
|
end
|