application_extension.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. module ApplicationExtension
  3. extend ActiveSupport::Concern
  4. included do
  5. include Redisable
  6. has_many :created_users, class_name: 'User', foreign_key: 'created_by_application_id', inverse_of: :created_by_application
  7. validates :name, length: { maximum: 60 }
  8. validates :website, url: true, length: { maximum: 2_000 }, if: :website?
  9. validates :redirect_uri, length: { maximum: 2_000 }
  10. # The relationship used between Applications and AccessTokens is using
  11. # dependent: delete_all, which means the ActiveRecord callback in
  12. # AccessTokenExtension is not run, so instead we manually announce to
  13. # streaming that these tokens are being deleted.
  14. before_destroy :push_to_streaming_api, prepend: true
  15. end
  16. def confirmation_redirect_uri
  17. redirect_uri.lines.first.strip
  18. end
  19. def push_to_streaming_api
  20. # TODO: #28793 Combine into a single topic
  21. payload = Oj.dump(event: :kill)
  22. access_tokens.in_batches do |tokens|
  23. redis.pipelined do |pipeline|
  24. tokens.ids.each do |id|
  25. pipeline.publish("timeline:access_token:#{id}", payload)
  26. end
  27. end
  28. end
  29. end
  30. end