2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-09 14:04:34 -04:00
|
|
|
require 'singleton'
|
|
|
|
|
|
|
|
class TagManager
|
|
|
|
include Singleton
|
|
|
|
include RoutingHelper
|
|
|
|
|
2017-04-14 20:15:46 -04:00
|
|
|
def web_domain?(domain)
|
|
|
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.web_domain).zero?
|
|
|
|
end
|
|
|
|
|
2016-10-06 10:36:16 -04:00
|
|
|
def local_domain?(domain)
|
2016-11-15 10:56:29 -05:00
|
|
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
|
2016-10-06 10:36:16 -04:00
|
|
|
end
|
|
|
|
|
2017-04-24 20:47:31 -04:00
|
|
|
def normalize_domain(domain)
|
2017-05-04 20:23:01 -04:00
|
|
|
return if domain.nil?
|
|
|
|
|
2017-04-24 20:47:31 -04:00
|
|
|
uri = Addressable::URI.new
|
2017-05-04 20:23:01 -04:00
|
|
|
uri.host = domain.gsub(/[\/]/, '')
|
2017-07-15 11:24:35 -04:00
|
|
|
uri.normalized_host
|
2017-04-24 20:47:31 -04:00
|
|
|
end
|
|
|
|
|
2017-03-28 08:16:08 -04:00
|
|
|
def same_acct?(canonical, needle)
|
|
|
|
return true if canonical.casecmp(needle).zero?
|
2019-07-08 21:27:35 -04:00
|
|
|
|
2017-03-28 08:16:08 -04:00
|
|
|
username, domain = needle.split('@')
|
2019-07-08 21:27:35 -04:00
|
|
|
|
2017-03-28 08:16:08 -04:00
|
|
|
local_domain?(domain) && canonical.casecmp(username).zero?
|
|
|
|
end
|
|
|
|
|
2017-01-27 10:55:06 -05:00
|
|
|
def local_url?(url)
|
2017-04-24 20:47:31 -04:00
|
|
|
uri = Addressable::URI.parse(url).normalize
|
2020-05-28 06:47:40 -04:00
|
|
|
return false unless uri.host
|
2017-01-27 10:55:06 -05:00
|
|
|
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
|
2019-07-08 21:27:35 -04:00
|
|
|
|
2017-09-13 08:22:16 -04:00
|
|
|
TagManager.instance.web_domain?(domain)
|
2020-05-09 09:50:09 -04:00
|
|
|
rescue Addressable::URI::InvalidURIError
|
|
|
|
false
|
2017-01-27 10:55:06 -05:00
|
|
|
end
|
2016-09-09 14:04:34 -04:00
|
|
|
end
|