chef-server-webui 0.8.16 → 0.9.0.a3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/Rakefile +14 -10
  2. data/app/controllers/application.rb +111 -128
  3. data/app/controllers/clients.rb +10 -10
  4. data/app/controllers/cookbook_attributes.rb +1 -1
  5. data/app/controllers/cookbook_definitions.rb +1 -1
  6. data/app/controllers/cookbook_files.rb +1 -1
  7. data/app/controllers/cookbook_libraries.rb +1 -1
  8. data/app/controllers/cookbook_recipes.rb +1 -1
  9. data/app/controllers/cookbook_templates.rb +1 -1
  10. data/app/controllers/cookbooks.rb +21 -3
  11. data/app/controllers/databag_items.rb +6 -6
  12. data/app/controllers/databags.rb +3 -3
  13. data/app/controllers/main.rb +1 -1
  14. data/app/controllers/nodes.rb +21 -21
  15. data/app/controllers/openid_consumer.rb +9 -9
  16. data/app/controllers/roles.rb +3 -3
  17. data/app/controllers/search.rb +1 -1
  18. data/app/controllers/search_entries.rb +1 -1
  19. data/app/controllers/status.rb +1 -1
  20. data/app/controllers/users.rb +7 -7
  21. data/app/helpers/application_helper.rb +1 -156
  22. data/app/helpers/global_helpers.rb +20 -16
  23. data/app/helpers/nodes_helper.rb +24 -22
  24. data/app/helpers/openid_server_helpers.rb +13 -10
  25. data/app/helpers/search_helper.rb +44 -38
  26. data/app/helpers/status_helper.rb +10 -3
  27. data/app/views/clients/_navigation.html.haml +5 -5
  28. data/app/views/clients/edit.html.haml +1 -1
  29. data/app/views/clients/index.html.haml +4 -4
  30. data/app/views/clients/new.html.haml +1 -1
  31. data/app/views/cookbooks/index.html.haml +1 -1
  32. data/app/views/cookbooks/show.html.haml +25 -16
  33. data/app/views/databag_items/_form.html.haml +1 -1
  34. data/app/views/databag_items/_navigation.html.haml +5 -5
  35. data/app/views/databag_items/edit.html.haml +1 -1
  36. data/app/views/databag_items/new.html.haml +1 -1
  37. data/app/views/databags/_item_navigation.html.haml +4 -4
  38. data/app/views/databags/_navigation.html.haml +5 -5
  39. data/app/views/databags/edit.html.haml +1 -1
  40. data/app/views/databags/index.html.haml +3 -3
  41. data/app/views/databags/new.html.haml +1 -1
  42. data/app/views/databags/show.html.haml +3 -3
  43. data/app/views/layout/{chef_server_webui.html.haml → application.html.haml} +11 -11
  44. data/app/views/layout/login.html.haml +1 -1
  45. data/app/views/nodes/_form.html.haml +1 -1
  46. data/app/views/nodes/_navigation.html.haml +5 -5
  47. data/app/views/nodes/edit.html.haml +1 -1
  48. data/app/views/nodes/index.html.haml +6 -6
  49. data/app/views/nodes/new.html.haml +1 -1
  50. data/app/views/nodes/show.html.haml +4 -5
  51. data/app/views/openid_consumer/index.html.haml +2 -2
  52. data/app/views/openid_register/index.html.haml +4 -4
  53. data/app/views/openid_register/show.html.haml +1 -1
  54. data/app/views/roles/_form.html.haml +1 -1
  55. data/app/views/roles/_navigation.html.haml +5 -5
  56. data/app/views/roles/edit.html.haml +1 -1
  57. data/app/views/roles/index.html.haml +4 -4
  58. data/app/views/roles/new.html.haml +1 -1
  59. data/app/views/roles/show.html.haml +3 -4
  60. data/app/views/search/_search_form.html.haml +1 -1
  61. data/app/views/search/index.html.haml +1 -1
  62. data/app/views/search/show.html.haml +1 -1
  63. data/app/views/status/index.html.haml +9 -12
  64. data/app/views/users/_form.html.haml +1 -1
  65. data/app/views/users/_navigation.html.haml +5 -5
  66. data/app/views/users/edit.html.haml +1 -1
  67. data/app/views/users/index.html.haml +3 -3
  68. data/app/views/users/login.html.haml +1 -1
  69. data/app/views/users/new.html.haml +1 -1
  70. data/bin/chef-server-webui +72 -0
  71. data/config.ru +10 -74
  72. data/config/init.rb +30 -11
  73. data/config/rack.rb +5 -0
  74. data/config/router.rb +62 -5
  75. data/lib/chef-server-webui.rb +2 -155
  76. data/lib/chef-server-webui/version.rb +3 -0
  77. data/public/javascripts/drop_down_menu.js +22 -0
  78. metadata +60 -48
  79. data/stubs/app/controllers/application.rb +0 -2
  80. data/stubs/app/controllers/main.rb +0 -2
