##// END OF EJS Templates
Resourcified issue categories (#9553)....
Jean-Philippe Lang -
r7761:6f4fb8b8920c
parent child
Show More
@@ -18,47 +18,55
18 class IssueCategoriesController < ApplicationController
18 class IssueCategoriesController < ApplicationController
19 menu_item :settings
19 menu_item :settings
20 model_object IssueCategory
20 model_object IssueCategory
21 before_filter :find_model_object, :except => :new
21 before_filter :find_model_object, :except => [:new, :create]
22 before_filter :find_project_from_association, :except => :new
22 before_filter :find_project_from_association, :except => [:new, :create]
23 before_filter :find_project, :only => :new
23 before_filter :find_project, :only => [:new, :create]
24 before_filter :authorize
24 before_filter :authorize
25
25
26 verify :method => :post, :only => :destroy
27
28 def new
26 def new
29 @category = @project.issue_categories.build(params[:category])
27 @category = @project.issue_categories.build(params[:category])
30 if request.post?
28 end
31 if @category.save
29
32 respond_to do |format|
30 verify :method => :post, :only => :create
33 format.html do
31 def create
34 flash[:notice] = l(:notice_successful_create)
32 @category = @project.issue_categories.build(params[:category])
35 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
33 if @category.save
36 end
34 respond_to do |format|
37 format.js do
35 format.html do
38 # IE doesn't support the replace_html rjs method for select box options
36 flash[:notice] = l(:notice_successful_create)
39 render(:update) {|page| page.replace "issue_category_id",
37 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
40 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
41 }
42 end
43 end
38 end
44 else
39 format.js do
45 respond_to do |format|
40 # IE doesn't support the replace_html rjs method for select box options
46 format.html
41 render(:update) {|page| page.replace "issue_category_id",
47 format.js do
42 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
48 render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
43 }
49 end
44 end
45 end
46 else
47 respond_to do |format|
48 format.html { render :action => 'new'}
49 format.js do
50 render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
50 end
51 end
51 end
52 end
52 end
53 end
53 end
54 end
54
55
55 def edit
56 def edit
56 if request.post? and @category.update_attributes(params[:category])
57 end
58
59 verify :method => :put, :only => :update
60 def update
61 if @category.update_attributes(params[:category])
57 flash[:notice] = l(:notice_successful_update)
62 flash[:notice] = l(:notice_successful_update)
58 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
63 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
64 else
65 render :action => 'edit'
59 end
66 end
60 end
67 end
61
68
69 verify :method => :delete, :only => :destroy
62 def destroy
70 def destroy
63 @issue_count = @category.issues.size
71 @issue_count = @category.issues.size
64 if @issue_count == 0
72 if @issue_count == 0
@@ -1,6 +1,6
1 <h2><%=l(:label_issue_category)%>: <%=h @category.name %></h2>
1 <h2><%=l(:label_issue_category)%>: <%=h @category.name %></h2>
2
2
3 <% form_tag({}) do %>
3 <% form_tag(issue_category_path(@category), :method => :delete) do %>
4 <div class="box">
4 <div class="box">
5 <p><strong><%= l(:text_issue_category_destroy_question, @issue_count) %></strong></p>
5 <p><strong><%= l(:text_issue_category_destroy_question, @issue_count) %></strong></p>
6 <p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %></label><br />
6 <p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %></label><br />
@@ -1,6 +1,6
1 <h2><%=l(:label_issue_category)%></h2>
1 <h2><%=l(:label_issue_category)%></h2>
2
2
3 <% labelled_tabular_form_for :category, @category, :url => { :action => 'edit', :id => @category } do |f| %>
3 <% labelled_tabular_form_for :category, @category, :url => issue_category_path(@category), :html => {:method => :put} do |f| %>
4 <%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
4 <%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
5 <%= submit_tag l(:button_save) %>
5 <%= submit_tag l(:button_save) %>
6 <% end %>
6 <% end %>
@@ -1,6 +1,6
1 <h2><%=l(:label_issue_category_new)%></h2>
1 <h2><%=l(:label_issue_category_new)%></h2>
2
2
3 <% labelled_tabular_form_for :category, @category, :url => { :action => 'new' } do |f| %>
3 <% labelled_tabular_form_for :category, @category, :url => project_issue_categories_path(@project) do |f| %>
4 <%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
4 <%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
5 <%= submit_tag l(:button_create) %>
5 <%= submit_tag l(:button_create) %>
6 <% end %>
6 <% end %>
@@ -14,7 +14,7
14 <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
14 <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
15 l(:label_issue_category_new),
15 l(:label_issue_category_new),
16 'category[name]',
16 'category[name]',
17 {:controller => 'issue_categories', :action => 'new', :project_id => @project},
17 {:controller => 'issue_categories', :action => 'create', :project_id => @project},
18 :title => l(:label_issue_category_new),
18 :title => l(:label_issue_category_new),
19 :tabindex => 199) if authorize_for('issue_categories', 'new') %></p>
19 :tabindex => 199) if authorize_for('issue_categories', 'new') %></p>
20 <% end %>
20 <% end %>
@@ -12,8 +12,10
12 <td><%=h(category.name) %></td>
12 <td><%=h(category.name) %></td>
13 <td><%=h(category.assigned_to.name) if category.assigned_to %></td>
13 <td><%=h(category.assigned_to.name) if category.assigned_to %></td>
14 <td class="buttons">
14 <td class="buttons">
15 <%= link_to_if_authorized l(:button_edit), { :controller => 'issue_categories', :action => 'edit', :id => category }, :class => 'icon icon-edit' %>
15 <% if User.current.allowed_to?(:manage_categories, @project) %>
16 <%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => category}, :method => :post, :class => 'icon icon-del' %>
16 <%= link_to l(:button_edit), edit_issue_category_path(category), :class => 'icon icon-edit' %>
17 <%= link_to l(:button_delete), issue_category_path(category), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
18 <% end %>
17 </td>
19 </td>
18 </tr>
20 </tr>
19 <% end %>
21 <% end %>
@@ -24,4 +26,4
24 <p class="nodata"><%= l(:label_no_data) %></p>
26 <p class="nodata"><%= l(:label_no_data) %></p>
25 <% end %>
27 <% end %>
26
28
27 <p><%= link_to_if_authorized l(:label_issue_category_new), :controller => 'issue_categories', :action => 'new', :project_id => @project %></p>
29 <p><%= link_to l(:label_issue_category_new), new_project_issue_category_path(@project) if User.current.allowed_to?(:manage_categories, @project) %></p>
@@ -157,6 +157,7 ActionController::Routing::Routes.draw do |map|
157 project.resources :news, :shallow => true
157 project.resources :news, :shallow => true
158 project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
158 project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
159 project.resources :queries, :only => [:new, :create]
159 project.resources :queries, :only => [:new, :create]
160 project.resources :issue_categories, :shallow => true
160
161
161 project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
162 project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
162 project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
163 project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
@@ -194,10 +195,6 ActionController::Routing::Routes.draw do |map|
194 activity.connect 'activity.:format', :id => nil
195 activity.connect 'activity.:format', :id => nil
195 end
196 end
196
197
197 map.with_options :controller => 'issue_categories' do |categories|
198 categories.connect 'projects/:project_id/issue_categories/new', :action => 'new'
199 end
200
201 map.with_options :controller => 'repositories' do |repositories|
198 map.with_options :controller => 'repositories' do |repositories|
202 repositories.with_options :conditions => {:method => :get} do |repository_views|
199 repositories.with_options :conditions => {:method => :get} do |repository_views|
203 repository_views.connect 'projects/:id/repository', :action => 'show'
200 repository_views.connect 'projects/:id/repository', :action => 'show'
@@ -58,7 +58,7 Redmine::AccessControl.map do |map|
58
58
59 map.project_module :issue_tracking do |map|
59 map.project_module :issue_tracking do |map|
60 # Issue categories
60 # Issue categories
61 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
61 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :create, :edit, :update, :destroy]}, :require => :member
62 # Issues
62 # Issues
63 map.permission :view_issues, {:issues => [:index, :show],
63 map.permission :view_issues, {:issues => [:index, :show],
64 :auto_complete => [:issues],
64 :auto_complete => [:issues],
@@ -32,17 +32,17 class IssueCategoriesControllerTest < ActionController::TestCase
32 @request.session[:user_id] = 2
32 @request.session[:user_id] = 2
33 end
33 end
34
34
35 def test_get_new
35 def test_new
36 @request.session[:user_id] = 2 # manager
36 @request.session[:user_id] = 2 # manager
37 get :new, :project_id => '1'
37 get :new, :project_id => '1'
38 assert_response :success
38 assert_response :success
39 assert_template 'new'
39 assert_template 'new'
40 end
40 end
41
41
42 def test_post_new
42 def test_create
43 @request.session[:user_id] = 2 # manager
43 @request.session[:user_id] = 2 # manager
44 assert_difference 'IssueCategory.count' do
44 assert_difference 'IssueCategory.count' do
45 post :new, :project_id => '1', :category => {:name => 'New category'}
45 post :create, :project_id => '1', :category => {:name => 'New category'}
46 end
46 end
47 assert_redirected_to '/projects/ecookbook/settings/categories'
47 assert_redirected_to '/projects/ecookbook/settings/categories'
48 category = IssueCategory.find_by_name('New category')
48 category = IssueCategory.find_by_name('New category')
@@ -50,27 +50,47 class IssueCategoriesControllerTest < ActionController::TestCase
50 assert_equal 1, category.project_id
50 assert_equal 1, category.project_id
51 end
51 end
52
52
53 def test_post_edit
53 def test_create_failure
54 @request.session[:user_id] = 2
55 post :create, :project_id => '1', :category => {:name => ''}
56 assert_response :success
57 assert_template 'new'
58 end
59
60 def test_edit
61 @request.session[:user_id] = 2
62 get :edit, :id => 2
63 assert_response :success
64 assert_template 'edit'
65 end
66
67 def test_update
54 assert_no_difference 'IssueCategory.count' do
68 assert_no_difference 'IssueCategory.count' do
55 post :edit, :id => 2, :category => { :name => 'Testing' }
69 put :update, :id => 2, :category => { :name => 'Testing' }
56 end
70 end
57 assert_redirected_to '/projects/ecookbook/settings/categories'
71 assert_redirected_to '/projects/ecookbook/settings/categories'
58 assert_equal 'Testing', IssueCategory.find(2).name
72 assert_equal 'Testing', IssueCategory.find(2).name
59 end
73 end
60
74
61 def test_edit_not_found
75 def test_update_failure
62 post :edit, :id => 97, :category => { :name => 'Testing' }
76 put :update, :id => 2, :category => { :name => '' }
77 assert_response :success
78 assert_template 'edit'
79 end
80
81 def test_update_not_found
82 put :update, :id => 97, :category => { :name => 'Testing' }
63 assert_response 404
83 assert_response 404
64 end
84 end
65
85
66 def test_destroy_category_not_in_use
86 def test_destroy_category_not_in_use
67 post :destroy, :id => 2
87 delete :destroy, :id => 2
68 assert_redirected_to '/projects/ecookbook/settings/categories'
88 assert_redirected_to '/projects/ecookbook/settings/categories'
69 assert_nil IssueCategory.find_by_id(2)
89 assert_nil IssueCategory.find_by_id(2)
70 end
90 end
71
91
72 def test_destroy_category_in_use
92 def test_destroy_category_in_use
73 post :destroy, :id => 1
93 delete :destroy, :id => 1
74 assert_response :success
94 assert_response :success
75 assert_template 'destroy'
95 assert_template 'destroy'
76 assert_not_nil IssueCategory.find_by_id(1)
96 assert_not_nil IssueCategory.find_by_id(1)
@@ -78,7 +98,7 class IssueCategoriesControllerTest < ActionController::TestCase
78
98
79 def test_destroy_category_in_use_with_reassignment
99 def test_destroy_category_in_use_with_reassignment
80 issue = Issue.find(:first, :conditions => {:category_id => 1})
100 issue = Issue.find(:first, :conditions => {:category_id => 1})
81 post :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
101 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
82 assert_redirected_to '/projects/ecookbook/settings/categories'
102 assert_redirected_to '/projects/ecookbook/settings/categories'
83 assert_nil IssueCategory.find_by_id(1)
103 assert_nil IssueCategory.find_by_id(1)
84 # check that the issue was reassign
104 # check that the issue was reassign
@@ -87,7 +107,7 class IssueCategoriesControllerTest < ActionController::TestCase
87
107
88 def test_destroy_category_in_use_without_reassignment
108 def test_destroy_category_in_use_without_reassignment
89 issue = Issue.find(:first, :conditions => {:category_id => 1})
109 issue = Issue.find(:first, :conditions => {:category_id => 1})
90 post :destroy, :id => 1, :todo => 'nullify'
110 delete :destroy, :id => 1, :todo => 'nullify'
91 assert_redirected_to '/projects/ecookbook/settings/categories'
111 assert_redirected_to '/projects/ecookbook/settings/categories'
92 assert_nil IssueCategory.find_by_id(1)
112 assert_nil IssueCategory.find_by_id(1)
93 # check that the issue category was nullified
113 # check that the issue category was nullified
General Comments 0
You need to be logged in to leave comments. Login now