public_link.rb 908 B

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