@@ -19,7 +19,7 @@
19
19
 
20
20
  require 'chef' / 'mixin' / 'checksum'
21
21
 
22
- class ChefServerWebui::CookbookDefinitions < ChefServerWebui::Application
22
+ class CookbookDefinitions < Application
23
23
 
24
24
  provides :html
25
25
 
@@ -21,7 +21,7 @@ require 'chef' / 'mixin' / 'checksum'
21
21
  require 'chef' / 'cookbook_loader'
22
22
  require 'chef' / 'mixin' / 'find_preferred_file'
23
23
 
24
- class ChefServerWebui::CookbookFiles < ChefServerWebui::Application
24
+ class CookbookFiles < Application
25
25
 
26
26
  provides :html
27
27
  before :login_required
@@ -20,7 +20,7 @@
20
20
  require 'chef' / 'mixin' / 'checksum'
21
21
  require 'chef' / 'cookbook_loader'
22
22
 
23
- class ChefServerWebui::CookbookLibraries < ChefServerWebui::Application
23
+ class CookbookLibraries < Application
24
24
 
25
25
  provides :html
26
26
  before :login_required
@@ -19,7 +19,7 @@
19
19
 
20
20
  require 'chef' / 'mixin' / 'checksum'
21
21
 
22
- class ChefServerWebui::CookbookRecipes < ChefServerWebui::Application
22
+ class CookbookRecipes < Application
23
23
 
24
24
  provides :html
25
25
  before :login_required
@@ -21,7 +21,7 @@ require 'chef' / 'mixin' / 'checksum'
21
21
  require 'chef' / 'cookbook_loader'
22
22
  require 'chef' / 'mixin' / 'find_preferred_file'
23
23
 
24
- class ChefServerWebui::CookbookTemplates < ChefServerWebui::Application
24
+ class CookbookTemplates < Application
25
25
 
26
26
  provides :html
27
27
  before :login_required
@@ -20,10 +20,16 @@
20
20
 
21
21
  require 'chef' / 'cookbook_loader'
22
22
 
23
- class ChefServerWebui::Cookbooks < ChefServerWebui::Application
23
+ class Cookbooks < Application
24
24
 
25
25
  provides :html, :json
26
- before :login_required
26
+ before :login_required
27
+ before :params_helper
28
+
29
+ attr_reader :cookbook_id
30
+ def params_helper
31
+ @cookbook_id = params[:id] || params[:cookbook_id]
32
+ end
27
33
 
28
34
  def index
29
35
  @cl = begin
@@ -38,7 +44,19 @@ class ChefServerWebui::Cookbooks < ChefServerWebui::Application
38
44
 
39
45
  def show
40
46
  begin
41
- @cookbook = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("cookbooks/#{params[:id]}")
47
+ # array of versions, sorted from large to small e.g. ["0.20.0", "0.1.0"]
48
+ versions = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("cookbooks/#{cookbook_id}")[cookbook_id].sort!{|x,y| y <=> x }
49
+ # if version is not specified in the url, get the most recent version, otherwise get the specified version
50
+ version = if params[:cb_version].nil? || params[:cb_version].empty?
51
+ versions.first
52
+ else
53
+ params[:cb_version]
54
+ end
55
+
56
+ @cookbook = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("cookbooks/#{cookbook_id}/#{version}")
57
+
58
+ # by default always show the largest version number (assuming largest means most recent)
59
+ @other_versions = versions - [version]
42
60
  raise NotFound unless @cookbook
