public_link.rb 834 B

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