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