43
61
  display @cookbook
44
62
  rescue => e
@@ -18,7 +18,7 @@
18
18
 
19
19
  require 'chef' / 'data_bag_item'
20
20
 
21
- class ChefServerWebui::DatabagItems < ChefServerWebui::Application
21
+ class DatabagItems < Application
22
22
 
23
23
  provides :html, :json
24
24
  before :login_required
@@ -41,7 +41,7 @@ class ChefServerWebui::DatabagItems < ChefServerWebui::Application
41
41
  @databag_item.raw_data = JSON.parse(params[:json_data])
42
42
  raise ArgumentError, "Updating id is not allowed" unless @databag_item.raw_data['id'] == params[:id] #to be consistent with other objects, changing id is not allowed.
43
43
  @databag_item.save
44
- redirect(slice_url(:databag_databag_items, :databag_id => params[:databag_id], :id => @databag_item.name), :message => { :notice => "Updated Databag Item #{@databag_item.name}" })
44
+ redirect(url(:databag_databag_items, :databag_id => params[:databag_id], :id => @databag_item.name), :message => { :notice => "Updated Databag Item #{@databag_item.name}" })
45
45
  rescue => e
46
46
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
47
47
  @_message = { :error => "Could not update the databag item" }
@@ -63,7 +63,7 @@ class ChefServerWebui::DatabagItems < ChefServerWebui::Application
63
63
  @databag_item.data_bag @databag_name
64
64
  @databag_item.raw_data = JSON.parse(params[:json_data])
65
65
  @databag_item.create
66
- redirect(slice_url(:databag_databag_items, :databag_id => @databag_name), :message => { :notice => "Databag item created successfully" })
66
+ redirect(url(:databag_databag_items, :databag_id => @databag_name), :message => { :notice => "Databag item created successfully" })
67
67
  rescue => e
68
68
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
69
69
  @_message = { :error => "Could not create databag item" }
@@ -84,7 +84,7 @@ class ChefServerWebui::DatabagItems < ChefServerWebui::Application
84
84
  display @databag_item
85
85
  rescue => e
86
86
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
87
- redirect(slice_url(:databag_databag_items), {:message => { :error => "Could not show the databag item" }, :permanent => true})
87
+ redirect(url(:databag_databag_items), {:message => { :error => "Could not show the databag item" }, :permanent => true})
88
88
  end
89
89
  end
90
90
 
@@ -92,10 +92,10 @@ class ChefServerWebui::DatabagItems < ChefServerWebui::Application
92
92
  begin
93
93
  @databag_item = Chef::DataBagItem.new
94
94
  @databag_item.destroy(databag_id, item_id)
95
- redirect(slice_url(:databag_databag_items), {:message => { :notice => "Databag item deleted successfully" }, :permanent => true})
95
+ redirect(url(:databag_databag_items), {:message => { :notice => "Databag item deleted successfully" }, :permanent => true})
96
96
  rescue => e
97
97
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
98
- redirect(slice_url(:databag_databag_items), {:message => { :error => "Could not delete databag item" }, :permanent => true})
98
+ redirect(url(:databag_databag_items), {:message => { :error => "Could not delete databag item" }, :permanent => true})
99
99
  end
100
100
  end
101
101
 
@@ -18,7 +18,7 @@
18
18
 
19
19
  require 'chef' / 'data_bag'
20
20
 
21
- class ChefServerWebui::Databags < ChefServerWebui::Application
21
+ class Databags < Application
22
22
 
23
23
  provides :html, :json
24
24
  before :login_required
@@ -33,7 +33,7 @@ class ChefServerWebui::Databags < ChefServerWebui::Application
33
33
  @databag = Chef::DataBag.new
34
34
  @databag.name params[:name]
