summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/boards_controller.rb23
-rw-r--r--app/views/boards/_form.html.erb6
-rw-r--r--app/views/boards/edit.html.erb2
-rw-r--r--app/views/boards/new.html.erb2
-rw-r--r--app/views/boards/show.html.erb2
-rw-r--r--app/views/messages/show.html.erb4
-rw-r--r--app/views/projects/settings/_boards.html.erb12
-rw-r--r--config/routes.rb16
-rw-r--r--lib/redmine.rb2
-rw-r--r--test/functional/boards_controller_test.rb69
-rw-r--r--test/integration/routing_test.rb6
11 files changed, 87 insertions, 57 deletions
diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb
index 36b0e233c..f9a507e6b 100644
--- a/app/controllers/boards_controller.rb
+++ b/app/controllers/boards_controller.rb
@@ -62,23 +62,34 @@ class BoardsController < ApplicationController
end
end
- verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
-
def new
- @board = Board.new(params[:board])
- @board.project = @project
- if request.post? && @board.save
+ @board = @project.boards.build(params[:board])
+ end
+
+ verify :method => :post, :only => :create, :redirect_to => { :action => :index }
+ def create
+ @board = @project.boards.build(params[:board])
+ if @board.save
flash[:notice] = l(:notice_successful_create)
redirect_to_settings_in_projects
+ else
+ render :action => 'new'
end
end
def edit
- if request.post? && @board.update_attributes(params[:board])
+ end
+
+ verify :method => :put, :only => :update, :redirect_to => { :action => :index }
+ def update
+ if @board.update_attributes(params[:board])
redirect_to_settings_in_projects
+ else
+ render :action => 'edit'
end
end
+ verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
def destroy
@board.destroy
redirect_to_settings_in_projects
diff --git a/app/views/boards/_form.html.erb b/app/views/boards/_form.html.erb
index 7ede589ab..d80c84717 100644
--- a/app/views/boards/_form.html.erb
+++ b/app/views/boards/_form.html.erb
@@ -1,8 +1,6 @@
-<%= error_messages_for 'board' %>
+<%= f.error_messages %>
-<!--[form:board]-->
-<div class="box">
+<div class="box tabular">
<p><%= f.text_field :name, :required => true %></p>
<p><%= f.text_field :description, :required => true, :size => 80 %></p>
</div>
-<!--[eoform:board]-->
diff --git a/app/views/boards/edit.html.erb b/app/views/boards/edit.html.erb
index ba4c8b5ac..9e94c25cd 100644
--- a/app/views/boards/edit.html.erb
+++ b/app/views/boards/edit.html.erb
@@ -1,6 +1,6 @@
<h2><%= l(:label_board) %></h2>
-<% labelled_tabular_form_for :board, @board, :url => {:action => 'edit', :id => @board} do |f| %>
+<% labelled_form_for @board, :url => project_board_path(@project, @board) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_save) %>
<% end %>
diff --git a/app/views/boards/new.html.erb b/app/views/boards/new.html.erb
index b89121880..68eb1a33c 100644
--- a/app/views/boards/new.html.erb
+++ b/app/views/boards/new.html.erb
@@ -1,6 +1,6 @@
<h2><%= l(:label_board_new) %></h2>
-<% labelled_tabular_form_for :board, @board, :url => {:action => 'new'} do |f| %>
+<% labelled_form_for @board, :url => project_boards_path(@project) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_create) %>
<% end %>
diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb
index 34ccba9d6..6441c5ce3 100644
--- a/app/views/boards/show.html.erb
+++ b/app/views/boards/show.html.erb
@@ -1,4 +1,4 @@
-<%= breadcrumb link_to(l(:label_board_plural), {:controller => 'boards', :action => 'index', :project_id => @project}) %>
+<%= breadcrumb link_to(l(:label_board_plural), project_boards_path(@project)) %>
<div class="contextual">
<%= link_to_if_authorized l(:label_message_new),
diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb
index c78856f73..272772737 100644
--- a/app/views/messages/show.html.erb
+++ b/app/views/messages/show.html.erb
@@ -1,5 +1,5 @@
-<%= breadcrumb link_to(l(:label_board_plural), {:controller => 'boards', :action => 'index', :project_id => @project}),
- link_to(h(@board.name), {:controller => 'boards', :action => 'show', :project_id => @project, :id => @board}) %>
+<%= breadcrumb link_to(l(:label_board_plural), project_boards_path(@project)),
+ link_to(h(@board.name), project_board_path(@project, @board)) %>
<div class="contextual">
<%= watcher_tag(@topic, User.current) %>
diff --git a/app/views/projects/settings/_boards.html.erb b/app/views/projects/settings/_boards.html.erb
index fc5fe96c0..66a838a4e 100644
--- a/app/views/projects/settings/_boards.html.erb
+++ b/app/views/projects/settings/_boards.html.erb
@@ -14,12 +14,14 @@
<td><%=h board.description %></td>
<td align="center">
<% if authorize_for("boards", "edit") %>
- <%= reorder_links('board', {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}) %>
+ <%= reorder_links('board', {:controller => 'boards', :action => 'update', :project_id => @project, :id => board}, :put) %>
<% end %>
</td>
<td class="buttons">
- <%= link_to_if_authorized l(:button_edit), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}, :class => 'icon icon-edit' %>
- <%= link_to_if_authorized l(:button_delete), {:controller => 'boards', :action => 'destroy', :project_id => @project, :id => board}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
+ <% if User.current.allowed_to?(:manage_boards, @project) %>
+ <%= link_to l(:button_edit), edit_project_board_path(@project, board), :class => 'icon icon-edit' %>
+ <%= link_to l(:button_delete), project_board_path(@project, board), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
+ <% end %>
</td>
</tr>
<% end %>
@@ -29,4 +31,6 @@
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
-<p><%= link_to_if_authorized l(:label_board_new), {:controller => 'boards', :action => 'new', :project_id => @project}, :class => 'icon icon-add' %></p>
+<% if User.current.allowed_to?(:manage_boards, @project) %>
+<p><%= link_to l(:label_board_new), new_project_board_path(@project), :class => 'icon icon-add' %></p>
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 59c66b9ab..3364682b7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -49,20 +49,6 @@ ActionController::Routing::Routes.draw do |map|
end
end
- map.with_options :controller => 'boards' do |board_routes|
- board_routes.with_options :conditions => {:method => :get} do |board_views|
- board_views.connect 'projects/:project_id/boards', :action => 'index'
- board_views.connect 'projects/:project_id/boards/new', :action => 'new'
- board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
- board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show'
- board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
- end
- board_routes.with_options :conditions => {:method => :post} do |board_actions|
- board_actions.connect 'projects/:project_id/boards', :action => 'new'
- board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
- end
- end
-
map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
map.resources :queries, :except => [:show]
@@ -141,6 +127,7 @@ ActionController::Routing::Routes.draw do |map|
project.resources :queries, :only => [:new, :create]
project.resources :issue_categories, :shallow => true
project.resources :documents, :shallow => true, :member => {:add_attachment => :post}
+ project.resources :boards
project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
@@ -212,7 +199,6 @@ ActionController::Routing::Routes.draw do |map|
map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post}
#left old routes at the bottom for backwards compat
- map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
map.connect 'projects/:project_id/news/:action', :controller => 'news'
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 6028599d2..ca748b611 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -131,7 +131,7 @@ Redmine::AccessControl.map do |map|
end
map.project_module :boards do |map|
- map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
+ map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member
map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
map.permission :add_messages, {:messages => [:new, :reply, :quote]}
map.permission :edit_messages, {:messages => :edit}, :require => :member
diff --git a/test/functional/boards_controller_test.rb b/test/functional/boards_controller_test.rb
index bc5ebec89..3d1983cd4 100644
--- a/test/functional/boards_controller_test.rb
+++ b/test/functional/boards_controller_test.rb
@@ -16,18 +16,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../test_helper', __FILE__)
-require 'boards_controller'
-
-# Re-raise errors caught by the controller.
-class BoardsController; def rescue_action(e) raise e end; end
class BoardsControllerTest < ActionController::TestCase
fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
def setup
- @controller = BoardsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
User.current = nil
end
@@ -53,14 +46,6 @@ class BoardsControllerTest < ActionController::TestCase
assert_not_nil assigns(:topics)
end
- def test_post_new
- @request.session[:user_id] = 2
- assert_difference 'Board.count' do
- post :new, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
- end
- assert_redirected_to '/projects/ecookbook/settings/boards'
- end
-
def test_show
get :show, :project_id => 1, :id => 1
assert_response :success
@@ -79,19 +64,65 @@ class BoardsControllerTest < ActionController::TestCase
assert_not_nil assigns(:messages)
end
- def test_post_edit
+ def test_show_not_found
+ get :index, :project_id => 1, :id => 97
+ assert_response 404
+ end
+
+ def test_new
+ @request.session[:user_id] = 2
+ get :new, :project_id => 1
+ assert_response :success
+ assert_template 'new'
+ end
+
+ def test_create
+ @request.session[:user_id] = 2
+ assert_difference 'Board.count' do
+ post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
+ end
+ assert_redirected_to '/projects/ecookbook/settings/boards'
+ board = Board.first(:order => 'id DESC')
+ assert_equal 'Testing', board.name
+ assert_equal 'Testing board creation', board.description
+ end
+
+ def test_create_with_failure
@request.session[:user_id] = 2
assert_no_difference 'Board.count' do
- post :edit, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
+ post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
+ end
+ assert_response :success
+ assert_template 'new'
+ end
+
+ def test_edit
+ @request.session[:user_id] = 2
+ get :edit, :project_id => 1, :id => 2
+ assert_response :success
+ assert_template 'edit'
+ end
+
+ def test_update
+ @request.session[:user_id] = 2
+ assert_no_difference 'Board.count' do
+ put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
end
assert_redirected_to '/projects/ecookbook/settings/boards'
assert_equal 'Testing', Board.find(2).name
end
- def test_post_destroy
+ def test_update_with_failure
+ @request.session[:user_id] = 2
+ put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
+ assert_response :success
+ assert_template 'edit'
+ end
+
+ def test_destroy
@request.session[:user_id] = 2
assert_difference 'Board.count', -1 do
- post :destroy, :project_id => 1, :id => 2
+ delete :destroy, :project_id => 1, :id => 2
end
assert_redirected_to '/projects/ecookbook/settings/boards'
assert_nil Board.find_by_id(2)
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index e554b0a4b..42dd55849 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -39,9 +39,9 @@ class RoutingTest < ActionController::IntegrationTest
should_route :get, "/projects/world_domination/boards/44.atom", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44', :format => 'atom'
should_route :get, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
- should_route :post, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
- should_route :post, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
- should_route :post, "/projects/world_domination/boards/44/destroy", :controller => 'boards', :action => 'destroy', :project_id => 'world_domination', :id => '44'
+ should_route :post, "/projects/world_domination/boards", :controller => 'boards', :action => 'create', :project_id => 'world_domination'
+ should_route :put, "/projects/world_domination/boards/44", :controller => 'boards', :action => 'update', :project_id => 'world_domination', :id => '44'
+ should_route :delete, "/projects/world_domination/boards/44", :controller => 'boards', :action => 'destroy', :project_id => 'world_domination', :id => '44'
end