@@ -15,4 +15,12 class ProjectEnumerationsController < ApplicationController | |||
|
15 | 15 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | def destroy | |
|
19 | @project.time_entry_activities.each do |time_entry_activity| | |
|
20 | time_entry_activity.destroy(time_entry_activity.parent) | |
|
21 | end | |
|
22 | flash[:notice] = l(:notice_successful_update) | |
|
23 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project | |
|
24 | end | |
|
25 | ||
|
18 | 26 | end |
@@ -238,14 +238,6 class ProjectsController < ApplicationController | |||
|
238 | 238 | @project = nil |
|
239 | 239 | end |
|
240 | 240 | |
|
241 | def reset_activities | |
|
242 | @project.time_entry_activities.each do |time_entry_activity| | |
|
243 | time_entry_activity.destroy(time_entry_activity.parent) | |
|
244 | end | |
|
245 | flash[:notice] = l(:notice_successful_update) | |
|
246 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project | |
|
247 | end | |
|
248 | ||
|
249 | 241 | private |
|
250 | 242 | def find_optional_project |
|
251 | 243 | return true unless params[:id] |
@@ -32,7 +32,7 | |||
|
32 | 32 | </table> |
|
33 | 33 | |
|
34 | 34 | <div class="contextual"> |
|
35 |
<%= link_to(l(:button_reset), {:controller => 'projects', :action => ' |
|
|
35 | <%= link_to(l(:button_reset), {:controller => 'project_enumerations', :action => 'destroy', :id => @project}, | |
|
36 | 36 | :method => :delete, |
|
37 | 37 | :confirm => l(:text_are_you_sure), |
|
38 | 38 | :class => 'icon icon-del') %> |
@@ -209,7 +209,7 ActionController::Routing::Routes.draw do |map| | |||
|
209 | 209 | |
|
210 | 210 | projects.with_options :conditions => {:method => :delete} do |project_actions| |
|
211 | 211 | project_actions.conditions 'projects/:id.:format', :action => 'destroy', :format => /xml/ |
|
212 |
project_actions.conditions 'projects/:id/reset_activities', :action => ' |
|
|
212 | project_actions.conditions 'projects/:id/reset_activities', :controller => 'project_enumerations', :action => 'destroy' | |
|
213 | 213 | end |
|
214 | 214 | end |
|
215 | 215 |
@@ -87,7 +87,7 Redmine::AccessControl.map do |map| | |||
|
87 | 87 | map.permission :view_time_entries, :timelog => [:details, :report] |
|
88 | 88 | map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member |
|
89 | 89 | map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin |
|
90 |
map.permission :manage_project_activities, { |
|
|
90 | map.permission :manage_project_activities, {:project_enumerations => [:save, :destroy]}, :require => :member | |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | map.project_module :news do |map| |
@@ -139,4 +139,51 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
139 | 139 | # TimeEntries shouldn't have been reassigned on the saved record either |
|
140 | 140 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" |
|
141 | 141 | end |
|
142 | ||
|
143 | def test_destroy | |
|
144 | @request.session[:user_id] = 2 # manager | |
|
145 | project_activity = TimeEntryActivity.new({ | |
|
146 | :name => 'Project Specific', | |
|
147 | :parent => TimeEntryActivity.find(:first), | |
|
148 | :project => Project.find(1), | |
|
149 | :active => true | |
|
150 | }) | |
|
151 | assert project_activity.save | |
|
152 | project_activity_two = TimeEntryActivity.new({ | |
|
153 | :name => 'Project Specific Two', | |
|
154 | :parent => TimeEntryActivity.find(:last), | |
|
155 | :project => Project.find(1), | |
|
156 | :active => true | |
|
157 | }) | |
|
158 | assert project_activity_two.save | |
|
159 | ||
|
160 | delete :destroy, :id => 1 | |
|
161 | assert_response :redirect | |
|
162 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
|
163 | ||
|
164 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
|
165 | assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | |
|
166 | end | |
|
167 | ||
|
168 | def test_destroy_should_reassign_time_entries_back_to_the_system_activity | |
|
169 | @request.session[:user_id] = 2 # manager | |
|
170 | project_activity = TimeEntryActivity.new({ | |
|
171 | :name => 'Project Specific Design', | |
|
172 | :parent => TimeEntryActivity.find(9), | |
|
173 | :project => Project.find(1), | |
|
174 | :active => true | |
|
175 | }) | |
|
176 | assert project_activity.save | |
|
177 | assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) | |
|
178 | assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size | |
|
179 | ||
|
180 | delete :destroy, :id => 1 | |
|
181 | assert_response :redirect | |
|
182 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
|
183 | ||
|
184 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
|
185 | assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" | |
|
186 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" | |
|
187 | end | |
|
188 | ||
|
142 | 189 | end |
@@ -381,52 +381,6 class ProjectsControllerTest < ActionController::TestCase | |||
|
381 | 381 | assert_template 'show' |
|
382 | 382 | end |
|
383 | 383 | |
|
384 | def test_reset_activities | |
|
385 | @request.session[:user_id] = 2 # manager | |
|
386 | project_activity = TimeEntryActivity.new({ | |
|
387 | :name => 'Project Specific', | |
|
388 | :parent => TimeEntryActivity.find(:first), | |
|
389 | :project => Project.find(1), | |
|
390 | :active => true | |
|
391 | }) | |
|
392 | assert project_activity.save | |
|
393 | project_activity_two = TimeEntryActivity.new({ | |
|
394 | :name => 'Project Specific Two', | |
|
395 | :parent => TimeEntryActivity.find(:last), | |
|
396 | :project => Project.find(1), | |
|
397 | :active => true | |
|
398 | }) | |
|
399 | assert project_activity_two.save | |
|
400 | ||
|
401 | delete :reset_activities, :id => 1 | |
|
402 | assert_response :redirect | |
|
403 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
|
404 | ||
|
405 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
|
406 | assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | |
|
407 | end | |
|
408 | ||
|
409 | def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity | |
|
410 | @request.session[:user_id] = 2 # manager | |
|
411 | project_activity = TimeEntryActivity.new({ | |
|
412 | :name => 'Project Specific Design', | |
|
413 | :parent => TimeEntryActivity.find(9), | |
|
414 | :project => Project.find(1), | |
|
415 | :active => true | |
|
416 | }) | |
|
417 | assert project_activity.save | |
|
418 | assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) | |
|
419 | assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size | |
|
420 | ||
|
421 | delete :reset_activities, :id => 1 | |
|
422 | assert_response :redirect | |
|
423 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
|
424 | ||
|
425 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
|
426 | assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" | |
|
427 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" | |
|
428 | end | |
|
429 | ||
|
430 | 384 | # A hook that is manually registered later |
|
431 | 385 | class ProjectBasedTemplate < Redmine::Hook::ViewListener |
|
432 | 386 | def view_layouts_base_html_head(context) |
@@ -190,7 +190,7 class RoutingTest < ActionController::IntegrationTest | |||
|
190 | 190 | should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'edit', :id => '1', :format => 'xml' |
|
191 | 191 | |
|
192 | 192 | should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml' |
|
193 |
should_route :delete, "/projects/64/reset_activities", :controller => 'projects', :action => ' |
|
|
193 | should_route :delete, "/projects/64/reset_activities", :controller => 'project_enumerations', :action => 'destroy', :id => '64' | |
|
194 | 194 | end |
|
195 | 195 | |
|
196 | 196 | context "repositories" do |
General Comments 0
You need to be logged in to leave comments.
Login now