35
35
  @databag.create
36
- redirect(slice_url(:databags), :message => { :notice => "Created Databag #{@databag.name}" })
36
+ redirect(url(:databags), :message => { :notice => "Created Databag #{@databag.name}" })
37
37
  rescue => e
38
38
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
39
39
  @_message = { :error => "Could not create databag" }
@@ -71,7 +71,7 @@ class ChefServerWebui::Databags < ChefServerWebui::Application
71
71
  begin
72
72
  r = Chef::REST.new(Chef::Config[:chef_server_url])
73
73
  r.delete_rest("data/#{params[:id]}")
74
- redirect(absolute_slice_url(:databags), {:message => { :notice => "Data bag #{params[:id]} deleted successfully" }, :permanent => true})
74
+ redirect(absolute_url(:databags), {:message => { :notice => "Data bag #{params[:id]} deleted successfully" }, :permanent => true})
75
75
  rescue => e
76
76
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
77
77
  @databags = Chef::DataBag.list
@@ -1,4 +1,4 @@
1
- class ChefServerWebui::Main < ChefServerWebui::Application
1
+ class Main < Application
2
2
 
3
3
  def index
4
4
  render
@@ -20,32 +20,32 @@
20
20
 
21
21
  require 'chef' / 'node'
22
22
 
23
- class ChefServerWebui::Nodes < ChefServerWebui::Application
23
+ class Nodes < Application
24
24
 
25
25
  provides :html
26
26
 
27
27
  before :login_required
28
- before :authorized_node, :only => [ :update, :destroy ]
29
28
 
30
29
  def index
31
- @node_list = begin
32
- Chef::Node.list
33
- rescue => e
34
- Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
35
- @_message = {:error => "Could not list nodes"}
36
- {}
37
- end
30
+ begin
31
+ node_hash = Chef::Node.list
32
+ @node_list = node_hash.keys.sort_by {|a,b| node_hash[a] <=> node_hash[b]}
33
+ rescue => e
34
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
35
+ @_message = {:error => "Could not list nodes"}
36
+ @node_hash = {}
37
+ end
38
38
  render
39
39
  end
40
40
 
41
41
  def show
42
- @node = begin
43
- Chef::Node.load(params[:id])
44
- rescue => e
45
- Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
46
- @_message = {:error => "Could not load node #{params[:id]}"}
47
- Chef::Node.new
48
- end
42
+ begin
43
+ @node =Chef::Node.load(params[:id])
44
+ rescue => e
45
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
46
+ @_message = {:error => "Could not load node #{params[:id]}"}
47
+ @node = Chef::Node.new
48
+ end
49
49
  render
50
50
  end
51
51
 
@@ -86,14 +86,14 @@ class ChefServerWebui::Nodes < ChefServerWebui::Application
86
86
  begin
87
87
  @node = Chef::Node.new
88
88
  @node.name params[:name]
89
- @node.attribute = JSON.parse(params[:attributes])
89
+ @node.normal_attrs = JSON.parse(params[:attributes])
90
90
  @node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
91
91
  raise ArgumentError, "Node name cannot be blank" if (params[:name].nil? || params[:name].length==0)
92
92
  @node.create
93
- redirect(slice_url(:nodes), :message => { :notice => "Created Node #{@node.name}" })
93
+ redirect(url(:nodes), :message => { :notice => "Created Node #{@node.name}" })
94
94
  rescue => e
95
95
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
96
- @node.attribute = JSON.parse(params[:attributes])
96
+ @node.normal_attrs = JSON.parse(params[:attributes])
97
97
  @available_recipes = get_available_recipes
98
98
  @available_roles = Chef::Role.list.keys.sort
99
99
  @node.run_list params[:for_node]
@@ -107,7 +107,7 @@ class ChefServerWebui::Nodes < ChefServerWebui::Application
107
107
  begin
108
108
  @node = Chef::Node.load(params[:id])
109
109
  @node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
110
- @node.attribute = JSON.parse(params[:attributes])
110
+ @node.normal_attrs = JSON.parse(params[:attributes])
111
111
  @node.save
