mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
parent
469312d7ee
commit
39d7c6ad1d
4 changed files with 24 additions and 3 deletions
|
@ -3,7 +3,7 @@ class Admin::ZonefilesController < ApplicationController
|
||||||
# TODO: Refactor this
|
# TODO: Refactor this
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if ZonefileSetting.pluck(:origin).include?(params[:origin])
|
if ZonefileSetting.origins.include?(params[:origin])
|
||||||
|
|
||||||
@zonefile = ActiveRecord::Base.connection.execute(
|
@zonefile = ActiveRecord::Base.connection.execute(
|
||||||
"select generate_zonefile('#{params[:origin]}')"
|
"select generate_zonefile('#{params[:origin]}')"
|
||||||
|
|
|
@ -32,6 +32,10 @@ class ZonefileSetting < ActiveRecord::Base
|
||||||
STDOUT << "#{Time.zone.now.utc} - Successfully generated zonefile #{filename}\n"
|
STDOUT << "#{Time.zone.now.utc} - Successfully generated zonefile #{filename}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.origins
|
||||||
|
pluck(:origin)
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
origin
|
origin
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,9 +12,9 @@ class DomainNameValidator < ActiveModel::EachValidator
|
||||||
return true unless value
|
return true unless value
|
||||||
value = value.mb_chars.downcase.strip
|
value = value.mb_chars.downcase.strip
|
||||||
|
|
||||||
origins = ZonefileSetting.pluck(:origin)
|
origins = ZonefileSetting.origins
|
||||||
# if someone tries to register an origin domain, let this validation pass
|
# if someone tries to register an origin domain, let this validation pass
|
||||||
# the error will be catched in blocked domains validator
|
# the error will be caught in blocked domains validator
|
||||||
return true if origins.include?(value)
|
return true if origins.include?(value)
|
||||||
|
|
||||||
general_domains = /(#{origins.join('|')})/
|
general_domains = /(#{origins.join('|')})/
|
||||||
|
|
17
spec/models/zonefile_setting_spec.rb
Normal file
17
spec/models/zonefile_setting_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ZonefileSetting, db: false do
|
||||||
|
it 'has versions' do
|
||||||
|
expect(described_class.new.versions).to eq([])
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '::origins' do
|
||||||
|
before :example do
|
||||||
|
expect(described_class).to receive(:pluck).with(:origin).and_return('origins')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns origins' do
|
||||||
|
expect(described_class.origins).to eq('origins')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue