Browse Source

regenerate token, fix toke uniqueness scope

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
0278267301
  1. 13
      app/controllers/as_controller.rb
  2. 19
      app/controllers/hosts_controller.rb
  3. 9
      app/controllers/records_controller.rb
  4. 3
      app/helpers/records_helper.rb
  5. 2
      app/models/record.rb
  6. 16
      app/views/as/_list_record.html.erb
  7. 15
      app/views/as/on_action_update.js.erb
  8. 6
      config/routes.rb

13
app/controllers/as_controller.rb

@ -8,9 +8,22 @@ class AsController < ApplicationController
conf.columns[:change_date].list_ui = :timestamp 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.actions.exclude :show
conf.action_links.add 'new_token', label: 'New Token', method: :put,
type: :member, position: false, confirm: 'Are you sure?'
end end
include RecordsControllerCommon 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 protected
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc

19
app/controllers/hosts_controller.rb

@ -5,17 +5,30 @@ class HostsController < ApplicationController
conf.create.columns = [:name, :host_domain, :content, :ttl] conf.create.columns = [:name, :host_domain, :content, :ttl]
conf.update.columns = [:name, :host_domain, :content, :ttl] conf.update.columns = [:name, :host_domain, :content, :ttl]
conf.list.label = 'Hosts' conf.list.label = 'Hosts'
conf.list.sorting = {:name => :asc} conf.list.sorting = {name: :asc}
conf.create.link.label = "Add Host" conf.create.link.label = "Add Host"
conf.columns[:host_domain].form_ui = :select 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].label = 'Host'
conf.columns[:name].description = 'Ex. "your-name"' conf.columns[:name].description = 'Ex. "your-name"'
conf.columns[:content].label = 'IP' conf.columns[:content].label = 'IP'
conf.columns[:content].description = 'Ex. "10.10.5.12"' conf.columns[:content].description = 'Ex. "10.10.5.12"'
conf.columns[:change_date].list_ui = :timestamp 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.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 end
protected protected

9
app/controllers/records_controller.rb

@ -25,6 +25,8 @@ class RecordsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
# conf.create.link.label = "Add Record" # conf.create.link.label = "Add Record"
conf.actions.exclude :show 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 end
include RecordsControllerCommon include RecordsControllerCommon
skip_before_filter :ensure_nested_under_domain, :only => 'modify' skip_before_filter :ensure_nested_under_domain, :only => 'modify'
@ -45,7 +47,7 @@ class RecordsController < ApplicationController
format.html {render(:text => MODIFY_OK)} format.html {render(:text => MODIFY_OK)}
end end
end end
protected protected
def new_model def new_model
@ -53,4 +55,9 @@ class RecordsController < ApplicationController
before_create_save(record) before_create_save(record)
record record
end end
# just to limit the action to A type records
def a_record?(record)
record.class == A
end
end end

3
app/helpers/records_helper.rb

@ -1,2 +1,5 @@
module RecordsHelper module RecordsHelper
def record_authentication_token_column(record)
record.type == 'A' ? record.authentication_token : '-'
end
end end

2
app/models/record.rb

@ -47,7 +47,7 @@ class Record < ActiveRecord::Base
def generate_token def generate_token
self.authentication_token = loop do self.authentication_token = loop do
token = Devise.friendly_token token = Devise.friendly_token
break token unless self.class.exists?(:authentication_token => token) break token unless Record.exists?(authentication_token: token)
end end
end end

16
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
-%>
<tr class="record <%= tr_class %>" id="<%= element_row_id(:controller_id => :as_records, :action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get)).html_safe %>">
<%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %>
<%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} unless action_links.empty? %>
<%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %>
</tr>

15
app/views/as/on_action_update.js.erb

@ -0,0 +1,15 @@
<%# add :controller_id => :as_records to respond in records list, not a's %>
<%if controller.send :successful?%>
ActiveScaffold.replace_html('<%=active_scaffold_messages_id(:controller_id => :as_records)%>','<%=escape_javascript(render(:partial => 'messages'))%>');
<%if @record%>
ActiveScaffold.update_row('<%=element_row_id(:controller_id => :as_records, :action => :list, :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>');
<%end%>
<% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
ActiveScaffold.replace('<%=active_scaffold_calculations_id(:controller_id => :as_records)%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
<% end %>
<%else%>
<%flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)%>
ActiveScaffold.replace_html('<%=active_scaffold_messages_id(:controller_id => :as_records)%>','<%=escape_javascript(render(:partial => 'messages'))%>');
ActiveScaffold.scroll_to('<%=active_scaffold_messages_id(:controller_id => :as_records)%>');
<%end%>

6
config/routes.rb

@ -11,6 +11,9 @@ Entrydns::Application.routes.draw do
resources :hosts do resources :hosts do
as_routes as_routes
member do
put 'new_token'
end
end end
put '/records/modify/:authentication_token', :to => 'records#modify', :as => :modify_record put '/records/modify/:authentication_token', :to => 'records#modify', :as => :modify_record
@ -32,6 +35,9 @@ Entrydns::Application.routes.draw do
resources :as do resources :as do
as_routes as_routes
member do
put 'new_token'
end
end end
resources :cnames do resources :cnames do

Loading…
Cancel
Save