112
112
  @_message = { :notice => "Updated Node" }
113
113
  render :show
@@ -126,7 +126,7 @@ class ChefServerWebui::Nodes < ChefServerWebui::Application
126
126
  begin
127
127
  @node = Chef::Node.load(params[:id])
128
128
  @node.destroy
129
- redirect(absolute_slice_url(:nodes), {:message => { :notice => "Node #{params[:id]} deleted successfully" }, :permanent => true})
129
+ redirect(absolute_url(:nodes), {:message => { :notice => "Node #{params[:id]} deleted successfully" }, :permanent => true})
130
130
  rescue => e
131
131
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
132
132
  @node_list = Chef::Node.list()
@@ -22,7 +22,7 @@ require 'pathname'
22
22
  require 'openid'
23
23
  require (Chef::Config[:openid_cstore_couchdb] ? 'openid-store-couchdb' : 'openid/store/filesystem')
24
24
 
25
- class ChefServerWebui::OpenidConsumer < ChefServerWebui::Application
25
+ class OpenidConsumer < Application
26
26
 
27
27
  provides :html
28
28
 
@@ -42,8 +42,8 @@ class ChefServerWebui::OpenidConsumer < ChefServerWebui::Application
42
42
  raise BadRequest, "Discovery failed for #{oid}: #{e}"
43
43
  end
44
44
 
45
- return_to = absolute_slice_url(:openid_consumer_complete)
46
- realm = absolute_slice_url(:openid_consumer)
45
+ return_to = absolute_url(:openid_consumer_complete)
46
+ realm = absolute_url(:openid_consumer)
47
47
 
48
48
  if oidreq.send_redirect?(realm, return_to, params[:immediate])
49
49
  return redirect(oidreq.redirect_url(realm, return_to, params[:immediate]))
@@ -55,7 +55,7 @@ class ChefServerWebui::OpenidConsumer < ChefServerWebui::Application
55
55
 
56
56
  def login
57
57
  if session[:user]
58
- redirect(slice_url(:nodes), :message => { :warning => "You've already logged in with user #{session[:user]}" })
58
+ redirect(url(:nodes), :message => { :warning => "You've already logged in with user #{session[:user]}" })
59
59
  else
60
60
  oid = params[:openid_identifier]
61
61
  raise(Unauthorized, "Sorry, #{oid} is not an authorized OpenID.") unless is_authorized_openid_identifier?(oid, Chef::Config[:authorized_openid_identifiers])
@@ -66,7 +66,7 @@ class ChefServerWebui::OpenidConsumer < ChefServerWebui::Application
66
66
 
67
67
  def complete
68
68
  # FIXME - url_for some action is not necessarily the current URL.
69
- current_url = absolute_slice_url(:openid_consumer_complete)
69
+ current_url = absolute_url(:openid_consumer_complete)
70
70
  parameters = params.reject{|k,v| k == "controller" || k == "action"}
71
71
  oidresp = consumer.complete(parameters, current_url)
72
72
  case oidresp.status
@@ -95,11 +95,11 @@ class ChefServerWebui::OpenidConsumer < ChefServerWebui::Application
95
95
  end
96
96
  end
97
97
  if session[:user].nil?
98
- redirect(slice_url(:openid_consumer), :message => { :error => "No user is associated with this OpenID." })
98
+ redirect(url(:openid_consumer), :message => { :error => "No user is associated with this OpenID." })
99
99
  return "No user is associated with this OpenID."
100
100
  end
101
101
  #end
102
- redirect_back_or_default(absolute_slice_url(:nodes))
102
+ redirect_back_or_default(absolute_url(:nodes))
103
103
  return "Verification of #{oidresp.display_identifier} succeeded."
104
104
  when OpenID::Consumer::SETUP_NEEDED
105
105
  return "Immediate request failed - Setup Needed"
@@ -107,12 +107,12 @@ class ChefServerWebui::OpenidConsumer < ChefServerWebui::Application
107
107
  return "OpenID transaction cancelled."
108
108
  else
109
109
  end
