You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
12 years ago
|
class Users::HostsController < UsersController
|
||
13 years ago
|
active_scaffold :a do |conf|
|
||
|
conf.columns = [:name, :host_domain, :content, :ttl, :change_date, :authentication_token]
|
||
|
conf.list.columns = [:name, :content, :ttl, :change_date, :authentication_token]
|
||
13 years ago
|
conf.create.columns = [:name, :host_domain, :content, :ttl]
|
||
13 years ago
|
conf.update.columns = [:name, :host_domain, :content, :ttl]
|
||
|
conf.list.label = 'Hosts'
|
||
13 years ago
|
conf.list.sorting = {name: :asc}
|
||
13 years ago
|
conf.create.link.label = "Add Host"
|
||
|
conf.columns[:host_domain].form_ui = :select
|
||
13 years ago
|
conf.columns[:host_domain].options = {options: Settings.host_domains}
|
||
13 years ago
|
conf.columns[:name].label = 'Host'
|
||
13 years ago
|
conf.columns[:name].description = 'Ex. "your-name"'
|
||
13 years ago
|
conf.columns[:content].label = 'IP'
|
||
|
conf.columns[:content].description = 'Ex. "10.10.5.12"'
|
||
|
conf.columns[:change_date].list_ui = :timestamp
|
||
13 years ago
|
conf.columns[:ttl].options = {i18n_number: {delimiter: ''}}
|
||
13 years ago
|
conf.actions.exclude :show
|
||
13 years ago
|
conf.action_links.add 'new_token', label: 'New Token', method: :put,
|
||
|
type: :member, position: false, confirm: 'Are you sure?'
|
||
|
end
|
||
|
|
||
|
def new_token
|
||
|
process_action_link_action do |record|
|
||
|
record.instance_variable_set(:@readonly, false)
|
||
|
record.generate_token
|
||
|
update_save(no_record_param_update: true)
|
||
|
if successful?
|
||
|
flash[:info] = "Token was updated successfully to #{record.authentication_token}"
|
||
|
end
|
||
|
end
|
||
13 years ago
|
end
|
||
|
|
||
|
protected
|
||
|
|
||
|
def new_model
|
||
|
record = super
|
||
|
record.content = client_remote_ip
|
||
|
before_create_save(record)
|
||
|
record
|
||
|
end
|
||
|
|
||
13 years ago
|
def beginning_of_chain
|
||
12 years ago
|
super.includes(:domain).where(:domains => {:name => Settings.host_domains}).readonly(false)
|
||
13 years ago
|
end
|
||
|
|
||
13 years ago
|
def before_create_save(record)
|
||
|
record.user = current_user
|
||
|
end
|
||
|
|
||
|
end
|