Skip to content

Commit 3e5576e

Browse files
committed
Basic prototype of concerto#909 - button placement on settings page needs CSS help...badly
1 parent c2aaa28 commit 3e5576e

File tree

9 files changed

+226
-2
lines changed

9 files changed

+226
-2
lines changed
Loading
+65
Loading

app/controllers/concerto_config_controller.rb

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ def initiate_restart
1010
restart_webserver()
1111
redirect_to :action => :show
1212
end
13+
14+
def config_check
15+
@imagemagick_installed = command?("convert")
16+
@rmagick_installed = Gem::Specification::find_all_by_name('rmagick').any?
17+
@not_using_sqlite = ActiveRecord::Base.configurations[Rails.env]['adapter'] != "sqlite3"
18+
@not_world_writable = !(File.stat(Rails.root).world_writable?)
19+
#Using Ruby methods to stat a directory and convert the mod bit to the familiar 3-digit octal
20+
#The logic here and in the view assumes a *nix system - no idea what other posix systems will return
21+
@rails_root_perms = File.stat(Rails.root).mode.to_s(8)[-3,3] == "700" #should be 700 on a shared box
22+
@rails_log_perms = File.stat(Rails.root.join('log')).mode.to_s(8)[-3,3] == "600" #should be 600 on a shared box
23+
@webserver_ownership = File.stat(Rails.root).owned?
24+
end
1325

1426
# get a hash of concerto_config keys and values and update them using the ConcertoConfig setter
1527
# PUT /settings

app/helpers/concerto_config_helper.rb

+42
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,46 @@ def generate_tabs configs
2525
headers << '</ul>'
2626
headers.join.html_safe
2727
end
28+
29+
def test_symbol(test_boolean)
30+
image_tag("elements/#{test_boolean ? "green" : "red"}_button.svg", :width => 15, :height => 15)
31+
end
32+
33+
def imagemagick_text
34+
"ImageMagick is #{@imagemagick_installed ? "installed" : "not installed"} at #{which("convert")}"
35+
end
36+
37+
def rmagick_text
38+
"RMagick is #{@rmagick_installed ? "installed" : "not installed"}"
39+
end
40+
41+
def world_writable_text
42+
@not_world_writable ? "The Concerto directory is not world writable" : "The Concerto directory is world writable"
43+
end
44+
45+
def root_perms_text
46+
"#{Rails.root} has permission #{File.stat(Rails.root).mode.to_s(8)[-3,3]}" + "#{@rails_root_perms == 700 ? "" : " instead of 700"}"
47+
end
48+
49+
def rails_log_text
50+
"#{Rails.root.join('log')} has permission #{File.stat(Rails.root.join('log')).mode.to_s(8)[-3,3]}" + "#{@rails_log_perms == 600 ? "" : " instead of 600"}"
51+
end
52+
53+
def webserver_ownership_text
54+
Rails.root.to_s + (@webserver_ownership ? " is owned by the webserver" : " is not owned by the webserver")
55+
end
56+
57+
def db_text
58+
adapter = ActiveRecord::Base.configurations[Rails.env]['adapter']
59+
if @not_using_sqlite == false && (system_has_mysql? && system_has_postgres?)
60+
"#{adapter} is your current database adapter. It's not recommended for production deployments and both MySQL (#{mysql_location}) and Postgresql (#{postgres_location}) are available on your system."
61+
elsif @not_using_sqlite == false && system_has_mysql?
62+
"#{adapter} is your current database adapter. It's not recommended for production deployments and MySQL is installed at #{mysql_location}"
63+
elsif @not_using_sqlite == false && system_has_postgres?
64+
"#{adapter} is your current database adapter. It's not recommended for production deployments and Postgresql is installed at #{postgres_location}"
65+
else
66+
"#{adapter} is properly installed"
67+
end
68+
end
69+
2870
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<section class="viewblock">
2+
<header class="viewblock-header">
3+
<h1 class="default-padding">
4+
<%= t('.configuration_check') %>
5+
</h1>
6+
<div class="viewblock-header_right">
7+
8+
</div>
9+
10+
</header>
11+
<div class="viewblock-cont">
12+
13+
<div class="subnav clearfix">
14+
<p><%= test_symbol(@imagemagick_installed) %><%=imagemagick_text%></p>
15+
<p><%= test_symbol(@rmagick_installed) %><%= rmagick_text %></p>
16+
<p><%= test_symbol(@not_using_sqlite) %><%= db_text %></p>
17+
<p><%= test_symbol(@not_world_writable) %><%= world_writable_text %></p>
18+
<p><%= test_symbol(@rails_root_perms) %><%= root_perms_text %></p>
19+
<p><%= test_symbol(@rails_log_perms) %><%= rails_log_text %></p>
20+
<p><%= test_symbol(@webserver_ownership) %><%= webserver_ownership_text %></p>
21+
</div>
22+
23+
</div>
24+
</section>

app/views/concerto_config/show.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<section class="viewblock">
44
<header class="viewblock-header">
55
<h1 class="default-padding">
6-
<%= t('.edit_settings') %>
6+
<%= t('.edit_settings') %><%= button_to t('.check_configuration'), {:action => :config_check}, {:method => :get } %>
77
</h1>
88
<div class="viewblock-header_right">
99
<div class="button-padding">

config/locales/views/concerto_config/en.yml

+3
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ en:
3636
edit_settings: "Edit Global Settings"
3737
restart_confirm: "Restarting the webserver may take a 10 to 20 seconds. Are you sure you'd like to restart?"
3838
restart_webserver: "Restart Webserver"
39+
check_configuration: "Check Configuration"
3940
save_settings: "Save Settings"
41+
config_check:
42+
configuration_check: "Configuration Check"

config/routes.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ def matches?(request)
111111
resources :html_texts, :controller => :contents, :except => [:index, :show], :path => "content"
112112
resources :client_times, :controller => :contents, :except => [:index, :show], :path => "content"
113113

114-
resource :concerto_config, :controller => :concerto_config, :only => [:show, :update], :path => "settings" do
114+
resource :concerto_config, :controller => :concerto_config, :only => [:show, :update,], :path => "settings" do
115115
post :initiate_restart
116+
get :config_check
116117
end
117118

118119
# This is the catch-all path we use for people who type /content when they

lib/command_check.rb

+8
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ def system_has_mysql?
2929
def system_has_postgres?
3030
Gem::Specification::find_all_by_name('pg').any? || command?('pg_config')
3131
end
32+
33+
def mysql_location
34+
which('mysql_config').split('/bin').first
35+
end
36+
37+
def postgres_location
38+
which('pg_config').split('/bin').first
39+
end

0 commit comments

Comments
 (0)