110
- redirect absolute_slice_url(:openid_consumer)
110
+ redirect absolute_url(:openid_consumer)
111
111
  end
112
112
 
113
113
  def logout
114
114
  cleanup_session
115
- redirect slice_url(:top)
115
+ redirect url(:top)
116
116
  end
117
117
 
118
118
  private
@@ -19,7 +19,7 @@
19
19
 
20
20
  require 'chef/role'
21
21
 
22
- class ChefServerWebui::Roles < ChefServerWebui::Application
22
+ class Roles < Application
23
23
 
24
24
  provides :html
25
25
  before :login_required
@@ -92,7 +92,7 @@ class ChefServerWebui::Roles < ChefServerWebui::Application
92
92
  @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != ''
93
93
  @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != ''
94
94
  @role.create
95
- redirect(slice_url(:roles), :message => { :notice => "Created Role #{@role.name}" })
95
+ redirect(url(:roles), :message => { :notice => "Created Role #{@role.name}" })
96
96
  rescue => e
97
97
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
98
98
  @available_recipes = get_available_recipes
@@ -134,7 +134,7 @@ class ChefServerWebui::Roles < ChefServerWebui::Application
134
134
  begin
135
135
  @role = Chef::Role.load(params[:id])
136
136
  @role.destroy
137
- redirect(absolute_slice_url(:roles), :message => { :notice => "Role #{@role.name} deleted successfully." }, :permanent => true)
137
+ redirect(absolute_url(:roles), :message => { :notice => "Role #{@role.name} deleted successfully." }, :permanent => true)
138
138
  rescue => e
139
139
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
140
140
  @role_list = Chef::Role.list()
@@ -18,7 +18,7 @@
18
18
 
19
19
  require 'chef' / 'search' / 'query'
20
20
 
21
- class ChefServerWebui::Search < ChefServerWebui::Application
21
+ class Search < Application
22
22
 
23
23
  provides :html
24
24
  before :login_required
@@ -20,7 +20,7 @@
20
20
  #require 'chef' / 'search'
21
21
  #require 'chef' / 'queue'
22
22
 
23
- class ChefServerWebui::SearchEntries < ChefServerWebui::Application
23
+ class SearchEntries < Application
24
24
 
25
25
  provides :html
26
26
  before :login_required
@@ -19,7 +19,7 @@
19
19
 
20
20
  require 'chef' / 'node'
21
21
 
22
- class ChefServerWebui::Status < ChefServerWebui::Application
22
+ class Status < Application
23
23
 
24
24
  provides :html
25
25
  before :login_required
@@ -20,7 +20,7 @@ require 'chef'/'webui_user'
20
20
  require 'uri'
21
21
  require 'merb-param-protection'
22
22
 
23
- class ChefServerWebui::Users < ChefServerWebui::Application
23
+ class Users < Application
24
24
 
25
25
  provides :html
26
26
  before :login_required, :exclude => [:login, :login_exec, :complete]
@@ -114,7 +114,7 @@ class ChefServerWebui::Users < ChefServerWebui::Application
114
114
  @user.admin = true if params[:admin]
115
115
  (params[:openid].length == 0 || params[:openid].nil?) ? @user.set_openid(nil) : @user.set_openid(URI.parse(params[:openid]).normalize.to_s)
116
116
  @user.create
117
- redirect(slice_url(:users), :message => { :notice => "Created User #{params[:name]}" })
117
+ redirect(url(:users), :message => { :notice => "Created User #{params[:name]}" })
118
118
  rescue => e
119
119
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
120
120
  @_message = { :error => "Could not create user" }
@@ -124,7 +124,7 @@ class ChefServerWebui::Users < ChefServerWebui::Application
124
124
 
125
125
  def login
126
126
  @user = Chef::WebUIUser.new
127
- session[:user] ? redirect(slice_url(:nodes), :message => { :warning => "You've already logged in with user #{session[:user]}" }) : (render :layout => 'login')
127
+ session[:user] ? redirect(url(:nodes), :message => { :warning => "You've already logged in with user #{session[:user]}" }) : (render :layout => 'login')
128
128
  end
