mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 00:17:17 +08:00
FEATURE: Can edit category/host relationships for embedding
This commit is contained in:
24
app/models/embeddable_host.rb
Normal file
24
app/models/embeddable_host.rb
Normal file
@ -0,0 +1,24 @@
|
||||
class EmbeddableHost < ActiveRecord::Base
|
||||
validates_format_of :host, :with => /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\Z/i
|
||||
belongs_to :category
|
||||
|
||||
before_validation do
|
||||
self.host.sub!(/^https?:\/\//, '')
|
||||
self.host.sub!(/\/.*$/, '')
|
||||
end
|
||||
|
||||
def self.record_for_host(host)
|
||||
uri = URI(host) rescue nil
|
||||
return false unless uri.present?
|
||||
|
||||
host = uri.host
|
||||
return false unless host.present?
|
||||
|
||||
where("lower(host) = ?", host).first
|
||||
end
|
||||
|
||||
def self.host_allowed?(host)
|
||||
record_for_host(host).present?
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user