diff --git a/app/controllers/as_controller.rb b/app/controllers/as_controller.rb index 66be7cb..b0c6a86 100644 --- a/app/controllers/as_controller.rb +++ b/app/controllers/as_controller.rb @@ -8,9 +8,22 @@ class AsController < ApplicationController conf.columns[:change_date].list_ui = :timestamp conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.actions.exclude :show + conf.action_links.add 'new_token', label: 'New Token', method: :put, + type: :member, position: false, confirm: 'Are you sure?' end include RecordsControllerCommon + 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 + end + protected # override to use :mx_records instead of :records assoc diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb index 1ac1292..019cea2 100644 --- a/app/controllers/hosts_controller.rb +++ b/app/controllers/hosts_controller.rb @@ -5,17 +5,30 @@ class HostsController < ApplicationController conf.create.columns = [:name, :host_domain, :content, :ttl] conf.update.columns = [:name, :host_domain, :content, :ttl] conf.list.label = 'Hosts' - conf.list.sorting = {:name => :asc} + conf.list.sorting = {name: :asc} conf.create.link.label = "Add Host" conf.columns[:host_domain].form_ui = :select - conf.columns[:host_domain].options = {:options => Settings.host_domains} + conf.columns[:host_domain].options = {options: Settings.host_domains} conf.columns[:name].label = 'Host' conf.columns[:name].description = 'Ex. "your-name"' conf.columns[:content].label = 'IP' conf.columns[:content].description = 'Ex. "10.10.5.12"' conf.columns[:change_date].list_ui = :timestamp - conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} + conf.columns[:ttl].options = {i18n_number: {delimiter: ''}} conf.actions.exclude :show + 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 end protected diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index b70d00d..6fa314e 100644 --- a/app/controllers/records_controller.rb +++ b/app/controllers/records_controller.rb @@ -25,6 +25,8 @@ class RecordsController < ApplicationController conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} # conf.create.link.label = "Add Record" conf.actions.exclude :show + conf.action_links.add 'new_token', label: 'New Token', method: :put, + security_method: :a_record?, type: :member, position: false, confirm: 'Are you sure?' end include RecordsControllerCommon skip_before_filter :ensure_nested_under_domain, :only => 'modify' @@ -45,7 +47,7 @@ class RecordsController < ApplicationController format.html {render(:text => MODIFY_OK)} end end - + protected def new_model @@ -53,4 +55,9 @@ class RecordsController < ApplicationController before_create_save(record) record end + + # just to limit the action to A type records + def a_record?(record) + record.class == A + end end \ No newline at end of file diff --git a/app/helpers/records_helper.rb b/app/helpers/records_helper.rb index 4493314..1d09970 100644 --- a/app/helpers/records_helper.rb +++ b/app/helpers/records_helper.rb @@ -1,2 +1,5 @@ module RecordsHelper + def record_authentication_token_column(record) + record.type == 'A' ? record.authentication_token : '-' + end end \ No newline at end of file diff --git a/app/models/record.rb b/app/models/record.rb index cfd3ea7..3f61135 100644 --- a/app/models/record.rb +++ b/app/models/record.rb @@ -47,7 +47,7 @@ class Record < ActiveRecord::Base def generate_token self.authentication_token = loop do token = Devise.friendly_token - break token unless self.class.exists?(:authentication_token => token) + break token unless Record.exists?(authentication_token: token) end end diff --git a/app/views/as/_list_record.html.erb b/app/views/as/_list_record.html.erb new file mode 100644 index 0000000..af97ccf --- /dev/null +++ b/app/views/as/_list_record.html.erb @@ -0,0 +1,16 @@ +<%# add :controller_id => :as_records to respond in records list, not a's %> + +<% +record = list_record if list_record # compat with render :partial :collection +columns ||= list_columns +tr_class = cycle("", "even-record") +tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class +url_options = params_for(:action => :list, :id => record.id) +action_links ||= active_scaffold_config.action_links.member +-%> + +