129
129
 
130
130
  def login_exec
@@ -143,12 +143,12 @@ class ChefServerWebui::Users < ChefServerWebui::Application
143
143
  def complete
144
144
  session[:user] = params[:name]
145
145
  session[:level] = (@user.admin == true ? :admin : :user)
146
- (@user.name == Chef::Config[:web_ui_admin_user_name] && @user.verify_password(Chef::Config[:web_ui_admin_default_password])) ? redirect(slice_url(:users_edit, :user_id => @user.name), :message => { :warning => "Please change the default password" }) : redirect_back_or_default(absolute_slice_url(:nodes))
146
+ (@user.name == Chef::Config[:web_ui_admin_user_name] && @user.verify_password(Chef::Config[:web_ui_admin_default_password])) ? redirect(url(:users_edit, :user_id => @user.name), :message => { :warning => "Please change the default password" }) : redirect_back_or_default(absolute_url(:nodes))
147
147
  end
148
148
 
149
149
  def logout
150
150
  cleanup_session
151
- redirect slice_url(:top)
151
+ redirect url(:top)
152
152
  end
153
153
 
154
154
  def destroy
@@ -158,7 +158,7 @@ class ChefServerWebui::Users < ChefServerWebui::Application
158
158
  @user = Chef::WebUIUser.load(params[:user_id])
159
159
  @user.destroy
160
160
  logout if params[:user_id] == session[:user]
161
- redirect(absolute_slice_url(:users), {:message => { :notice => "User #{params[:user_id]} deleted successfully" }, :permanent => true})
161
+ redirect(absolute_url(:users), {:message => { :notice => "User #{params[:user_id]} deleted successfully" }, :permanent => true})
162
162
  rescue => e
163
163
  Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
164
164
  session[:level] != :admin ? set_user_and_redirect : redirect_to_list_users({ :error => $! })
@@ -173,7 +173,7 @@ class ChefServerWebui::Users < ChefServerWebui::Application
173
173
  rescue
174
174
  logout_and_redirect_to_login
175
175
  else
176
- redirect(slice_url(:users_show, :user_id => session[:user]), {:message => { :error => $! }, :permanent => true})
176
+ redirect(url(:users_show, :user_id => session[:user]), {:message => { :error => $! }, :permanent => true})
177
177
  end
178
178
  end
179
179
 
@@ -1,161 +1,6 @@
1
1
  require 'chef/mixin/deep_merge'
2
2
 
3
3
  module Merb
