From 1f278a0221fa088718e46a14afd4173d087a5dbc Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 20 Sep 2010 03:58:20 +0000 Subject: [PATCH] Merged r4054 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.0-stable@4124 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../project_enumerations_controller.rb | 8 ++++ app/controllers/projects_controller.rb | 8 ---- app/views/projects/settings/_activities.rhtml | 2 +- config/routes.rb | 2 +- lib/redmine.rb | 2 +- .../project_enumerations_controller_test.rb | 47 +++++++++++++++++++ test/functional/projects_controller_test.rb | 46 ------------------ test/integration/routing_test.rb | 2 +- 8 files changed, 59 insertions(+), 58 deletions(-) diff --git a/app/controllers/project_enumerations_controller.rb b/app/controllers/project_enumerations_controller.rb index c4b48e476..d63e23641 100644 --- a/app/controllers/project_enumerations_controller.rb +++ b/app/controllers/project_enumerations_controller.rb @@ -15,4 +15,12 @@ class ProjectEnumerationsController < ApplicationController redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project end + def destroy + @project.time_entry_activities.each do |time_entry_activity| + time_entry_activity.destroy(time_entry_activity.parent) + end + flash[:notice] = l(:notice_successful_update) + redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project + end + end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0670cb1ec..90eddd7b2 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -238,14 +238,6 @@ class ProjectsController < ApplicationController @project = nil end - def reset_activities - @project.time_entry_activities.each do |time_entry_activity| - time_entry_activity.destroy(time_entry_activity.parent) - end - flash[:notice] = l(:notice_successful_update) - redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project - end - private def find_optional_project return true unless params[:id] diff --git a/app/views/projects/settings/_activities.rhtml b/app/views/projects/settings/_activities.rhtml index e39bf9b91..5909ac64c 100644 --- a/app/views/projects/settings/_activities.rhtml +++ b/app/views/projects/settings/_activities.rhtml @@ -32,7 +32,7 @@
-<%= link_to(l(:button_reset), {:controller => 'projects', :action => 'reset_activities', :id => @project}, +<%= link_to(l(:button_reset), {:controller => 'project_enumerations', :action => 'destroy', :id => @project}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> diff --git a/config/routes.rb b/config/routes.rb index 4df212167..9974e21f0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -227,7 +227,7 @@ ActionController::Routing::Routes.draw do |map| projects.with_options :conditions => {:method => :delete} do |project_actions| project_actions.conditions 'projects/:id.:format', :action => 'destroy', :format => /xml/ - project_actions.conditions 'projects/:id/reset_activities', :action => 'reset_activities' + project_actions.conditions 'projects/:id/reset_activities', :controller => 'project_enumerations', :action => 'destroy' end end diff --git a/lib/redmine.rb b/lib/redmine.rb index a30ea5405..7f631ad5d 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -87,7 +87,7 @@ Redmine::AccessControl.map do |map| map.permission :view_time_entries, :timelog => [:details, :report] map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin - map.permission :manage_project_activities, {:projects => [:reset_activities], :project_enumerations => [:save]}, :require => :member + map.permission :manage_project_activities, {:project_enumerations => [:save, :destroy]}, :require => :member end map.project_module :news do |map| diff --git a/test/functional/project_enumerations_controller_test.rb b/test/functional/project_enumerations_controller_test.rb index 23da42378..c03be04fb 100644 --- a/test/functional/project_enumerations_controller_test.rb +++ b/test/functional/project_enumerations_controller_test.rb @@ -139,4 +139,51 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase # TimeEntries shouldn't have been reassigned on the saved record either assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" end + + def test_destroy + @request.session[:user_id] = 2 # manager + project_activity = TimeEntryActivity.new({ + :name => 'Project Specific', + :parent => TimeEntryActivity.find(:first), + :project => Project.find(1), + :active => true + }) + assert project_activity.save + project_activity_two = TimeEntryActivity.new({ + :name => 'Project Specific Two', + :parent => TimeEntryActivity.find(:last), + :project => Project.find(1), + :active => true + }) + assert project_activity_two.save + + delete :destroy, :id => 1 + assert_response :redirect + assert_redirected_to 'projects/ecookbook/settings/activities' + + assert_nil TimeEntryActivity.find_by_id(project_activity.id) + assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) + end + + def test_destroy_should_reassign_time_entries_back_to_the_system_activity + @request.session[:user_id] = 2 # manager + project_activity = TimeEntryActivity.new({ + :name => 'Project Specific Design', + :parent => TimeEntryActivity.find(9), + :project => Project.find(1), + :active => true + }) + assert project_activity.save + assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) + assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size + + delete :destroy, :id => 1 + assert_response :redirect + assert_redirected_to 'projects/ecookbook/settings/activities' + + assert_nil TimeEntryActivity.find_by_id(project_activity.id) + assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" + assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" + end + end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 152d0837b..4decb060f 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -381,52 +381,6 @@ class ProjectsControllerTest < ActionController::TestCase assert_template 'show' end - def test_reset_activities - @request.session[:user_id] = 2 # manager - project_activity = TimeEntryActivity.new({ - :name => 'Project Specific', - :parent => TimeEntryActivity.find(:first), - :project => Project.find(1), - :active => true - }) - assert project_activity.save - project_activity_two = TimeEntryActivity.new({ - :name => 'Project Specific Two', - :parent => TimeEntryActivity.find(:last), - :project => Project.find(1), - :active => true - }) - assert project_activity_two.save - - delete :reset_activities, :id => 1 - assert_response :redirect - assert_redirected_to 'projects/ecookbook/settings/activities' - - assert_nil TimeEntryActivity.find_by_id(project_activity.id) - assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) - end - - def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity - @request.session[:user_id] = 2 # manager - project_activity = TimeEntryActivity.new({ - :name => 'Project Specific Design', - :parent => TimeEntryActivity.find(9), - :project => Project.find(1), - :active => true - }) - assert project_activity.save - assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) - assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size - - delete :reset_activities, :id => 1 - assert_response :redirect - assert_redirected_to 'projects/ecookbook/settings/activities' - - assert_nil TimeEntryActivity.find_by_id(project_activity.id) - assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" - assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" - end - # A hook that is manually registered later class ProjectBasedTemplate < Redmine::Hook::ViewListener def view_layouts_base_html_head(context) diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 0f67da68c..b8c99ca7f 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -190,7 +190,7 @@ class RoutingTest < ActionController::IntegrationTest should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'edit', :id => '1', :format => 'xml' should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml' - should_route :delete, "/projects/64/reset_activities", :controller => 'projects', :action => 'reset_activities', :id => '64' + should_route :delete, "/projects/64/reset_activities", :controller => 'project_enumerations', :action => 'destroy', :id => '64' end context "repositories" do -- 2.39.5