public_link.rb 885 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class PublicLink < ApplicationModel
  3. include CanPriorization
  4. include ChecksClientNotification
  5. include PublicLink::TriggersSubscriptions
  6. AVAILABLE_SCREENS = %w[login signup password_reset].freeze
  7. validates :link, presence: true, length: { maximum: 500 }
  8. validates :title, presence: true, length: { maximum: 200 }
  9. validates :screen, presence: true, inclusion: { in: AVAILABLE_SCREENS }
  10. before_validation :check_link
  11. default_scope { order(:prio, :id) }
  12. belongs_to :created_by, class_name: 'User'
  13. belongs_to :updated_by, class_name: 'User'
  14. client_notification_send_type 'public'
  15. private
  16. def check_link
  17. return true if link.blank?
  18. uri = URI.parse(link)
  19. raise Exceptions::UnprocessableEntity, "Invalid link '#{link}'." if !uri.is_a?(URI::HTTP)
  20. true
  21. end
  22. end