4
- module ChefServerWebui
5
- module ApplicationHelper
6
-
7
- # @param *segments<Array[#to_s]> Path segments to append.
8
- #
9
- # @return <String>
10
- # A path relative to the public directory, with added segments.
11
- def image_path(*segments)
12
- public_path_for(:image, *segments)
13
- end
14
-
15
- # @param *segments<Array[#to_s]> Path segments to append.
16
- #
17
- # @return <String>
18
- # A path relative to the public directory, with added segments.
19
- def javascript_path(*segments)
20
- public_path_for(:javascript, *segments)
21
- end
22
-
23
- # @param *segments<Array[#to_s]> Path segments to append.
24
- #
25
- # @return <String>
26
- # A path relative to the public directory, with added segments.
27
- def stylesheet_path(*segments)
28
- public_path_for(:stylesheet, *segments)
29
- end
30
-
31
- # Construct a path relative to the public directory
32
- #
33
- # @param <Symbol> The type of component.
34
- # @param *segments<Array[#to_s]> Path segments to append.
35
- #
36
- # @return <String>
37
- # A path relative to the public directory, with added segments.
38
- def public_path_for(type, *segments)
39
- ::ChefServerWebui.public_path_for(type, *segments)
40
- end
41
-
42
- # Construct an app-level path.
43
- #
44
- # @param <Symbol> The type of component.
45
- # @param *segments<Array[#to_s]> Path segments to append.
46
- #
47
- # @return <String>
48
- # A path within the host application, with added segments.
49
- def app_path_for(type, *segments)
50
- ::ChefServerWebui.app_path_for(type, *segments)
51
- end
52
-
53
- # Construct a slice-level path.
54
- #
55
- # @param <Symbol> The type of component.
56
- # @param *segments<Array[#to_s]> Path segments to append.
57
- #
58
- # @return <String>
59
- # A path within the slice source (Gem), with added segments.
60
- def slice_path_for(type, *segments)
61
- ::ChefServerWebui.slice_path_for(type, *segments)
62
- end
63
-
64
- def build_tree(name, node, default={}, override={})
65
- node = Chef::Mixin::DeepMerge.merge(default, node)
66
- node = Chef::Mixin::DeepMerge.merge(node, override)
67
- html = "<table id='#{name}' class='tree table'>"
68
- html << "<tr><th class='first'>Attribute</th><th class='last'>Value</th></tr>"
69
- count = 0
70
- parent = 0
71
- append_tree(name, html, node, count, parent, override)
72
- html << "</table>"
73
- html
74
- end
75
-
76
- def append_tree(name, html, node, count, parent, override)
77
- node.sort{ |a,b| a[0] <=> b[0] }.each do |key, value|
78
- to_send = Array.new
79
- count += 1
80
- is_parent = false
81
- local_html = ""
82
- local_html << "<tr id='#{name}-#{count}' class='collapsed #{name}"
83
- if parent != 0
84
- local_html << " child-of-#{name}-#{parent}' style='display: none;'>"
85
- else
86
- local_html << "'>"
87
- end
88
- local_html << "<td class='table-key'><span toggle='#{name}-#{count}'/>#{key}</td>"
89
- case value
90
- when Hash
91
- is_parent = true
92
- local_html << "<td></td>"
93
- p = count
94
- to_send << Proc.new { append_tree(name, html, value, count, p, override) }
95
- when Array
96
- is_parent = true
97
- local_html << "<td></td>"
98
- as_hash = {}
99
- value.each_index { |i| as_hash[i] = value[i] }
100
- p = count
101
- to_send << Proc.new { append_tree(name, html, as_hash, count, p, override) }
102
- else
103
- local_html << "<td><div class='json-attr'>#{value}</div></td>"
104
- end
105
- local_html << "</tr>"
106
- local_html.sub!(/class='collapsed/, 'class=\'collapsed parent') if is_parent
107
- local_html.sub!(/<span/, "<span class='expander'") if is_parent
108
- html << local_html
109
- to_send.each { |s| count = s.call }
110
- count += to_send.length
111
- end
112
- count
113
- end
114
-
115
- def syntax_highlight(uri)
116
- code = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest(uri)
117
- CodeRay.encode_tokens(CodeRay.scan(code, :ruby), :span)
118
- end
119
-
120
- def str_to_bool(str)
121
- str =~ /true/ ? true : false
122
- end
123
-
124
- #for showing search result
125
- def determine_name(type, object)
126
- case type
127
- when :node, :role, :client
128
- object.name
129
- else
130
- params[:id]
131
- end
132
- end
133
-
134
- # Recursively build a tree of lists.
135
- #def build_tree(node)
136
- # list = "<dl>"
137
- # list << "\n<!-- Beginning of Tree -->"
138
- # walk = lambda do |key,value|
139
- # case value
140
- # when Hash, Array
141
- # list << "\n<!-- Beginning of Enumerable obj -->"
142
- # list << "\n<dt>#{key}</dt>"
143
- # list << "<dd>"
144
- # list << "\t<dl>\n"
145
- # value.each(&walk)
146
- # list << "\t</dl>\n"
147
- # list << "</dd>"
148
- # list << "\n<!-- End of Enumerable obj -->"
149
- #
150
- # else
151
- # list << "\n<dt>#{key}</dt>"
152
- # list << "<dd>#{value}</dd>"
153
- # end
154
- # end
155
- # node.sort{ |a,b| a[0] <=> b[0] }.each(&walk)
156
- # list << "</dl>"
157
- #end
158
-
159
- end
4
+ module ApplicationHelper
160
5
  end
161
6
  end