NOTE: this patch is a rebase of the previous patch since #125 was pushed.
The admin user can click on the Admin link and select the Server
Settings page. From there they can set the server name name. Changes are
stored in the database.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/server_settings_controller.rb | 40 +++++++++++++++++
app/helpers/server_settings_helper.rb | 2 +
app/views/projects/_details.html.erb | 5 ++
app/views/server_settings/edit.html.erb | 25 +++++++++++
app/views/server_settings/show.html.erb | 25 +++++++++++
config/routes.rb | 3 +
doc/ChangeLog | 3 +-
test/fixtures/config_properties.yml | 6 +-
test/fixtures/user_privileges.yml | 1 +
test/functional/server_settings_controller_test.rb | 46 ++++++++++++++++++++
10 files changed, 152 insertions(+), 4 deletions(-)
create mode 100644 app/controllers/server_settings_controller.rb
create mode 100644 app/helpers/server_settings_helper.rb
create mode 100644 app/views/server_settings/edit.html.erb
create mode 100644 app/views/server_settings/show.html.erb
create mode 100644 test/functional/server_settings_controller_test.rb
diff --git a/app/controllers/server_settings_controller.rb
b/app/controllers/server_settings_controller.rb
new file mode 100644
index 0000000..8544483
--- /dev/null
+++ b/app/controllers/server_settings_controller.rb
@@ -0,0 +1,40 @@
+# server_settings_controller.rb
+# Copyright (C) 2009, Darryl L. Pierce <mcpierce(a)gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <
http://www.gnu.org/licenses/>.
+#
+
+# +ServerSettingsController+ allows the admin to modify server settings.
+class ServerSettingsController < AdminController
+ # GET /admin/server
+ def show
+ @title = "Server Properties"
+ end
+
+ # GET /admin/server/edit
+ def edit
+ @title = "Edit Server Properties"
+ @system_name = ConfigProperty.fetch("system.name")
+ end
+
+ # PUT /admin/server
+ def update
+ @system_name = params[:system_name]
+ ConfigProperty.transaction do
+ ConfigProperty.store("system.name", @system_name)
+
+ redirect_to admin_server_path
+ end
+ end
+end
diff --git a/app/helpers/server_settings_helper.rb
b/app/helpers/server_settings_helper.rb
new file mode 100644
index 0000000..fd4a69b
--- /dev/null
+++ b/app/helpers/server_settings_helper.rb
@@ -0,0 +1,2 @@
+module ServerSettingsHelper
+end
diff --git a/app/views/projects/_details.html.erb b/app/views/projects/_details.html.erb
index a54b89b..4cba562 100644
--- a/app/views/projects/_details.html.erb
+++ b/app/views/projects/_details.html.erb
@@ -1,4 +1,9 @@
<table class="detail">
+ <colgroup>
+ <col class="label" />
+ <col class="value" />
+ </colgroup>
+
<thead>
<tr>
<th class="title" colspan="2"><%= "Details For
#{(a)project.name}" %></th>
diff --git a/app/views/server_settings/edit.html.erb
b/app/views/server_settings/edit.html.erb
new file mode 100644
index 0000000..1e61c24
--- /dev/null
+++ b/app/views/server_settings/edit.html.erb
@@ -0,0 +1,25 @@
+<%= form_tag admin_server_path, :method => :put %>
+
+<fieldset id="server_settings">
+ <legend>Edit Server Settings</legend>
+
+ <table class="edit">
+ <colgroup>
+ <col class="label" />
+ <col class="value" />
+ </colgroup>
+
+ <tbody>
+ <tr>
+ <td class="label">System Name</td>
+ <td class="value"><%= text_field_tag :system_name, @system_name
%></td>
+ </tr>
+
+ <tr>
+ <td class="buttons" colspan="2">
+ <%= submit_tag "Save" %>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</fieldset>
diff --git a/app/views/server_settings/show.html.erb
b/app/views/server_settings/show.html.erb
new file mode 100644
index 0000000..f0c8869
--- /dev/null
+++ b/app/views/server_settings/show.html.erb
@@ -0,0 +1,25 @@
+<table class="detail">
+ <colgroup>
+ <col class="label" />
+ <col class="value" />
+ </colgroup>
+
+ <thead>
+ <tr>
+ <th class="title" colspan="2" >Server
Settings</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <tr>
+ <td class="label">System name:</td>
+ <td class="value"><%=
ConfigProperty.fetch("system.name", "Undefined") %></td>
+ </tr>
+
+ <tr>
+ <td colspan="2" class="buttons">
+ <%= link_to("Edit", edit_admin_server_path) %>
+ </td>
+ </tr>
+ </tbody>
+</table>
diff --git a/config/routes.rb b/config/routes.rb
index 54c1971..db4de9c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -17,6 +17,9 @@
ActionController::Routing::Routes.draw do |map|
map.admin "/admin", :controller => 'admin', :action =>
'index'
+ map.resource :admin do |admin|
+ admin.resource :server, :controller => 'ServerSettings'
+ end
map.resources :projects
map.resources :products do |product|
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 777c394..bf0f244 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,2 +1,3 @@
Change Log (0.2.0):
- * Added a system title to all pages.#125 - Darryl L. Pierce <mcpierce(a)gmail.com>
+ * #125 Added a system title to all pages. - Darryl L. Pierce <mcpierce(a)gmail.com>
+ * #136 System title can be changed by the admin. - Darryl L. Pierce
<mcpierce(a)gmail.com>
diff --git a/test/fixtures/config_properties.yml b/test/fixtures/config_properties.yml
index 05d87bf..4e070f1 100644
--- a/test/fixtures/config_properties.yml
+++ b/test/fixtures/config_properties.yml
@@ -1,3 +1,3 @@
-email_server_name:
- name: email.server.name
- value:
smtp.google.com
+server_name:
+ name: server.name
+ value: Killer ProjXP Installation
diff --git a/test/fixtures/user_privileges.yml b/test/fixtures/user_privileges.yml
index 38ffbf7..ba57357 100644
--- a/test/fixtures/user_privileges.yml
+++ b/test/fixtures/user_privileges.yml
@@ -4,6 +4,7 @@ admin_privileges:
user_id: <%= Fixtures.identify(:admin) %>
admin_projects: true
admin_users: true
+ admin_site: true
projxp_owner_privileges:
user_id: <%= Fixtures.identify(:projxp_owner) %>
diff --git a/test/functional/server_settings_controller_test.rb
b/test/functional/server_settings_controller_test.rb
new file mode 100644
index 0000000..75def2d
--- /dev/null
+++ b/test/functional/server_settings_controller_test.rb
@@ -0,0 +1,46 @@
+# server_settings_controller.rb
+# Copyright (C) 2009, Darryl L. Pierce <mcpierce(a)gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <
http://www.gnu.org/licenses/>.
+#
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ServerSettingsControllerTest < ActionController::TestCase
+ fixtures :user_privileges
+ fixtures :users
+
+ def setup
+ @admin = users(:admin)
+ raise "Admin user must have admin privileges" unless
@admin.privileges.admin_site
+
+ @server_name = config_properties(:server_name).value
+ end
+
+ # Ensures the right values are loaded when editing the server settings.
+ def test_edit
+ get :edit, {}, {:user_id => @admin.id}
+
+ assert_response :success
+ assert_equal assigns['server_name'], @server_name, "Failed to load the
server name."
+ end
+
+ # Ensures that saving values works as expected.
+ def test_update
+ put :update, {:server_name => "new server name"}, {:user_id =>
@admin.id}
+
+ assert_redirected_to admin_server_path
+ assert_equal ConfigProperty.fetch("server.name"), "new server
name", "Failed to store the server name"
+ end
+end
--
1.6.0.6