##// END OF EJS Templates
Reorder links refactoring (follows r2526)....
Jean-Philippe Lang -
r2478:47f5713b1e1c
parent child
Show More
@@ -1,87 +1,81
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class BoardsController < ApplicationController
18 class BoardsController < ApplicationController
19 before_filter :find_project, :authorize
19 before_filter :find_project, :authorize
20
20
21 helper :messages
21 helper :messages
22 include MessagesHelper
22 include MessagesHelper
23 helper :sort
23 helper :sort
24 include SortHelper
24 include SortHelper
25 helper :watchers
25 helper :watchers
26 include WatchersHelper
26 include WatchersHelper
27
27
28 def index
28 def index
29 @boards = @project.boards
29 @boards = @project.boards
30 # show the board if there is only one
30 # show the board if there is only one
31 if @boards.size == 1
31 if @boards.size == 1
32 @board = @boards.first
32 @board = @boards.first
33 show
33 show
34 end
34 end
35 end
35 end
36
36
37 def show
37 def show
38 sort_init 'updated_on', 'desc'
38 sort_init 'updated_on', 'desc'
39 sort_update 'created_on' => "#{Message.table_name}.created_on",
39 sort_update 'created_on' => "#{Message.table_name}.created_on",
40 'replies' => "#{Message.table_name}.replies_count",
40 'replies' => "#{Message.table_name}.replies_count",
41 'updated_on' => "#{Message.table_name}.updated_on"
41 'updated_on' => "#{Message.table_name}.updated_on"
42
42
43 @topic_count = @board.topics.count
43 @topic_count = @board.topics.count
44 @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
44 @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
45 @topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
45 @topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
46 :include => [:author, {:last_reply => :author}],
46 :include => [:author, {:last_reply => :author}],
47 :limit => @topic_pages.items_per_page,
47 :limit => @topic_pages.items_per_page,
48 :offset => @topic_pages.current.offset
48 :offset => @topic_pages.current.offset
49 render :action => 'show', :layout => !request.xhr?
49 render :action => 'show', :layout => !request.xhr?
50 end
50 end
51
51
52 verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
52 verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
53
53
54 def new
54 def new
55 @board = Board.new(params[:board])
55 @board = Board.new(params[:board])
56 @board.project = @project
56 @board.project = @project
57 if request.post? && @board.save
57 if request.post? && @board.save
58 flash[:notice] = l(:notice_successful_create)
58 flash[:notice] = l(:notice_successful_create)
59 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
59 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
60 end
60 end
61 end
61 end
62
62
63 def edit
63 def edit
64 if request.post? && @board.update_attributes(params[:board])
64 if request.post? && @board.update_attributes(params[:board])
65 case params[:position]
66 when 'highest'; @board.move_to_top
67 when 'higher'; @board.move_higher
68 when 'lower'; @board.move_lower
69 when 'lowest'; @board.move_to_bottom
70 end if params[:position]
71 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
65 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
72 end
66 end
73 end
67 end
74
68
75 def destroy
69 def destroy
76 @board.destroy
70 @board.destroy
77 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
71 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
78 end
72 end
79
73
80 private
74 private
81 def find_project
75 def find_project
82 @project = Project.find(params[:project_id])
76 @project = Project.find(params[:project_id])
83 @board = @project.boards.find(params[:id]) if params[:id]
77 @board = @project.boards.find(params[:id]) if params[:id]
84 rescue ActiveRecord::RecordNotFound
78 rescue ActiveRecord::RecordNotFound
85 render_404
79 render_404
86 end
80 end
87 end
81 end
@@ -1,73 +1,58
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class CustomFieldsController < ApplicationController
18 class CustomFieldsController < ApplicationController
19 before_filter :require_admin
19 before_filter :require_admin
20
20
21 def index
21 def index
22 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
22 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
23 @tab = params[:tab] || 'IssueCustomField'
23 @tab = params[:tab] || 'IssueCustomField'
24 end
24 end
25
25
26 def new
26 def new
27 @custom_field = begin
27 @custom_field = begin
28 if params[:type].to_s.match(/.+CustomField$/)
28 if params[:type].to_s.match(/.+CustomField$/)
29 params[:type].to_s.constantize.new(params[:custom_field])
29 params[:type].to_s.constantize.new(params[:custom_field])
30 end
30 end
31 rescue
31 rescue
32 end
32 end
33 redirect_to(:action => 'index') and return unless @custom_field.is_a?(CustomField)
33 redirect_to(:action => 'index') and return unless @custom_field.is_a?(CustomField)
34
34
35 if request.post? and @custom_field.save
35 if request.post? and @custom_field.save
36 flash[:notice] = l(:notice_successful_create)
36 flash[:notice] = l(:notice_successful_create)
37 redirect_to :action => 'index', :tab => @custom_field.class.name
37 redirect_to :action => 'index', :tab => @custom_field.class.name
38 end
38 end
39 @trackers = Tracker.find(:all, :order => 'position')
39 @trackers = Tracker.find(:all, :order => 'position')
40 end
40 end
41
41
42 def edit
42 def edit
43 @custom_field = CustomField.find(params[:id])
43 @custom_field = CustomField.find(params[:id])
44 if request.post? and @custom_field.update_attributes(params[:custom_field])
44 if request.post? and @custom_field.update_attributes(params[:custom_field])
45 flash[:notice] = l(:notice_successful_update)
45 flash[:notice] = l(:notice_successful_update)
46 redirect_to :action => 'index', :tab => @custom_field.class.name
46 redirect_to :action => 'index', :tab => @custom_field.class.name
47 end
47 end
48 @trackers = Tracker.find(:all, :order => 'position')
48 @trackers = Tracker.find(:all, :order => 'position')
49 end
49 end
50
51 def move
52 @custom_field = CustomField.find(params[:id])
53 case params[:position]
54 when 'highest'
55 @custom_field.move_to_top
56 when 'higher'
57 @custom_field.move_higher
58 when 'lower'
59 @custom_field.move_lower
60 when 'lowest'
61 @custom_field.move_to_bottom
62 end if params[:position]
63 redirect_to :action => 'index', :tab => @custom_field.class.name
64 end
65
50
66 def destroy
51 def destroy
67 @custom_field = CustomField.find(params[:id]).destroy
52 @custom_field = CustomField.find(params[:id]).destroy
68 redirect_to :action => 'index', :tab => @custom_field.class.name
53 redirect_to :action => 'index', :tab => @custom_field.class.name
69 rescue
54 rescue
70 flash[:error] = "Unable to delete custom field"
55 flash[:error] = "Unable to delete custom field"
71 redirect_to :action => 'index'
56 redirect_to :action => 'index'
72 end
57 end
73 end
58 end
@@ -1,93 +1,78
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class EnumerationsController < ApplicationController
18 class EnumerationsController < ApplicationController
19 before_filter :require_admin
19 before_filter :require_admin
20
20
21 def index
21 def index
22 list
22 list
23 render :action => 'list'
23 render :action => 'list'
24 end
24 end
25
25
26 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
26 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
27 verify :method => :post, :only => [ :destroy, :create, :update ],
27 verify :method => :post, :only => [ :destroy, :create, :update ],
28 :redirect_to => { :action => :list }
28 :redirect_to => { :action => :list }
29
29
30 def list
30 def list
31 end
31 end
32
32
33 def new
33 def new
34 @enumeration = Enumeration.new(:opt => params[:opt])
34 @enumeration = Enumeration.new(:opt => params[:opt])
35 end
35 end
36
36
37 def create
37 def create
38 @enumeration = Enumeration.new(params[:enumeration])
38 @enumeration = Enumeration.new(params[:enumeration])
39 if @enumeration.save
39 if @enumeration.save
40 flash[:notice] = l(:notice_successful_create)
40 flash[:notice] = l(:notice_successful_create)
41 redirect_to :action => 'list', :opt => @enumeration.opt
41 redirect_to :action => 'list', :opt => @enumeration.opt
42 else
42 else
43 render :action => 'new'
43 render :action => 'new'
44 end
44 end
45 end
45 end
46
46
47 def edit
47 def edit
48 @enumeration = Enumeration.find(params[:id])
48 @enumeration = Enumeration.find(params[:id])
49 end
49 end
50
50
51 def update
51 def update
52 @enumeration = Enumeration.find(params[:id])
52 @enumeration = Enumeration.find(params[:id])
53 if @enumeration.update_attributes(params[:enumeration])
53 if @enumeration.update_attributes(params[:enumeration])
54 flash[:notice] = l(:notice_successful_update)
54 flash[:notice] = l(:notice_successful_update)
55 redirect_to :action => 'list', :opt => @enumeration.opt
55 redirect_to :action => 'list', :opt => @enumeration.opt
56 else
56 else
57 render :action => 'edit'
57 render :action => 'edit'
58 end
58 end
59 end
59 end
60
61 def move
62 @enumeration = Enumeration.find(params[:id])
63 case params[:position]
64 when 'highest'
65 @enumeration.move_to_top
66 when 'higher'
67 @enumeration.move_higher
68 when 'lower'
69 @enumeration.move_lower
70 when 'lowest'
71 @enumeration.move_to_bottom
72 end if params[:position]
73 redirect_to :action => 'index'
74 end
75
60
76 def destroy
61 def destroy
77 @enumeration = Enumeration.find(params[:id])
62 @enumeration = Enumeration.find(params[:id])
78 if !@enumeration.in_use?
63 if !@enumeration.in_use?
79 # No associated objects
64 # No associated objects
80 @enumeration.destroy
65 @enumeration.destroy
81 redirect_to :action => 'index'
66 redirect_to :action => 'index'
82 elsif params[:reassign_to_id]
67 elsif params[:reassign_to_id]
83 if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
68 if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
84 @enumeration.destroy(reassign_to)
69 @enumeration.destroy(reassign_to)
85 redirect_to :action => 'index'
70 redirect_to :action => 'index'
86 end
71 end
87 end
72 end
88 @enumerations = Enumeration.values(@enumeration.opt) - [@enumeration]
73 @enumerations = Enumeration.values(@enumeration.opt) - [@enumeration]
89 #rescue
74 #rescue
90 # flash[:error] = 'Unable to delete enumeration'
75 # flash[:error] = 'Unable to delete enumeration'
91 # redirect_to :action => 'index'
76 # redirect_to :action => 'index'
92 end
77 end
93 end
78 end
@@ -1,84 +1,69
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssueStatusesController < ApplicationController
18 class IssueStatusesController < ApplicationController
19 before_filter :require_admin
19 before_filter :require_admin
20
20
21 verify :method => :post, :only => [ :destroy, :create, :update, :move ],
21 verify :method => :post, :only => [ :destroy, :create, :update, :move ],
22 :redirect_to => { :action => :list }
22 :redirect_to => { :action => :list }
23
23
24 def index
24 def index
25 list
25 list
26 render :action => 'list' unless request.xhr?
26 render :action => 'list' unless request.xhr?
27 end
27 end
28
28
29 def list
29 def list
30 @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
30 @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
31 render :action => "list", :layout => false if request.xhr?
31 render :action => "list", :layout => false if request.xhr?
32 end
32 end
33
33
34 def new
34 def new
35 @issue_status = IssueStatus.new
35 @issue_status = IssueStatus.new
36 end
36 end
37
37
38 def create
38 def create
39 @issue_status = IssueStatus.new(params[:issue_status])
39 @issue_status = IssueStatus.new(params[:issue_status])
40 if @issue_status.save
40 if @issue_status.save
41 flash[:notice] = l(:notice_successful_create)
41 flash[:notice] = l(:notice_successful_create)
42 redirect_to :action => 'list'
42 redirect_to :action => 'list'
43 else
43 else
44 render :action => 'new'
44 render :action => 'new'
45 end
45 end
46 end
46 end
47
47
48 def edit
48 def edit
49 @issue_status = IssueStatus.find(params[:id])
49 @issue_status = IssueStatus.find(params[:id])
50 end
50 end
51
51
52 def update
52 def update
53 @issue_status = IssueStatus.find(params[:id])
53 @issue_status = IssueStatus.find(params[:id])
54 if @issue_status.update_attributes(params[:issue_status])
54 if @issue_status.update_attributes(params[:issue_status])
55 flash[:notice] = l(:notice_successful_update)
55 flash[:notice] = l(:notice_successful_update)
56 redirect_to :action => 'list'
56 redirect_to :action => 'list'
57 else
57 else
58 render :action => 'edit'
58 render :action => 'edit'
59 end
59 end
60 end
60 end
61
62 def move
63 @issue_status = IssueStatus.find(params[:id])
64 case params[:position]
65 when 'highest'
66 @issue_status.move_to_top
67 when 'higher'
68 @issue_status.move_higher
69 when 'lower'
70 @issue_status.move_lower
71 when 'lowest'
72 @issue_status.move_to_bottom
73 end if params[:position]
74 redirect_to :action => 'list'
75 end
76
61
77 def destroy
62 def destroy
78 IssueStatus.find(params[:id]).destroy
63 IssueStatus.find(params[:id]).destroy
79 redirect_to :action => 'list'
64 redirect_to :action => 'list'
80 rescue
65 rescue
81 flash[:error] = "Unable to delete issue status"
66 flash[:error] = "Unable to delete issue status"
82 redirect_to :action => 'list'
67 redirect_to :action => 'list'
83 end
68 end
84 end
69 end
@@ -1,94 +1,79
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class RolesController < ApplicationController
18 class RolesController < ApplicationController
19 before_filter :require_admin
19 before_filter :require_admin
20
20
21 verify :method => :post, :only => [ :destroy, :move ],
21 verify :method => :post, :only => [ :destroy, :move ],
22 :redirect_to => { :action => :list }
22 :redirect_to => { :action => :list }
23
23
24 def index
24 def index
25 list
25 list
26 render :action => 'list' unless request.xhr?
26 render :action => 'list' unless request.xhr?
27 end
27 end
28
28
29 def list
29 def list
30 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
30 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
31 render :action => "list", :layout => false if request.xhr?
31 render :action => "list", :layout => false if request.xhr?
32 end
32 end
33
33
34 def new
34 def new
35 # Prefills the form with 'Non member' role permissions
35 # Prefills the form with 'Non member' role permissions
36 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
36 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
37 if request.post? && @role.save
37 if request.post? && @role.save
38 # workflow copy
38 # workflow copy
39 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
39 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
40 @role.workflows.copy(copy_from)
40 @role.workflows.copy(copy_from)
41 end
41 end
42 flash[:notice] = l(:notice_successful_create)
42 flash[:notice] = l(:notice_successful_create)
43 redirect_to :action => 'list'
43 redirect_to :action => 'list'
44 end
44 end
45 @permissions = @role.setable_permissions
45 @permissions = @role.setable_permissions
46 @roles = Role.find :all, :order => 'builtin, position'
46 @roles = Role.find :all, :order => 'builtin, position'
47 end
47 end
48
48
49 def edit
49 def edit
50 @role = Role.find(params[:id])
50 @role = Role.find(params[:id])
51 if request.post? and @role.update_attributes(params[:role])
51 if request.post? and @role.update_attributes(params[:role])
52 flash[:notice] = l(:notice_successful_update)
52 flash[:notice] = l(:notice_successful_update)
53 redirect_to :action => 'list'
53 redirect_to :action => 'list'
54 end
54 end
55 @permissions = @role.setable_permissions
55 @permissions = @role.setable_permissions
56 end
56 end
57
57
58 def destroy
58 def destroy
59 @role = Role.find(params[:id])
59 @role = Role.find(params[:id])
60 @role.destroy
60 @role.destroy
61 redirect_to :action => 'list'
61 redirect_to :action => 'list'
62 rescue
62 rescue
63 flash[:error] = 'This role is in use and can not be deleted.'
63 flash[:error] = 'This role is in use and can not be deleted.'
64 redirect_to :action => 'index'
64 redirect_to :action => 'index'
65 end
65 end
66
66
67 def move
68 @role = Role.find(params[:id])
69 case params[:position]
70 when 'highest'
71 @role.move_to_top
72 when 'higher'
73 @role.move_higher
74 when 'lower'
75 @role.move_lower
76 when 'lowest'
77 @role.move_to_bottom
78 end if params[:position]
79 redirect_to :action => 'list'
80 end
81
82 def report
67 def report
83 @roles = Role.find(:all, :order => 'builtin, position')
68 @roles = Role.find(:all, :order => 'builtin, position')
84 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
69 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
85 if request.post?
70 if request.post?
86 @roles.each do |role|
71 @roles.each do |role|
87 role.permissions = params[:permissions][role.id.to_s]
72 role.permissions = params[:permissions][role.id.to_s]
88 role.save
73 role.save
89 end
74 end
90 flash[:notice] = l(:notice_successful_update)
75 flash[:notice] = l(:notice_successful_update)
91 redirect_to :action => 'list'
76 redirect_to :action => 'list'
92 end
77 end
93 end
78 end
94 end
79 end
@@ -1,58 +1,53
1 <h2><%=l(:label_custom_field_plural)%></h2>
1 <h2><%=l(:label_custom_field_plural)%></h2>
2
2
3 <% selected_tab = params[:tab] ? params[:tab].to_s : custom_fields_tabs.first[:name] %>
3 <% selected_tab = params[:tab] ? params[:tab].to_s : custom_fields_tabs.first[:name] %>
4
4
5 <div class="tabs">
5 <div class="tabs">
6 <ul>
6 <ul>
7 <% custom_fields_tabs.each do |tab| -%>
7 <% custom_fields_tabs.each do |tab| -%>
8 <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
8 <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
9 :id => "tab-#{tab[:name]}",
9 :id => "tab-#{tab[:name]}",
10 :class => (tab[:name] != selected_tab ? nil : 'selected'),
10 :class => (tab[:name] != selected_tab ? nil : 'selected'),
11 :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
11 :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
12 <% end -%>
12 <% end -%>
13 </ul>
13 </ul>
14 </div>
14 </div>
15
15
16 <% custom_fields_tabs.each do |tab| %>
16 <% custom_fields_tabs.each do |tab| %>
17 <div id="tab-content-<%= tab[:name] %>" class="tab-content" style="<%= tab[:name] != selected_tab ? 'display:none' : nil %>">
17 <div id="tab-content-<%= tab[:name] %>" class="tab-content" style="<%= tab[:name] != selected_tab ? 'display:none' : nil %>">
18 <table class="list">
18 <table class="list">
19 <thead><tr>
19 <thead><tr>
20 <th width="30%"><%=l(:field_name)%></th>
20 <th width="30%"><%=l(:field_name)%></th>
21 <th><%=l(:field_field_format)%></th>
21 <th><%=l(:field_field_format)%></th>
22 <th><%=l(:field_is_required)%></th>
22 <th><%=l(:field_is_required)%></th>
23 <% if tab[:name] == 'IssueCustomField' %>
23 <% if tab[:name] == 'IssueCustomField' %>
24 <th><%=l(:field_is_for_all)%></th>
24 <th><%=l(:field_is_for_all)%></th>
25 <th><%=l(:label_used_by)%></th>
25 <th><%=l(:label_used_by)%></th>
26 <% end %>
26 <% end %>
27 <th><%=l(:button_sort)%></th>
27 <th><%=l(:button_sort)%></th>
28 <th width="10%"></th>
28 <th width="10%"></th>
29 </tr></thead>
29 </tr></thead>
30 <tbody>
30 <tbody>
31 <% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%>
31 <% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%>
32 <tr class="<%= cycle("odd", "even") %>">
32 <tr class="<%= cycle("odd", "even") %>">
33 <td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
33 <td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
34 <td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
34 <td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
35 <td align="center"><%= image_tag 'true.png' if custom_field.is_required? %></td>
35 <td align="center"><%= image_tag 'true.png' if custom_field.is_required? %></td>
36 <% if tab[:name] == 'IssueCustomField' %>
36 <% if tab[:name] == 'IssueCustomField' %>
37 <td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
37 <td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
38 <td align="center"><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
38 <td align="center"><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
39 <% end %>
39 <% end %>
40 <td align="center" style="width:15%;">
40 <td align="center" style="width:15%;"><%= reorder_links('custom_field', {:action => 'edit', :id => custom_field}) %></td>
41 <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => custom_field, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
42 <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => custom_field, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
43 <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => custom_field, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
44 <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => custom_field, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
45 </td>
46 <td align="center">
41 <td align="center">
47 <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
42 <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
48 </td>
43 </td>
49 </tr>
44 </tr>
50 <% end; reset_cycle %>
45 <% end; reset_cycle %>
51 </tbody>
46 </tbody>
52 </table>
47 </table>
53
48
54 <p><%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %></p>
49 <p><%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %></p>
55 </div>
50 </div>
56 <% end %>
51 <% end %>
57
52
58 <% html_title(l(:label_custom_field_plural)) -%>
53 <% html_title(l(:label_custom_field_plural)) -%>
@@ -1,31 +1,26
1 <h2><%=l(:label_enumerations)%></h2>
1 <h2><%=l(:label_enumerations)%></h2>
2
2
3 <% Enumeration::OPTIONS.each do |option, params| %>
3 <% Enumeration::OPTIONS.each do |option, params| %>
4 <h3><%= l(params[:label]) %></h3>
4 <h3><%= l(params[:label]) %></h3>
5
5
6 <% enumerations = Enumeration.values(option) %>
6 <% enumerations = Enumeration.values(option) %>
7 <% if enumerations.any? %>
7 <% if enumerations.any? %>
8 <table class="list">
8 <table class="list">
9 <% enumerations.each do |enumeration| %>
9 <% enumerations.each do |enumeration| %>
10 <tr class="<%= cycle('odd', 'even') %>">
10 <tr class="<%= cycle('odd', 'even') %>">
11 <td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td>
11 <td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td>
12 <td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
12 <td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
13 <td style="width:15%;">
13 <td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}) %></td>
14 <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => enumeration, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
15 <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => enumeration, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
16 <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => enumeration, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
17 <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => enumeration, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
18 </td>
19 <td align="center" style="width:10%;">
14 <td align="center" style="width:10%;">
20 <%= link_to l(:button_delete), { :action => 'destroy', :id => enumeration }, :method => :post, :confirm => l(:text_are_you_sure), :class => "icon icon-del" %>
15 <%= link_to l(:button_delete), { :action => 'destroy', :id => enumeration }, :method => :post, :confirm => l(:text_are_you_sure), :class => "icon icon-del" %>
21 </td>
16 </td>
22 </tr>
17 </tr>
23 <% end %>
18 <% end %>
24 </table>
19 </table>
25 <% reset_cycle %>
20 <% reset_cycle %>
26 <% end %>
21 <% end %>
27
22
28 <p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p>
23 <p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p>
29 <% end %>
24 <% end %>
30
25
31 <% html_title(l(:label_enumerations)) -%>
26 <% html_title(l(:label_enumerations)) -%>
@@ -1,37 +1,32
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to l(:label_issue_status_new), {:action => 'new'}, :class => 'icon icon-add' %>
2 <%= link_to l(:label_issue_status_new), {:action => 'new'}, :class => 'icon icon-add' %>
3 </div>
3 </div>
4
4
5 <h2><%=l(:label_issue_status_plural)%></h2>
5 <h2><%=l(:label_issue_status_plural)%></h2>
6
6
7 <table class="list">
7 <table class="list">
8 <thead><tr>
8 <thead><tr>
9 <th><%=l(:field_status)%></th>
9 <th><%=l(:field_status)%></th>
10 <th><%=l(:field_is_default)%></th>
10 <th><%=l(:field_is_default)%></th>
11 <th><%=l(:field_is_closed)%></th>
11 <th><%=l(:field_is_closed)%></th>
12 <th><%=l(:button_sort)%></th>
12 <th><%=l(:button_sort)%></th>
13 <th></th>
13 <th></th>
14 </tr></thead>
14 </tr></thead>
15 <tbody>
15 <tbody>
16 <% for status in @issue_statuses %>
16 <% for status in @issue_statuses %>
17 <tr class="<%= cycle("odd", "even") %>">
17 <tr class="<%= cycle("odd", "even") %>">
18 <td><%= link_to status.name, :action => 'edit', :id => status %></td>
18 <td><%= link_to status.name, :action => 'edit', :id => status %></td>
19 <td align="center"><%= image_tag 'true.png' if status.is_default? %></td>
19 <td align="center"><%= image_tag 'true.png' if status.is_default? %></td>
20 <td align="center"><%= image_tag 'true.png' if status.is_closed? %></td>
20 <td align="center"><%= image_tag 'true.png' if status.is_closed? %></td>
21 <td align="center" style="width:15%;">
21 <td align="center" style="width:15%;"><%= reorder_links('issue_status', {:action => 'update', :id => status}) %></td>
22 <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => status, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
23 <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => status, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
24 <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => status, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
25 <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => status, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
26 </td>
27 <td align="center" style="width:10%;">
22 <td align="center" style="width:10%;">
28 <%= button_to l(:button_delete), { :action => 'destroy', :id => status }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
23 <%= button_to l(:button_delete), { :action => 'destroy', :id => status }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
29 </td>
24 </td>
30 </tr>
25 </tr>
31 <% end %>
26 <% end %>
32 </tbody>
27 </tbody>
33 </table>
28 </table>
34
29
35 <p class="pagination"><%= pagination_links_full @issue_status_pages %></p>
30 <p class="pagination"><%= pagination_links_full @issue_status_pages %></p>
36
31
37 <% html_title(l(:label_issue_status_plural)) -%>
32 <% html_title(l(:label_issue_status_plural)) -%>
@@ -1,28 +1,25
1 <% if @project.boards.any? %>
1 <% if @project.boards.any? %>
2 <table class="list">
2 <table class="list">
3 <thead><th><%= l(:label_board) %></th><th><%= l(:field_description) %></th><th style="width:15%"></th><th style="width:15%"></th><th style="width:15%"></th></thead>
3 <thead><th><%= l(:label_board) %></th><th><%= l(:field_description) %></th><th style="width:15%"></th><th style="width:15%"></th><th style="width:15%"></th></thead>
4 <tbody>
4 <tbody>
5 <% @project.boards.each do |board|
5 <% @project.boards.each do |board|
6 next if board.new_record? %>
6 next if board.new_record? %>
7 <tr class="<%= cycle 'odd', 'even' %>">
7 <tr class="<%= cycle 'odd', 'even' %>">
8 <td><%=h board.name %></td>
8 <td><%=h board.name %></td>
9 <td><%=h board.description %></td>
9 <td><%=h board.description %></td>
10 <td align="center">
10 <td align="center">
11 <% if authorize_for("boards", "edit") %>
11 <% if authorize_for("boards", "edit") %>
12 <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
12 <%= reorder_links('board', {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}) %>
13 <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
14 <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
15 <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
16 <% end %>
13 <% end %>
17 </td>
14 </td>
18 <td align="center"><%= link_to_if_authorized l(:button_edit), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}, :class => 'icon icon-edit' %></td>
15 <td align="center"><%= link_to_if_authorized l(:button_edit), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}, :class => 'icon icon-edit' %></td>
19 <td align="center"><%= 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' %></td>
16 <td align="center"><%= 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' %></td>
20 </tr>
17 </tr>
21 <% end %>
18 <% end %>
22 </tbody>
19 </tbody>
23 </table>
20 </table>
24 <% else %>
21 <% else %>
25 <p class="nodata"><%= l(:label_no_data) %></p>
22 <p class="nodata"><%= l(:label_no_data) %></p>
26 <% end %>
23 <% end %>
27
24
28 <p><%= link_to_if_authorized l(:label_board_new), {:controller => 'boards', :action => 'new', :project_id => @project} %></p>
25 <p><%= link_to_if_authorized l(:label_board_new), {:controller => 'boards', :action => 'new', :project_id => @project} %></p>
@@ -1,37 +1,34
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to l(:label_role_new), {:action => 'new'}, :class => 'icon icon-add' %>
2 <%= link_to l(:label_role_new), {:action => 'new'}, :class => 'icon icon-add' %>
3 </div>
3 </div>
4
4
5 <h2><%=l(:label_role_plural)%></h2>
5 <h2><%=l(:label_role_plural)%></h2>
6
6
7 <table class="list">
7 <table class="list">
8 <thead><tr>
8 <thead><tr>
9 <th><%=l(:label_role)%></th>
9 <th><%=l(:label_role)%></th>
10 <th><%=l(:button_sort)%></th>
10 <th><%=l(:button_sort)%></th>
11 <th></th>
11 <th></th>
12 </tr></thead>
12 </tr></thead>
13 <tbody>
13 <tbody>
14 <% for role in @roles %>
14 <% for role in @roles %>
15 <tr class="<%= cycle("odd", "even") %>">
15 <tr class="<%= cycle("odd", "even") %>">
16 <td><%= content_tag(role.builtin? ? 'em' : 'span', link_to(role.name, :action => 'edit', :id => role)) %></td>
16 <td><%= content_tag(role.builtin? ? 'em' : 'span', link_to(role.name, :action => 'edit', :id => role)) %></td>
17 <td align="center" style="width:15%;">
17 <td align="center" style="width:15%;">
18 <% unless role.builtin? %>
18 <% unless role.builtin? %>
19 <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => role, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
19 <%= reorder_links('role', {:action => 'edit', :id => role}) %>
20 <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => role, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
21 <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => role, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
22 <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => role, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
23 <% end %>
20 <% end %>
24 </td>
21 </td>
25 <td align="center" style="width:10%;">
22 <td align="center" style="width:10%;">
26 <%= button_to(l(:button_delete), { :action => 'destroy', :id => role }, :confirm => l(:text_are_you_sure), :class => "button-small", :disabled => role.builtin? ) %>
23 <%= button_to(l(:button_delete), { :action => 'destroy', :id => role }, :confirm => l(:text_are_you_sure), :class => "button-small", :disabled => role.builtin? ) %>
27 </td>
24 </td>
28 </tr>
25 </tr>
29 <% end %>
26 <% end %>
30 </tbody>
27 </tbody>
31 </table>
28 </table>
32
29
33 <p class="pagination"><%= pagination_links_full @role_pages %></p>
30 <p class="pagination"><%= pagination_links_full @role_pages %></p>
34
31
35 <p><%= link_to l(:label_permissions_report), :action => 'report' %></p>
32 <p><%= link_to l(:label_permissions_report), :action => 'report' %></p>
36
33
37 <% html_title(l(:label_role_plural)) -%>
34 <% html_title(l(:label_role_plural)) -%>
@@ -1,180 +1,180
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'roles_controller'
19 require 'roles_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RolesController; def rescue_action(e) raise e end; end
22 class RolesController; def rescue_action(e) raise e end; end
23
23
24 class RolesControllerTest < Test::Unit::TestCase
24 class RolesControllerTest < Test::Unit::TestCase
25 fixtures :roles, :users, :members, :workflows
25 fixtures :roles, :users, :members, :workflows
26
26
27 def setup
27 def setup
28 @controller = RolesController.new
28 @controller = RolesController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 @request.session[:user_id] = 1 # admin
32 @request.session[:user_id] = 1 # admin
33 end
33 end
34
34
35 def test_get_index
35 def test_get_index
36 get :index
36 get :index
37 assert_response :success
37 assert_response :success
38 assert_template 'list'
38 assert_template 'list'
39
39
40 assert_not_nil assigns(:roles)
40 assert_not_nil assigns(:roles)
41 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
41 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
42
42
43 assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' },
43 assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' },
44 :content => 'Manager'
44 :content => 'Manager'
45 end
45 end
46
46
47 def test_get_new
47 def test_get_new
48 get :new
48 get :new
49 assert_response :success
49 assert_response :success
50 assert_template 'new'
50 assert_template 'new'
51 end
51 end
52
52
53 def test_post_new_with_validaton_failure
53 def test_post_new_with_validaton_failure
54 post :new, :role => {:name => '',
54 post :new, :role => {:name => '',
55 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
55 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
56 :assignable => '0'}
56 :assignable => '0'}
57
57
58 assert_response :success
58 assert_response :success
59 assert_template 'new'
59 assert_template 'new'
60 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
60 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
61 end
61 end
62
62
63 def test_post_new_without_workflow_copy
63 def test_post_new_without_workflow_copy
64 post :new, :role => {:name => 'RoleWithoutWorkflowCopy',
64 post :new, :role => {:name => 'RoleWithoutWorkflowCopy',
65 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
65 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
66 :assignable => '0'}
66 :assignable => '0'}
67
67
68 assert_redirected_to 'roles/list'
68 assert_redirected_to 'roles/list'
69 role = Role.find_by_name('RoleWithoutWorkflowCopy')
69 role = Role.find_by_name('RoleWithoutWorkflowCopy')
70 assert_not_nil role
70 assert_not_nil role
71 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
71 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
72 assert !role.assignable?
72 assert !role.assignable?
73 end
73 end
74
74
75 def test_post_new_with_workflow_copy
75 def test_post_new_with_workflow_copy
76 post :new, :role => {:name => 'RoleWithWorkflowCopy',
76 post :new, :role => {:name => 'RoleWithWorkflowCopy',
77 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
77 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
78 :assignable => '0'},
78 :assignable => '0'},
79 :copy_workflow_from => '1'
79 :copy_workflow_from => '1'
80
80
81 assert_redirected_to 'roles/list'
81 assert_redirected_to 'roles/list'
82 role = Role.find_by_name('RoleWithWorkflowCopy')
82 role = Role.find_by_name('RoleWithWorkflowCopy')
83 assert_not_nil role
83 assert_not_nil role
84 assert_equal Role.find(1).workflows.size, role.workflows.size
84 assert_equal Role.find(1).workflows.size, role.workflows.size
85 end
85 end
86
86
87 def test_get_edit
87 def test_get_edit
88 get :edit, :id => 1
88 get :edit, :id => 1
89 assert_response :success
89 assert_response :success
90 assert_template 'edit'
90 assert_template 'edit'
91 assert_equal Role.find(1), assigns(:role)
91 assert_equal Role.find(1), assigns(:role)
92 end
92 end
93
93
94 def test_post_edit
94 def test_post_edit
95 post :edit, :id => 1,
95 post :edit, :id => 1,
96 :role => {:name => 'Manager',
96 :role => {:name => 'Manager',
97 :permissions => ['edit_project', ''],
97 :permissions => ['edit_project', ''],
98 :assignable => '0'}
98 :assignable => '0'}
99
99
100 assert_redirected_to 'roles/list'
100 assert_redirected_to 'roles/list'
101 role = Role.find(1)
101 role = Role.find(1)
102 assert_equal [:edit_project], role.permissions
102 assert_equal [:edit_project], role.permissions
103 end
103 end
104
104
105 def test_destroy
105 def test_destroy
106 r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
106 r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
107 assert r.save
107 assert r.save
108
108
109 post :destroy, :id => r
109 post :destroy, :id => r
110 assert_redirected_to 'roles/list'
110 assert_redirected_to 'roles/list'
111 assert_nil Role.find_by_id(r.id)
111 assert_nil Role.find_by_id(r.id)
112 end
112 end
113
113
114 def test_destroy_role_in_use
114 def test_destroy_role_in_use
115 post :destroy, :id => 1
115 post :destroy, :id => 1
116 assert_redirected_to 'roles'
116 assert_redirected_to 'roles'
117 assert flash[:error] == 'This role is in use and can not be deleted.'
117 assert flash[:error] == 'This role is in use and can not be deleted.'
118 assert_not_nil Role.find_by_id(1)
118 assert_not_nil Role.find_by_id(1)
119 end
119 end
120
120
121 def test_get_report
121 def test_get_report
122 get :report
122 get :report
123 assert_response :success
123 assert_response :success
124 assert_template 'report'
124 assert_template 'report'
125
125
126 assert_not_nil assigns(:roles)
126 assert_not_nil assigns(:roles)
127 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
127 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
128
128
129 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
129 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
130 :name => 'permissions[3][]',
130 :name => 'permissions[3][]',
131 :value => 'add_issues',
131 :value => 'add_issues',
132 :checked => 'checked' }
132 :checked => 'checked' }
133
133
134 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
134 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
135 :name => 'permissions[3][]',
135 :name => 'permissions[3][]',
136 :value => 'delete_issues',
136 :value => 'delete_issues',
137 :checked => nil }
137 :checked => nil }
138 end
138 end
139
139
140 def test_post_report
140 def test_post_report
141 post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
141 post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
142 assert_redirected_to 'roles/list'
142 assert_redirected_to 'roles/list'
143
143
144 assert_equal [:edit_issues], Role.find(1).permissions
144 assert_equal [:edit_issues], Role.find(1).permissions
145 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
145 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
146 assert Role.find(2).permissions.empty?
146 assert Role.find(2).permissions.empty?
147 end
147 end
148
148
149 def test_clear_all_permissions
149 def test_clear_all_permissions
150 post :report, :permissions => { '0' => '' }
150 post :report, :permissions => { '0' => '' }
151 assert_redirected_to 'roles/list'
151 assert_redirected_to 'roles/list'
152 assert Role.find(1).permissions.empty?
152 assert Role.find(1).permissions.empty?
153 end
153 end
154
154
155 def test_move_highest
155 def test_move_highest
156 post :move, :id => 3, :position => 'highest'
156 post :edit, :id => 3, :role => {:move_to => 'highest'}
157 assert_redirected_to 'roles/list'
157 assert_redirected_to 'roles/list'
158 assert_equal 1, Role.find(3).position
158 assert_equal 1, Role.find(3).position
159 end
159 end
160
160
161 def test_move_higher
161 def test_move_higher
162 position = Role.find(3).position
162 position = Role.find(3).position
163 post :move, :id => 3, :position => 'higher'
163 post :edit, :id => 3, :role => {:move_to => 'higher'}
164 assert_redirected_to 'roles/list'
164 assert_redirected_to 'roles/list'
165 assert_equal position - 1, Role.find(3).position
165 assert_equal position - 1, Role.find(3).position
166 end
166 end
167
167
168 def test_move_lower
168 def test_move_lower
169 position = Role.find(2).position
169 position = Role.find(2).position
170 post :move, :id => 2, :position => 'lower'
170 post :edit, :id => 2, :role => {:move_to => 'lower'}
171 assert_redirected_to 'roles/list'
171 assert_redirected_to 'roles/list'
172 assert_equal position + 1, Role.find(2).position
172 assert_equal position + 1, Role.find(2).position
173 end
173 end
174
174
175 def test_move_lowest
175 def test_move_lowest
176 post :move, :id => 2, :position => 'lowest'
176 post :edit, :id => 2, :role => {:move_to => 'lowest'}
177 assert_redirected_to 'roles/list'
177 assert_redirected_to 'roles/list'
178 assert_equal Role.count, Role.find(2).position
178 assert_equal Role.count, Role.find(2).position
179 end
179 end
180 end
180 end
General Comments 0
You need to be logged in to leave comments. Login now