@@ -1,278 +1,279 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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 'redmine/core_ext' |
|
18 | require 'redmine/core_ext' | |
19 |
|
19 | |||
20 | begin |
|
20 | begin | |
21 | require 'rmagick' unless Object.const_defined?(:Magick) |
|
21 | require 'rmagick' unless Object.const_defined?(:Magick) | |
22 | rescue LoadError |
|
22 | rescue LoadError | |
23 | # RMagick is not available |
|
23 | # RMagick is not available | |
24 | end |
|
24 | end | |
25 | begin |
|
25 | begin | |
26 | require 'redcarpet' unless Object.const_defined?(:Redcarpet) |
|
26 | require 'redcarpet' unless Object.const_defined?(:Redcarpet) | |
27 | rescue LoadError |
|
27 | rescue LoadError | |
28 | # Redcarpet is not available |
|
28 | # Redcarpet is not available | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | require 'redmine/scm/base' |
|
31 | require 'redmine/scm/base' | |
32 | require 'redmine/access_control' |
|
32 | require 'redmine/access_control' | |
33 | require 'redmine/access_keys' |
|
33 | require 'redmine/access_keys' | |
34 | require 'redmine/activity' |
|
34 | require 'redmine/activity' | |
35 | require 'redmine/activity/fetcher' |
|
35 | require 'redmine/activity/fetcher' | |
36 | require 'redmine/ciphering' |
|
36 | require 'redmine/ciphering' | |
37 | require 'redmine/codeset_util' |
|
37 | require 'redmine/codeset_util' | |
38 | require 'redmine/field_format' |
|
38 | require 'redmine/field_format' | |
39 | require 'redmine/i18n' |
|
39 | require 'redmine/i18n' | |
40 | require 'redmine/menu_manager' |
|
40 | require 'redmine/menu_manager' | |
41 | require 'redmine/notifiable' |
|
41 | require 'redmine/notifiable' | |
42 | require 'redmine/platform' |
|
42 | require 'redmine/platform' | |
43 | require 'redmine/mime_type' |
|
43 | require 'redmine/mime_type' | |
44 | require 'redmine/notifiable' |
|
44 | require 'redmine/notifiable' | |
45 | require 'redmine/search' |
|
45 | require 'redmine/search' | |
46 | require 'redmine/syntax_highlighting' |
|
46 | require 'redmine/syntax_highlighting' | |
47 | require 'redmine/thumbnail' |
|
47 | require 'redmine/thumbnail' | |
48 | require 'redmine/unified_diff' |
|
48 | require 'redmine/unified_diff' | |
49 | require 'redmine/utils' |
|
49 | require 'redmine/utils' | |
50 | require 'redmine/version' |
|
50 | require 'redmine/version' | |
51 | require 'redmine/wiki_formatting' |
|
51 | require 'redmine/wiki_formatting' | |
52 |
|
52 | |||
53 | require 'redmine/default_data/loader' |
|
53 | require 'redmine/default_data/loader' | |
54 | require 'redmine/helpers/calendar' |
|
54 | require 'redmine/helpers/calendar' | |
55 | require 'redmine/helpers/diff' |
|
55 | require 'redmine/helpers/diff' | |
56 | require 'redmine/helpers/gantt' |
|
56 | require 'redmine/helpers/gantt' | |
57 | require 'redmine/helpers/time_report' |
|
57 | require 'redmine/helpers/time_report' | |
58 | require 'redmine/views/other_formats_builder' |
|
58 | require 'redmine/views/other_formats_builder' | |
59 | require 'redmine/views/labelled_form_builder' |
|
59 | require 'redmine/views/labelled_form_builder' | |
60 | require 'redmine/views/builders' |
|
60 | require 'redmine/views/builders' | |
61 |
|
61 | |||
62 | require 'redmine/themes' |
|
62 | require 'redmine/themes' | |
63 | require 'redmine/hook' |
|
63 | require 'redmine/hook' | |
64 | require 'redmine/plugin' |
|
64 | require 'redmine/plugin' | |
65 |
|
65 | |||
66 | require 'csv' |
|
66 | require 'csv' | |
67 |
|
67 | |||
68 | Redmine::Scm::Base.add "Subversion" |
|
68 | Redmine::Scm::Base.add "Subversion" | |
69 | Redmine::Scm::Base.add "Darcs" |
|
69 | Redmine::Scm::Base.add "Darcs" | |
70 | Redmine::Scm::Base.add "Mercurial" |
|
70 | Redmine::Scm::Base.add "Mercurial" | |
71 | Redmine::Scm::Base.add "Cvs" |
|
71 | Redmine::Scm::Base.add "Cvs" | |
72 | Redmine::Scm::Base.add "Bazaar" |
|
72 | Redmine::Scm::Base.add "Bazaar" | |
73 | Redmine::Scm::Base.add "Git" |
|
73 | Redmine::Scm::Base.add "Git" | |
74 | Redmine::Scm::Base.add "Filesystem" |
|
74 | Redmine::Scm::Base.add "Filesystem" | |
75 |
|
75 | |||
76 | # Permissions |
|
76 | # Permissions | |
77 | Redmine::AccessControl.map do |map| |
|
77 | Redmine::AccessControl.map do |map| | |
78 | map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true, :read => true |
|
78 | map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true, :read => true | |
79 | map.permission :search_project, {:search => :index}, :public => true, :read => true |
|
79 | map.permission :search_project, {:search => :index}, :public => true, :read => true | |
80 | map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin |
|
80 | map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin | |
81 | map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member |
|
81 | map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member | |
82 | map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true |
|
82 | map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true | |
83 | map.permission :select_project_modules, {:projects => :modules}, :require => :member |
|
83 | map.permission :select_project_modules, {:projects => :modules}, :require => :member | |
84 | map.permission :view_members, {:members => [:index, :show]}, :public => true, :read => true |
|
84 | map.permission :view_members, {:members => [:index, :show]}, :public => true, :read => true | |
85 | map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :new, :create, :update, :destroy, :autocomplete]}, :require => :member |
|
85 | map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :new, :create, :update, :destroy, :autocomplete]}, :require => :member | |
86 | map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member |
|
86 | map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member | |
87 | map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member |
|
87 | map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member | |
88 |
|
88 | |||
89 | map.project_module :issue_tracking do |map| |
|
89 | map.project_module :issue_tracking do |map| | |
90 | # Issue categories |
|
90 | # Issue categories | |
91 | map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member |
|
91 | map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member | |
92 | # Issues |
|
92 | # Issues | |
93 | map.permission :view_issues, {:issues => [:index, :show], |
|
93 | map.permission :view_issues, {:issues => [:index, :show], | |
94 | :auto_complete => [:issues], |
|
94 | :auto_complete => [:issues], | |
95 | :context_menus => [:issues], |
|
95 | :context_menus => [:issues], | |
96 | :versions => [:index, :show, :status_by], |
|
96 | :versions => [:index, :show, :status_by], | |
97 | :journals => [:index, :diff], |
|
97 | :journals => [:index, :diff], | |
98 | :queries => :index, |
|
98 | :queries => :index, | |
99 | :reports => [:issue_report, :issue_report_details]}, |
|
99 | :reports => [:issue_report, :issue_report_details]}, | |
100 | :read => true |
|
100 | :read => true | |
101 | map.permission :add_issues, {:issues => [:new, :create], :attachments => :upload} |
|
101 | map.permission :add_issues, {:issues => [:new, :create], :attachments => :upload} | |
102 | map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new], :attachments => :upload} |
|
102 | map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new], :attachments => :upload} | |
103 | map.permission :copy_issues, {:issues => [:new, :create, :bulk_edit, :bulk_update], :attachments => :upload} |
|
103 | map.permission :copy_issues, {:issues => [:new, :create, :bulk_edit, :bulk_update], :attachments => :upload} | |
104 | map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]} |
|
104 | map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]} | |
105 | map.permission :manage_subtasks, {} |
|
105 | map.permission :manage_subtasks, {} | |
106 | map.permission :set_issues_private, {} |
|
106 | map.permission :set_issues_private, {} | |
107 | map.permission :set_own_issues_private, {}, :require => :loggedin |
|
107 | map.permission :set_own_issues_private, {}, :require => :loggedin | |
108 | map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload} |
|
108 | map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload} | |
109 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin |
|
109 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin | |
110 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin |
|
110 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin | |
111 | map.permission :view_private_notes, {}, :read => true, :require => :member |
|
111 | map.permission :view_private_notes, {}, :read => true, :require => :member | |
112 | map.permission :set_notes_private, {}, :require => :member |
|
112 | map.permission :set_notes_private, {}, :require => :member | |
113 | map.permission :delete_issues, {:issues => :destroy}, :require => :member |
|
113 | map.permission :delete_issues, {:issues => :destroy}, :require => :member | |
114 | # Queries |
|
114 | # Queries | |
115 | map.permission :manage_public_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :member |
|
115 | map.permission :manage_public_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :member | |
116 | map.permission :save_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin |
|
116 | map.permission :save_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin | |
117 | # Watchers |
|
117 | # Watchers | |
118 | map.permission :view_issue_watchers, {}, :read => true |
|
118 | map.permission :view_issue_watchers, {}, :read => true | |
119 | map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]} |
|
119 | map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]} | |
120 | map.permission :delete_issue_watchers, {:watchers => :destroy} |
|
120 | map.permission :delete_issue_watchers, {:watchers => :destroy} | |
121 | end |
|
121 | end | |
122 |
|
122 | |||
123 | map.project_module :time_tracking do |map| |
|
123 | map.project_module :time_tracking do |map| | |
124 | map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin |
|
124 | map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin | |
125 | map.permission :view_time_entries, {:timelog => [:index, :report, :show]}, :read => true |
|
125 | map.permission :view_time_entries, {:timelog => [:index, :report, :show]}, :read => true | |
126 | map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member |
|
126 | map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member | |
127 | map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin |
|
127 | map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin | |
128 | map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member |
|
128 | map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | map.project_module :news do |map| |
|
131 | map.project_module :news do |map| | |
132 | map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy], :attachments => :upload}, :require => :member |
|
132 | map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy], :attachments => :upload}, :require => :member | |
133 | map.permission :view_news, {:news => [:index, :show]}, :public => true, :read => true |
|
133 | map.permission :view_news, {:news => [:index, :show]}, :public => true, :read => true | |
134 | map.permission :comment_news, {:comments => :create} |
|
134 | map.permission :comment_news, {:comments => :create} | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | map.project_module :documents do |map| |
|
137 | map.project_module :documents do |map| | |
138 | map.permission :add_documents, {:documents => [:new, :create, :add_attachment], :attachments => :upload}, :require => :loggedin |
|
138 | map.permission :add_documents, {:documents => [:new, :create, :add_attachment], :attachments => :upload}, :require => :loggedin | |
139 | map.permission :edit_documents, {:documents => [:edit, :update, :add_attachment], :attachments => :upload}, :require => :loggedin |
|
139 | map.permission :edit_documents, {:documents => [:edit, :update, :add_attachment], :attachments => :upload}, :require => :loggedin | |
140 | map.permission :delete_documents, {:documents => [:destroy]}, :require => :loggedin |
|
140 | map.permission :delete_documents, {:documents => [:destroy]}, :require => :loggedin | |
141 | map.permission :view_documents, {:documents => [:index, :show, :download]}, :read => true |
|
141 | map.permission :view_documents, {:documents => [:index, :show, :download]}, :read => true | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | map.project_module :files do |map| |
|
144 | map.project_module :files do |map| | |
145 | map.permission :manage_files, {:files => [:new, :create], :attachments => :upload}, :require => :loggedin |
|
145 | map.permission :manage_files, {:files => [:new, :create], :attachments => :upload}, :require => :loggedin | |
146 | map.permission :view_files, {:files => :index, :versions => :download}, :read => true |
|
146 | map.permission :view_files, {:files => :index, :versions => :download}, :read => true | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | map.project_module :wiki do |map| |
|
149 | map.project_module :wiki do |map| | |
150 | map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member |
|
150 | map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member | |
151 | map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member |
|
151 | map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member | |
152 | map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member |
|
152 | map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member | |
153 | map.permission :view_wiki_pages, {:wiki => [:index, :show, :special, :date_index]}, :read => true |
|
153 | map.permission :view_wiki_pages, {:wiki => [:index, :show, :special, :date_index]}, :read => true | |
154 | map.permission :export_wiki_pages, {:wiki => [:export]}, :read => true |
|
154 | map.permission :export_wiki_pages, {:wiki => [:export]}, :read => true | |
155 | map.permission :view_wiki_edits, {:wiki => [:history, :diff, :annotate]}, :read => true |
|
155 | map.permission :view_wiki_edits, {:wiki => [:history, :diff, :annotate]}, :read => true | |
156 | map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment], :attachments => :upload |
|
156 | map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment], :attachments => :upload | |
157 | map.permission :delete_wiki_pages_attachments, {} |
|
157 | map.permission :delete_wiki_pages_attachments, {} | |
158 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member |
|
158 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member | |
159 | end |
|
159 | end | |
160 |
|
160 | |||
161 | map.project_module :repository do |map| |
|
161 | map.project_module :repository do |map| | |
162 | map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member |
|
162 | map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member | |
163 | map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]}, :read => true |
|
163 | map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]}, :read => true | |
164 | map.permission :view_changesets, {:repositories => [:show, :revisions, :revision]}, :read => true |
|
164 | map.permission :view_changesets, {:repositories => [:show, :revisions, :revision]}, :read => true | |
165 | map.permission :commit_access, {} |
|
165 | map.permission :commit_access, {} | |
166 | map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]} |
|
166 | map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]} | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | map.project_module :boards do |map| |
|
169 | map.project_module :boards do |map| | |
170 | map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member |
|
170 | map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member | |
171 | map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true, :read => true |
|
171 | map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true, :read => true | |
172 | map.permission :add_messages, {:messages => [:new, :reply, :quote], :attachments => :upload} |
|
172 | map.permission :add_messages, {:messages => [:new, :reply, :quote], :attachments => :upload} | |
173 | map.permission :edit_messages, {:messages => :edit, :attachments => :upload}, :require => :member |
|
173 | map.permission :edit_messages, {:messages => :edit, :attachments => :upload}, :require => :member | |
174 | map.permission :edit_own_messages, {:messages => :edit, :attachments => :upload}, :require => :loggedin |
|
174 | map.permission :edit_own_messages, {:messages => :edit, :attachments => :upload}, :require => :loggedin | |
175 | map.permission :delete_messages, {:messages => :destroy}, :require => :member |
|
175 | map.permission :delete_messages, {:messages => :destroy}, :require => :member | |
176 | map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin |
|
176 | map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | map.project_module :calendar do |map| |
|
179 | map.project_module :calendar do |map| | |
180 | map.permission :view_calendar, {:calendars => [:show, :update]}, :read => true |
|
180 | map.permission :view_calendar, {:calendars => [:show, :update]}, :read => true | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | map.project_module :gantt do |map| |
|
183 | map.project_module :gantt do |map| | |
184 | map.permission :view_gantt, {:gantts => [:show, :update]}, :read => true |
|
184 | map.permission :view_gantt, {:gantts => [:show, :update]}, :read => true | |
185 | end |
|
185 | end | |
186 | end |
|
186 | end | |
187 |
|
187 | |||
188 | Redmine::MenuManager.map :top_menu do |menu| |
|
188 | Redmine::MenuManager.map :top_menu do |menu| | |
189 | menu.push :home, :home_path |
|
189 | menu.push :home, :home_path | |
190 | menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? } |
|
190 | menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? } | |
191 | menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural |
|
191 | menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural | |
192 | menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true |
|
192 | menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true | |
193 | menu.push :help, Redmine::Info.help_url, :last => true |
|
193 | menu.push :help, Redmine::Info.help_url, :last => true | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | Redmine::MenuManager.map :account_menu do |menu| |
|
196 | Redmine::MenuManager.map :account_menu do |menu| | |
197 | menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? } |
|
197 | menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? } | |
198 | menu.push :register, :register_path, :if => Proc.new { !User.current.logged? && Setting.self_registration? } |
|
198 | menu.push :register, :register_path, :if => Proc.new { !User.current.logged? && Setting.self_registration? } | |
199 | menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? } |
|
199 | menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? } | |
200 | menu.push :logout, :signout_path, :html => {:method => 'post'}, :if => Proc.new { User.current.logged? } |
|
200 | menu.push :logout, :signout_path, :html => {:method => 'post'}, :if => Proc.new { User.current.logged? } | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | Redmine::MenuManager.map :application_menu do |menu| |
|
203 | Redmine::MenuManager.map :application_menu do |menu| | |
204 | # Empty |
|
204 | # Empty | |
205 | end |
|
205 | end | |
206 |
|
206 | |||
207 | Redmine::MenuManager.map :admin_menu do |menu| |
|
207 | Redmine::MenuManager.map :admin_menu do |menu| | |
208 | menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural |
|
208 | menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural | |
209 | menu.push :users, {:controller => 'users'}, :caption => :label_user_plural |
|
209 | menu.push :users, {:controller => 'users'}, :caption => :label_user_plural | |
210 | menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural |
|
210 | menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural | |
211 | menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions |
|
211 | menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions | |
212 | menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural |
|
212 | menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural | |
213 | menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural, |
|
213 | menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural, | |
214 | :html => {:class => 'issue_statuses'} |
|
214 | :html => {:class => 'issue_statuses'} | |
215 | menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow |
|
215 | menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow | |
216 | menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural, |
|
216 | menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural, | |
217 | :html => {:class => 'custom_fields'} |
|
217 | :html => {:class => 'custom_fields'} | |
218 | menu.push :enumerations, {:controller => 'enumerations'} |
|
218 | menu.push :enumerations, {:controller => 'enumerations'} | |
219 | menu.push :settings, {:controller => 'settings'} |
|
219 | menu.push :settings, {:controller => 'settings'} | |
220 | menu.push :ldap_authentication, {:controller => 'auth_sources', :action => 'index'}, |
|
220 | menu.push :ldap_authentication, {:controller => 'auth_sources', :action => 'index'}, | |
221 | :html => {:class => 'server_authentication'} |
|
221 | :html => {:class => 'server_authentication'} | |
222 | menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true |
|
222 | menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true | |
223 | menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true |
|
223 | menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | Redmine::MenuManager.map :project_menu do |menu| |
|
226 | Redmine::MenuManager.map :project_menu do |menu| | |
227 | menu.push :overview, { :controller => 'projects', :action => 'show' } |
|
227 | menu.push :overview, { :controller => 'projects', :action => 'show' } | |
228 | menu.push :activity, { :controller => 'activities', :action => 'index' } |
|
228 | menu.push :activity, { :controller => 'activities', :action => 'index' } | |
229 | menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id, |
|
229 | menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id, | |
230 | :if => Proc.new { |p| p.shared_versions.any? } |
|
230 | :if => Proc.new { |p| p.shared_versions.any? } | |
231 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural |
|
231 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural | |
232 | menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new, |
|
232 | menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new, | |
233 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }, |
|
233 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }, | |
234 | :if => Proc.new { |p| p.trackers.any? } |
|
234 | :if => Proc.new { |p| p.trackers.any? }, | |
|
235 | :permission => :add_issues | |||
235 | menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt |
|
236 | menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt | |
236 | menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar |
|
237 | menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar | |
237 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural |
|
238 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural | |
238 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural |
|
239 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural | |
239 | menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id, |
|
240 | menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id, | |
240 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } |
|
241 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } | |
241 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, |
|
242 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, | |
242 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural |
|
243 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural | |
243 | menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id |
|
244 | menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id | |
244 | menu.push :repository, { :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil }, |
|
245 | menu.push :repository, { :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil }, | |
245 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } |
|
246 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } | |
246 | menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true |
|
247 | menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true | |
247 | end |
|
248 | end | |
248 |
|
249 | |||
249 | Redmine::Activity.map do |activity| |
|
250 | Redmine::Activity.map do |activity| | |
250 | activity.register :issues, :class_name => %w(Issue Journal) |
|
251 | activity.register :issues, :class_name => %w(Issue Journal) | |
251 | activity.register :changesets |
|
252 | activity.register :changesets | |
252 | activity.register :news |
|
253 | activity.register :news | |
253 | activity.register :documents, :class_name => %w(Document Attachment) |
|
254 | activity.register :documents, :class_name => %w(Document Attachment) | |
254 | activity.register :files, :class_name => 'Attachment' |
|
255 | activity.register :files, :class_name => 'Attachment' | |
255 | activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false |
|
256 | activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false | |
256 | activity.register :messages, :default => false |
|
257 | activity.register :messages, :default => false | |
257 | activity.register :time_entries, :default => false |
|
258 | activity.register :time_entries, :default => false | |
258 | end |
|
259 | end | |
259 |
|
260 | |||
260 | Redmine::Search.map do |search| |
|
261 | Redmine::Search.map do |search| | |
261 | search.register :issues |
|
262 | search.register :issues | |
262 | search.register :news |
|
263 | search.register :news | |
263 | search.register :documents |
|
264 | search.register :documents | |
264 | search.register :changesets |
|
265 | search.register :changesets | |
265 | search.register :wiki_pages |
|
266 | search.register :wiki_pages | |
266 | search.register :messages |
|
267 | search.register :messages | |
267 | search.register :projects |
|
268 | search.register :projects | |
268 | end |
|
269 | end | |
269 |
|
270 | |||
270 | Redmine::WikiFormatting.map do |format| |
|
271 | Redmine::WikiFormatting.map do |format| | |
271 | format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper |
|
272 | format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper | |
272 | if Object.const_defined?(:Redcarpet) |
|
273 | if Object.const_defined?(:Redcarpet) | |
273 | format.register :markdown, Redmine::WikiFormatting::Markdown::Formatter, Redmine::WikiFormatting::Markdown::Helper, |
|
274 | format.register :markdown, Redmine::WikiFormatting::Markdown::Formatter, Redmine::WikiFormatting::Markdown::Helper, | |
274 | :label => 'Markdown' |
|
275 | :label => 'Markdown' | |
275 | end |
|
276 | end | |
276 | end |
|
277 | end | |
277 |
|
278 | |||
278 | ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler |
|
279 | ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler |
@@ -1,674 +1,684 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class ProjectsControllerTest < ActionController::TestCase |
|
20 | class ProjectsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :versions, :users, :email_addresses, :roles, :members, |
|
21 | fixtures :projects, :versions, :users, :email_addresses, :roles, :members, | |
22 | :member_roles, :issues, :journals, :journal_details, |
|
22 | :member_roles, :issues, :journals, :journal_details, | |
23 | :trackers, :projects_trackers, :issue_statuses, |
|
23 | :trackers, :projects_trackers, :issue_statuses, | |
24 | :enabled_modules, :enumerations, :boards, :messages, |
|
24 | :enabled_modules, :enumerations, :boards, :messages, | |
25 | :attachments, :custom_fields, :custom_values, :time_entries, |
|
25 | :attachments, :custom_fields, :custom_values, :time_entries, | |
26 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions |
|
26 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions | |
27 |
|
27 | |||
28 | def setup |
|
28 | def setup | |
29 | @request.session[:user_id] = nil |
|
29 | @request.session[:user_id] = nil | |
30 | Setting.default_language = 'en' |
|
30 | Setting.default_language = 'en' | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_index_by_anonymous_should_not_show_private_projects |
|
33 | def test_index_by_anonymous_should_not_show_private_projects | |
34 | get :index |
|
34 | get :index | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'index' |
|
36 | assert_template 'index' | |
37 | projects = assigns(:projects) |
|
37 | projects = assigns(:projects) | |
38 | assert_not_nil projects |
|
38 | assert_not_nil projects | |
39 | assert projects.all?(&:is_public?) |
|
39 | assert projects.all?(&:is_public?) | |
40 |
|
40 | |||
41 | assert_select 'ul' do |
|
41 | assert_select 'ul' do | |
42 | assert_select 'li' do |
|
42 | assert_select 'li' do | |
43 | assert_select 'a', :text => 'eCookbook' |
|
43 | assert_select 'a', :text => 'eCookbook' | |
44 | assert_select 'ul' do |
|
44 | assert_select 'ul' do | |
45 | assert_select 'a', :text => 'Child of private child' |
|
45 | assert_select 'a', :text => 'Child of private child' | |
46 | end |
|
46 | end | |
47 | end |
|
47 | end | |
48 | end |
|
48 | end | |
49 | assert_select 'a', :text => /Private child of eCookbook/, :count => 0 |
|
49 | assert_select 'a', :text => /Private child of eCookbook/, :count => 0 | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_index_atom |
|
52 | def test_index_atom | |
53 | get :index, :format => 'atom' |
|
53 | get :index, :format => 'atom' | |
54 | assert_response :success |
|
54 | assert_response :success | |
55 | assert_template 'common/feed' |
|
55 | assert_template 'common/feed' | |
56 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
56 | assert_select 'feed>title', :text => 'Redmine: Latest projects' | |
57 | assert_select 'feed>entry', :count => Project.visible(User.current).count |
|
57 | assert_select 'feed>entry', :count => Project.visible(User.current).count | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | test "#index by non-admin user with view_time_entries permission should show overall spent time link" do |
|
60 | test "#index by non-admin user with view_time_entries permission should show overall spent time link" do | |
61 | @request.session[:user_id] = 3 |
|
61 | @request.session[:user_id] = 3 | |
62 | get :index |
|
62 | get :index | |
63 | assert_template 'index' |
|
63 | assert_template 'index' | |
64 | assert_select 'a[href=?]', '/time_entries' |
|
64 | assert_select 'a[href=?]', '/time_entries' | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do |
|
67 | test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do | |
68 | Role.find(2).remove_permission! :view_time_entries |
|
68 | Role.find(2).remove_permission! :view_time_entries | |
69 | Role.non_member.remove_permission! :view_time_entries |
|
69 | Role.non_member.remove_permission! :view_time_entries | |
70 | Role.anonymous.remove_permission! :view_time_entries |
|
70 | Role.anonymous.remove_permission! :view_time_entries | |
71 | @request.session[:user_id] = 3 |
|
71 | @request.session[:user_id] = 3 | |
72 |
|
72 | |||
73 | get :index |
|
73 | get :index | |
74 | assert_template 'index' |
|
74 | assert_template 'index' | |
75 | assert_select 'a[href=?]', '/time_entries', 0 |
|
75 | assert_select 'a[href=?]', '/time_entries', 0 | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | test "#index by non-admin user with permission should show add project link" do |
|
78 | test "#index by non-admin user with permission should show add project link" do | |
79 | Role.find(1).add_permission! :add_project |
|
79 | Role.find(1).add_permission! :add_project | |
80 | @request.session[:user_id] = 2 |
|
80 | @request.session[:user_id] = 2 | |
81 | get :index |
|
81 | get :index | |
82 | assert_template 'index' |
|
82 | assert_template 'index' | |
83 | assert_select 'a[href=?]', '/projects/new' |
|
83 | assert_select 'a[href=?]', '/projects/new' | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | test "#new by admin user should accept get" do |
|
86 | test "#new by admin user should accept get" do | |
87 | @request.session[:user_id] = 1 |
|
87 | @request.session[:user_id] = 1 | |
88 |
|
88 | |||
89 | get :new |
|
89 | get :new | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'new' |
|
91 | assert_template 'new' | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | test "#new by non-admin user with add_project permission should accept get" do |
|
94 | test "#new by non-admin user with add_project permission should accept get" do | |
95 | Role.non_member.add_permission! :add_project |
|
95 | Role.non_member.add_permission! :add_project | |
96 | @request.session[:user_id] = 9 |
|
96 | @request.session[:user_id] = 9 | |
97 |
|
97 | |||
98 | get :new |
|
98 | get :new | |
99 | assert_response :success |
|
99 | assert_response :success | |
100 | assert_template 'new' |
|
100 | assert_template 'new' | |
101 | assert_select 'select[name=?]', 'project[parent_id]', 0 |
|
101 | assert_select 'select[name=?]', 'project[parent_id]', 0 | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | test "#new by non-admin user with add_subprojects permission should accept get" do |
|
104 | test "#new by non-admin user with add_subprojects permission should accept get" do | |
105 | Role.find(1).remove_permission! :add_project |
|
105 | Role.find(1).remove_permission! :add_project | |
106 | Role.find(1).add_permission! :add_subprojects |
|
106 | Role.find(1).add_permission! :add_subprojects | |
107 | @request.session[:user_id] = 2 |
|
107 | @request.session[:user_id] = 2 | |
108 |
|
108 | |||
109 | get :new, :parent_id => 'ecookbook' |
|
109 | get :new, :parent_id => 'ecookbook' | |
110 | assert_response :success |
|
110 | assert_response :success | |
111 | assert_template 'new' |
|
111 | assert_template 'new' | |
112 |
|
112 | |||
113 | assert_select 'select[name=?]', 'project[parent_id]' do |
|
113 | assert_select 'select[name=?]', 'project[parent_id]' do | |
114 | # parent project selected |
|
114 | # parent project selected | |
115 | assert_select 'option[value="1"][selected=selected]' |
|
115 | assert_select 'option[value="1"][selected=selected]' | |
116 | # no empty value |
|
116 | # no empty value | |
117 | assert_select 'option[value=""]', 0 |
|
117 | assert_select 'option[value=""]', 0 | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | test "#create by admin user should create a new project" do |
|
121 | test "#create by admin user should create a new project" do | |
122 | @request.session[:user_id] = 1 |
|
122 | @request.session[:user_id] = 1 | |
123 |
|
123 | |||
124 | post :create, |
|
124 | post :create, | |
125 | :project => { |
|
125 | :project => { | |
126 | :name => "blog", |
|
126 | :name => "blog", | |
127 | :description => "weblog", |
|
127 | :description => "weblog", | |
128 | :homepage => 'http://weblog', |
|
128 | :homepage => 'http://weblog', | |
129 | :identifier => "blog", |
|
129 | :identifier => "blog", | |
130 | :is_public => 1, |
|
130 | :is_public => 1, | |
131 | :custom_field_values => { '3' => 'Beta' }, |
|
131 | :custom_field_values => { '3' => 'Beta' }, | |
132 | :tracker_ids => ['1', '3'], |
|
132 | :tracker_ids => ['1', '3'], | |
133 | # an issue custom field that is not for all project |
|
133 | # an issue custom field that is not for all project | |
134 | :issue_custom_field_ids => ['9'], |
|
134 | :issue_custom_field_ids => ['9'], | |
135 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
135 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |
136 | } |
|
136 | } | |
137 | assert_redirected_to '/projects/blog/settings' |
|
137 | assert_redirected_to '/projects/blog/settings' | |
138 |
|
138 | |||
139 | project = Project.find_by_name('blog') |
|
139 | project = Project.find_by_name('blog') | |
140 | assert_kind_of Project, project |
|
140 | assert_kind_of Project, project | |
141 | assert project.active? |
|
141 | assert project.active? | |
142 | assert_equal 'weblog', project.description |
|
142 | assert_equal 'weblog', project.description | |
143 | assert_equal 'http://weblog', project.homepage |
|
143 | assert_equal 'http://weblog', project.homepage | |
144 | assert_equal true, project.is_public? |
|
144 | assert_equal true, project.is_public? | |
145 | assert_nil project.parent |
|
145 | assert_nil project.parent | |
146 | assert_equal 'Beta', project.custom_value_for(3).value |
|
146 | assert_equal 'Beta', project.custom_value_for(3).value | |
147 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
147 | assert_equal [1, 3], project.trackers.map(&:id).sort | |
148 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
148 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |
149 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
|
149 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | test "#create by admin user should create a new subproject" do |
|
152 | test "#create by admin user should create a new subproject" do | |
153 | @request.session[:user_id] = 1 |
|
153 | @request.session[:user_id] = 1 | |
154 |
|
154 | |||
155 | assert_difference 'Project.count' do |
|
155 | assert_difference 'Project.count' do | |
156 | post :create, :project => { :name => "blog", |
|
156 | post :create, :project => { :name => "blog", | |
157 | :description => "weblog", |
|
157 | :description => "weblog", | |
158 | :identifier => "blog", |
|
158 | :identifier => "blog", | |
159 | :is_public => 1, |
|
159 | :is_public => 1, | |
160 | :custom_field_values => { '3' => 'Beta' }, |
|
160 | :custom_field_values => { '3' => 'Beta' }, | |
161 | :parent_id => 1 |
|
161 | :parent_id => 1 | |
162 | } |
|
162 | } | |
163 | assert_redirected_to '/projects/blog/settings' |
|
163 | assert_redirected_to '/projects/blog/settings' | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | project = Project.find_by_name('blog') |
|
166 | project = Project.find_by_name('blog') | |
167 | assert_kind_of Project, project |
|
167 | assert_kind_of Project, project | |
168 | assert_equal Project.find(1), project.parent |
|
168 | assert_equal Project.find(1), project.parent | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | test "#create by admin user should continue" do |
|
171 | test "#create by admin user should continue" do | |
172 | @request.session[:user_id] = 1 |
|
172 | @request.session[:user_id] = 1 | |
173 |
|
173 | |||
174 | assert_difference 'Project.count' do |
|
174 | assert_difference 'Project.count' do | |
175 | post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' |
|
175 | post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' | |
176 | end |
|
176 | end | |
177 | assert_redirected_to '/projects/new' |
|
177 | assert_redirected_to '/projects/new' | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | test "#create by non-admin user with add_project permission should create a new project" do |
|
180 | test "#create by non-admin user with add_project permission should create a new project" do | |
181 | Role.non_member.add_permission! :add_project |
|
181 | Role.non_member.add_permission! :add_project | |
182 | @request.session[:user_id] = 9 |
|
182 | @request.session[:user_id] = 9 | |
183 |
|
183 | |||
184 | post :create, :project => { :name => "blog", |
|
184 | post :create, :project => { :name => "blog", | |
185 | :description => "weblog", |
|
185 | :description => "weblog", | |
186 | :identifier => "blog", |
|
186 | :identifier => "blog", | |
187 | :is_public => 1, |
|
187 | :is_public => 1, | |
188 | :custom_field_values => { '3' => 'Beta' }, |
|
188 | :custom_field_values => { '3' => 'Beta' }, | |
189 | :tracker_ids => ['1', '3'], |
|
189 | :tracker_ids => ['1', '3'], | |
190 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
190 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | assert_redirected_to '/projects/blog/settings' |
|
193 | assert_redirected_to '/projects/blog/settings' | |
194 |
|
194 | |||
195 | project = Project.find_by_name('blog') |
|
195 | project = Project.find_by_name('blog') | |
196 | assert_kind_of Project, project |
|
196 | assert_kind_of Project, project | |
197 | assert_equal 'weblog', project.description |
|
197 | assert_equal 'weblog', project.description | |
198 | assert_equal true, project.is_public? |
|
198 | assert_equal true, project.is_public? | |
199 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
199 | assert_equal [1, 3], project.trackers.map(&:id).sort | |
200 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
200 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |
201 |
|
201 | |||
202 | # User should be added as a project member |
|
202 | # User should be added as a project member | |
203 | assert User.find(9).member_of?(project) |
|
203 | assert User.find(9).member_of?(project) | |
204 | assert_equal 1, project.members.size |
|
204 | assert_equal 1, project.members.size | |
205 | end |
|
205 | end | |
206 |
|
206 | |||
207 | test "#create by non-admin user with add_project permission should fail with parent_id" do |
|
207 | test "#create by non-admin user with add_project permission should fail with parent_id" do | |
208 | Role.non_member.add_permission! :add_project |
|
208 | Role.non_member.add_permission! :add_project | |
209 | @request.session[:user_id] = 9 |
|
209 | @request.session[:user_id] = 9 | |
210 |
|
210 | |||
211 | assert_no_difference 'Project.count' do |
|
211 | assert_no_difference 'Project.count' do | |
212 | post :create, :project => { :name => "blog", |
|
212 | post :create, :project => { :name => "blog", | |
213 | :description => "weblog", |
|
213 | :description => "weblog", | |
214 | :identifier => "blog", |
|
214 | :identifier => "blog", | |
215 | :is_public => 1, |
|
215 | :is_public => 1, | |
216 | :custom_field_values => { '3' => 'Beta' }, |
|
216 | :custom_field_values => { '3' => 'Beta' }, | |
217 | :parent_id => 1 |
|
217 | :parent_id => 1 | |
218 | } |
|
218 | } | |
219 | end |
|
219 | end | |
220 | assert_response :success |
|
220 | assert_response :success | |
221 | project = assigns(:project) |
|
221 | project = assigns(:project) | |
222 | assert_kind_of Project, project |
|
222 | assert_kind_of Project, project | |
223 | assert_not_equal [], project.errors[:parent_id] |
|
223 | assert_not_equal [], project.errors[:parent_id] | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do |
|
226 | test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do | |
227 | Role.find(1).remove_permission! :add_project |
|
227 | Role.find(1).remove_permission! :add_project | |
228 | Role.find(1).add_permission! :add_subprojects |
|
228 | Role.find(1).add_permission! :add_subprojects | |
229 | @request.session[:user_id] = 2 |
|
229 | @request.session[:user_id] = 2 | |
230 |
|
230 | |||
231 | post :create, :project => { :name => "blog", |
|
231 | post :create, :project => { :name => "blog", | |
232 | :description => "weblog", |
|
232 | :description => "weblog", | |
233 | :identifier => "blog", |
|
233 | :identifier => "blog", | |
234 | :is_public => 1, |
|
234 | :is_public => 1, | |
235 | :custom_field_values => { '3' => 'Beta' }, |
|
235 | :custom_field_values => { '3' => 'Beta' }, | |
236 | :parent_id => 1 |
|
236 | :parent_id => 1 | |
237 | } |
|
237 | } | |
238 | assert_redirected_to '/projects/blog/settings' |
|
238 | assert_redirected_to '/projects/blog/settings' | |
239 | project = Project.find_by_name('blog') |
|
239 | project = Project.find_by_name('blog') | |
240 | end |
|
240 | end | |
241 |
|
241 | |||
242 | test "#create by non-admin user with add_subprojects permission should fail without parent_id" do |
|
242 | test "#create by non-admin user with add_subprojects permission should fail without parent_id" do | |
243 | Role.find(1).remove_permission! :add_project |
|
243 | Role.find(1).remove_permission! :add_project | |
244 | Role.find(1).add_permission! :add_subprojects |
|
244 | Role.find(1).add_permission! :add_subprojects | |
245 | @request.session[:user_id] = 2 |
|
245 | @request.session[:user_id] = 2 | |
246 |
|
246 | |||
247 | assert_no_difference 'Project.count' do |
|
247 | assert_no_difference 'Project.count' do | |
248 | post :create, :project => { :name => "blog", |
|
248 | post :create, :project => { :name => "blog", | |
249 | :description => "weblog", |
|
249 | :description => "weblog", | |
250 | :identifier => "blog", |
|
250 | :identifier => "blog", | |
251 | :is_public => 1, |
|
251 | :is_public => 1, | |
252 | :custom_field_values => { '3' => 'Beta' } |
|
252 | :custom_field_values => { '3' => 'Beta' } | |
253 | } |
|
253 | } | |
254 | end |
|
254 | end | |
255 | assert_response :success |
|
255 | assert_response :success | |
256 | project = assigns(:project) |
|
256 | project = assigns(:project) | |
257 | assert_kind_of Project, project |
|
257 | assert_kind_of Project, project | |
258 | assert_not_equal [], project.errors[:parent_id] |
|
258 | assert_not_equal [], project.errors[:parent_id] | |
259 | end |
|
259 | end | |
260 |
|
260 | |||
261 | test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do |
|
261 | test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do | |
262 | Role.find(1).remove_permission! :add_project |
|
262 | Role.find(1).remove_permission! :add_project | |
263 | Role.find(1).add_permission! :add_subprojects |
|
263 | Role.find(1).add_permission! :add_subprojects | |
264 | @request.session[:user_id] = 2 |
|
264 | @request.session[:user_id] = 2 | |
265 |
|
265 | |||
266 | assert !User.find(2).member_of?(Project.find(6)) |
|
266 | assert !User.find(2).member_of?(Project.find(6)) | |
267 | assert_no_difference 'Project.count' do |
|
267 | assert_no_difference 'Project.count' do | |
268 | post :create, :project => { :name => "blog", |
|
268 | post :create, :project => { :name => "blog", | |
269 | :description => "weblog", |
|
269 | :description => "weblog", | |
270 | :identifier => "blog", |
|
270 | :identifier => "blog", | |
271 | :is_public => 1, |
|
271 | :is_public => 1, | |
272 | :custom_field_values => { '3' => 'Beta' }, |
|
272 | :custom_field_values => { '3' => 'Beta' }, | |
273 | :parent_id => 6 |
|
273 | :parent_id => 6 | |
274 | } |
|
274 | } | |
275 | end |
|
275 | end | |
276 | assert_response :success |
|
276 | assert_response :success | |
277 | project = assigns(:project) |
|
277 | project = assigns(:project) | |
278 | assert_kind_of Project, project |
|
278 | assert_kind_of Project, project | |
279 | assert_not_equal [], project.errors[:parent_id] |
|
279 | assert_not_equal [], project.errors[:parent_id] | |
280 | end |
|
280 | end | |
281 |
|
281 | |||
282 | def test_create_subproject_with_inherit_members_should_inherit_members |
|
282 | def test_create_subproject_with_inherit_members_should_inherit_members | |
283 | Role.find_by_name('Manager').add_permission! :add_subprojects |
|
283 | Role.find_by_name('Manager').add_permission! :add_subprojects | |
284 | parent = Project.find(1) |
|
284 | parent = Project.find(1) | |
285 | @request.session[:user_id] = 2 |
|
285 | @request.session[:user_id] = 2 | |
286 |
|
286 | |||
287 | assert_difference 'Project.count' do |
|
287 | assert_difference 'Project.count' do | |
288 | post :create, :project => { |
|
288 | post :create, :project => { | |
289 | :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' |
|
289 | :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' | |
290 | } |
|
290 | } | |
291 | assert_response 302 |
|
291 | assert_response 302 | |
292 | end |
|
292 | end | |
293 |
|
293 | |||
294 | project = Project.order('id desc').first |
|
294 | project = Project.order('id desc').first | |
295 | assert_equal 'inherited', project.name |
|
295 | assert_equal 'inherited', project.name | |
296 | assert_equal parent, project.parent |
|
296 | assert_equal parent, project.parent | |
297 | assert project.memberships.count > 0 |
|
297 | assert project.memberships.count > 0 | |
298 | assert_equal parent.memberships.count, project.memberships.count |
|
298 | assert_equal parent.memberships.count, project.memberships.count | |
299 | end |
|
299 | end | |
300 |
|
300 | |||
301 | def test_create_should_preserve_modules_on_validation_failure |
|
301 | def test_create_should_preserve_modules_on_validation_failure | |
302 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
302 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
303 | @request.session[:user_id] = 1 |
|
303 | @request.session[:user_id] = 1 | |
304 | assert_no_difference 'Project.count' do |
|
304 | assert_no_difference 'Project.count' do | |
305 | post :create, :project => { |
|
305 | post :create, :project => { | |
306 | :name => "blog", |
|
306 | :name => "blog", | |
307 | :identifier => "", |
|
307 | :identifier => "", | |
308 | :enabled_module_names => %w(issue_tracking news) |
|
308 | :enabled_module_names => %w(issue_tracking news) | |
309 | } |
|
309 | } | |
310 | end |
|
310 | end | |
311 | assert_response :success |
|
311 | assert_response :success | |
312 | project = assigns(:project) |
|
312 | project = assigns(:project) | |
313 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
313 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort | |
314 | end |
|
314 | end | |
315 | end |
|
315 | end | |
316 |
|
316 | |||
317 | def test_show_by_id |
|
317 | def test_show_by_id | |
318 | get :show, :id => 1 |
|
318 | get :show, :id => 1 | |
319 | assert_response :success |
|
319 | assert_response :success | |
320 | assert_template 'show' |
|
320 | assert_template 'show' | |
321 | assert_not_nil assigns(:project) |
|
321 | assert_not_nil assigns(:project) | |
322 | end |
|
322 | end | |
323 |
|
323 | |||
324 | def test_show_by_identifier |
|
324 | def test_show_by_identifier | |
325 | get :show, :id => 'ecookbook' |
|
325 | get :show, :id => 'ecookbook' | |
326 | assert_response :success |
|
326 | assert_response :success | |
327 | assert_template 'show' |
|
327 | assert_template 'show' | |
328 | assert_not_nil assigns(:project) |
|
328 | assert_not_nil assigns(:project) | |
329 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
329 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
330 |
|
330 | |||
331 | assert_select 'li', :text => /Development status/ |
|
331 | assert_select 'li', :text => /Development status/ | |
332 | end |
|
332 | end | |
333 |
|
333 | |||
334 | def test_show_should_not_display_empty_sidebar |
|
334 | def test_show_should_not_display_empty_sidebar | |
335 | p = Project.find(1) |
|
335 | p = Project.find(1) | |
336 | p.enabled_module_names = [] |
|
336 | p.enabled_module_names = [] | |
337 | p.save! |
|
337 | p.save! | |
338 |
|
338 | |||
339 | get :show, :id => 'ecookbook' |
|
339 | get :show, :id => 'ecookbook' | |
340 | assert_response :success |
|
340 | assert_response :success | |
341 | assert_select '#main.nosidebar' |
|
341 | assert_select '#main.nosidebar' | |
342 | end |
|
342 | end | |
343 |
|
343 | |||
344 | def test_show_should_not_display_hidden_custom_fields |
|
344 | def test_show_should_not_display_hidden_custom_fields | |
345 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false |
|
345 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false | |
346 | get :show, :id => 'ecookbook' |
|
346 | get :show, :id => 'ecookbook' | |
347 | assert_response :success |
|
347 | assert_response :success | |
348 | assert_template 'show' |
|
348 | assert_template 'show' | |
349 | assert_not_nil assigns(:project) |
|
349 | assert_not_nil assigns(:project) | |
350 |
|
350 | |||
351 | assert_select 'li', :text => /Development status/, :count => 0 |
|
351 | assert_select 'li', :text => /Development status/, :count => 0 | |
352 | end |
|
352 | end | |
353 |
|
353 | |||
354 | def test_show_should_not_display_blank_custom_fields_with_multiple_values |
|
354 | def test_show_should_not_display_blank_custom_fields_with_multiple_values | |
355 | f1 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Foo Bar), :multiple => true |
|
355 | f1 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Foo Bar), :multiple => true | |
356 | f2 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Baz Qux), :multiple => true |
|
356 | f2 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Baz Qux), :multiple => true | |
357 | project = Project.generate!(:custom_field_values => {f2.id.to_s => %w(Qux)}) |
|
357 | project = Project.generate!(:custom_field_values => {f2.id.to_s => %w(Qux)}) | |
358 |
|
358 | |||
359 | get :show, :id => project.id |
|
359 | get :show, :id => project.id | |
360 | assert_response :success |
|
360 | assert_response :success | |
361 |
|
361 | |||
362 | assert_select 'li', :text => /#{f1.name}/, :count => 0 |
|
362 | assert_select 'li', :text => /#{f1.name}/, :count => 0 | |
363 | assert_select 'li', :text => /#{f2.name}/ |
|
363 | assert_select 'li', :text => /#{f2.name}/ | |
364 | end |
|
364 | end | |
365 |
|
365 | |||
366 | def test_show_should_not_display_blank_text_custom_fields |
|
366 | def test_show_should_not_display_blank_text_custom_fields | |
367 | f1 = ProjectCustomField.generate! :field_format => 'text' |
|
367 | f1 = ProjectCustomField.generate! :field_format => 'text' | |
368 |
|
368 | |||
369 | get :show, :id => 1 |
|
369 | get :show, :id => 1 | |
370 | assert_response :success |
|
370 | assert_response :success | |
371 |
|
371 | |||
372 | assert_select 'li', :text => /#{f1.name}/, :count => 0 |
|
372 | assert_select 'li', :text => /#{f1.name}/, :count => 0 | |
373 | end |
|
373 | end | |
374 |
|
374 | |||
375 | def test_show_should_not_fail_when_custom_values_are_nil |
|
375 | def test_show_should_not_fail_when_custom_values_are_nil | |
376 | project = Project.find_by_identifier('ecookbook') |
|
376 | project = Project.find_by_identifier('ecookbook') | |
377 | project.custom_values.first.update_attribute(:value, nil) |
|
377 | project.custom_values.first.update_attribute(:value, nil) | |
378 | get :show, :id => 'ecookbook' |
|
378 | get :show, :id => 'ecookbook' | |
379 | assert_response :success |
|
379 | assert_response :success | |
380 | assert_template 'show' |
|
380 | assert_template 'show' | |
381 | assert_not_nil assigns(:project) |
|
381 | assert_not_nil assigns(:project) | |
382 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
382 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
383 | end |
|
383 | end | |
384 |
|
384 | |||
385 | def show_archived_project_should_be_denied |
|
385 | def show_archived_project_should_be_denied | |
386 | project = Project.find_by_identifier('ecookbook') |
|
386 | project = Project.find_by_identifier('ecookbook') | |
387 | project.archive! |
|
387 | project.archive! | |
388 |
|
388 | |||
389 | get :show, :id => 'ecookbook' |
|
389 | get :show, :id => 'ecookbook' | |
390 | assert_response 403 |
|
390 | assert_response 403 | |
391 | assert_nil assigns(:project) |
|
391 | assert_nil assigns(:project) | |
392 | assert_select 'p', :text => /archived/ |
|
392 | assert_select 'p', :text => /archived/ | |
393 | end |
|
393 | end | |
394 |
|
394 | |||
395 | def test_show_should_not_show_private_subprojects_that_are_not_visible |
|
395 | def test_show_should_not_show_private_subprojects_that_are_not_visible | |
396 | get :show, :id => 'ecookbook' |
|
396 | get :show, :id => 'ecookbook' | |
397 | assert_response :success |
|
397 | assert_response :success | |
398 | assert_template 'show' |
|
398 | assert_template 'show' | |
399 | assert_select 'a', :text => /Private child/, :count => 0 |
|
399 | assert_select 'a', :text => /Private child/, :count => 0 | |
400 | end |
|
400 | end | |
401 |
|
401 | |||
402 | def test_show_should_show_private_subprojects_that_are_visible |
|
402 | def test_show_should_show_private_subprojects_that_are_visible | |
403 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
403 | @request.session[:user_id] = 2 # manager who is a member of the private subproject | |
404 | get :show, :id => 'ecookbook' |
|
404 | get :show, :id => 'ecookbook' | |
405 | assert_response :success |
|
405 | assert_response :success | |
406 | assert_template 'show' |
|
406 | assert_template 'show' | |
407 | assert_select 'a', :text => /Private child/ |
|
407 | assert_select 'a', :text => /Private child/ | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | def test_settings |
|
410 | def test_settings | |
411 | @request.session[:user_id] = 2 # manager |
|
411 | @request.session[:user_id] = 2 # manager | |
412 | get :settings, :id => 1 |
|
412 | get :settings, :id => 1 | |
413 | assert_response :success |
|
413 | assert_response :success | |
414 | assert_template 'settings' |
|
414 | assert_template 'settings' | |
415 | end |
|
415 | end | |
416 |
|
416 | |||
417 | def test_settings_of_subproject |
|
417 | def test_settings_of_subproject | |
418 | @request.session[:user_id] = 2 |
|
418 | @request.session[:user_id] = 2 | |
419 | get :settings, :id => 'private-child' |
|
419 | get :settings, :id => 'private-child' | |
420 | assert_response :success |
|
420 | assert_response :success | |
421 | assert_template 'settings' |
|
421 | assert_template 'settings' | |
422 |
|
422 | |||
423 | assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]' |
|
423 | assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]' | |
424 | end |
|
424 | end | |
425 |
|
425 | |||
426 | def test_settings_should_be_denied_for_member_on_closed_project |
|
426 | def test_settings_should_be_denied_for_member_on_closed_project | |
427 | Project.find(1).close |
|
427 | Project.find(1).close | |
428 | @request.session[:user_id] = 2 # manager |
|
428 | @request.session[:user_id] = 2 # manager | |
429 |
|
429 | |||
430 | get :settings, :id => 1 |
|
430 | get :settings, :id => 1 | |
431 | assert_response 403 |
|
431 | assert_response 403 | |
432 | end |
|
432 | end | |
433 |
|
433 | |||
434 | def test_settings_should_be_denied_for_anonymous_on_closed_project |
|
434 | def test_settings_should_be_denied_for_anonymous_on_closed_project | |
435 | Project.find(1).close |
|
435 | Project.find(1).close | |
436 |
|
436 | |||
437 | get :settings, :id => 1 |
|
437 | get :settings, :id => 1 | |
438 | assert_response 302 |
|
438 | assert_response 302 | |
439 | end |
|
439 | end | |
440 |
|
440 | |||
441 | def test_setting_with_wiki_module_and_no_wiki |
|
441 | def test_setting_with_wiki_module_and_no_wiki | |
442 | Project.find(1).wiki.destroy |
|
442 | Project.find(1).wiki.destroy | |
443 | Role.find(1).add_permission! :manage_wiki |
|
443 | Role.find(1).add_permission! :manage_wiki | |
444 | @request.session[:user_id] = 2 |
|
444 | @request.session[:user_id] = 2 | |
445 |
|
445 | |||
446 | get :settings, :id => 1 |
|
446 | get :settings, :id => 1 | |
447 | assert_response :success |
|
447 | assert_response :success | |
448 | assert_template 'settings' |
|
448 | assert_template 'settings' | |
449 |
|
449 | |||
450 | assert_select 'form[action=?]', '/projects/ecookbook/wiki' do |
|
450 | assert_select 'form[action=?]', '/projects/ecookbook/wiki' do | |
451 | assert_select 'input[name=?]', 'wiki[start_page]' |
|
451 | assert_select 'input[name=?]', 'wiki[start_page]' | |
452 | end |
|
452 | end | |
453 | end |
|
453 | end | |
454 |
|
454 | |||
455 | def test_update |
|
455 | def test_update | |
456 | @request.session[:user_id] = 2 # manager |
|
456 | @request.session[:user_id] = 2 # manager | |
457 | post :update, :id => 1, :project => {:name => 'Test changed name', |
|
457 | post :update, :id => 1, :project => {:name => 'Test changed name', | |
458 | :issue_custom_field_ids => ['']} |
|
458 | :issue_custom_field_ids => ['']} | |
459 | assert_redirected_to '/projects/ecookbook/settings' |
|
459 | assert_redirected_to '/projects/ecookbook/settings' | |
460 | project = Project.find(1) |
|
460 | project = Project.find(1) | |
461 | assert_equal 'Test changed name', project.name |
|
461 | assert_equal 'Test changed name', project.name | |
462 | end |
|
462 | end | |
463 |
|
463 | |||
464 | def test_update_with_failure |
|
464 | def test_update_with_failure | |
465 | @request.session[:user_id] = 2 # manager |
|
465 | @request.session[:user_id] = 2 # manager | |
466 | post :update, :id => 1, :project => {:name => ''} |
|
466 | post :update, :id => 1, :project => {:name => ''} | |
467 | assert_response :success |
|
467 | assert_response :success | |
468 | assert_template 'settings' |
|
468 | assert_template 'settings' | |
469 | assert_select_error /name cannot be blank/i |
|
469 | assert_select_error /name cannot be blank/i | |
470 | end |
|
470 | end | |
471 |
|
471 | |||
472 | def test_update_should_be_denied_for_member_on_closed_project |
|
472 | def test_update_should_be_denied_for_member_on_closed_project | |
473 | Project.find(1).close |
|
473 | Project.find(1).close | |
474 | @request.session[:user_id] = 2 # manager |
|
474 | @request.session[:user_id] = 2 # manager | |
475 |
|
475 | |||
476 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
476 | post :update, :id => 1, :project => {:name => 'Closed'} | |
477 | assert_response 403 |
|
477 | assert_response 403 | |
478 | assert_equal 'eCookbook', Project.find(1).name |
|
478 | assert_equal 'eCookbook', Project.find(1).name | |
479 | end |
|
479 | end | |
480 |
|
480 | |||
481 | def test_update_should_be_denied_for_anonymous_on_closed_project |
|
481 | def test_update_should_be_denied_for_anonymous_on_closed_project | |
482 | Project.find(1).close |
|
482 | Project.find(1).close | |
483 |
|
483 | |||
484 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
484 | post :update, :id => 1, :project => {:name => 'Closed'} | |
485 | assert_response 302 |
|
485 | assert_response 302 | |
486 | assert_equal 'eCookbook', Project.find(1).name |
|
486 | assert_equal 'eCookbook', Project.find(1).name | |
487 | end |
|
487 | end | |
488 |
|
488 | |||
489 | def test_modules |
|
489 | def test_modules | |
490 | @request.session[:user_id] = 2 |
|
490 | @request.session[:user_id] = 2 | |
491 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
|
491 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] | |
492 |
|
492 | |||
493 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] |
|
493 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] | |
494 | assert_redirected_to '/projects/ecookbook/settings/modules' |
|
494 | assert_redirected_to '/projects/ecookbook/settings/modules' | |
495 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort |
|
495 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort | |
496 | end |
|
496 | end | |
497 |
|
497 | |||
498 | def test_destroy_leaf_project_without_confirmation_should_show_confirmation |
|
498 | def test_destroy_leaf_project_without_confirmation_should_show_confirmation | |
499 | @request.session[:user_id] = 1 # admin |
|
499 | @request.session[:user_id] = 1 # admin | |
500 |
|
500 | |||
501 | assert_no_difference 'Project.count' do |
|
501 | assert_no_difference 'Project.count' do | |
502 | delete :destroy, :id => 2 |
|
502 | delete :destroy, :id => 2 | |
503 | assert_response :success |
|
503 | assert_response :success | |
504 | assert_template 'destroy' |
|
504 | assert_template 'destroy' | |
505 | end |
|
505 | end | |
506 | end |
|
506 | end | |
507 |
|
507 | |||
508 | def test_destroy_without_confirmation_should_show_confirmation_with_subprojects |
|
508 | def test_destroy_without_confirmation_should_show_confirmation_with_subprojects | |
509 | @request.session[:user_id] = 1 # admin |
|
509 | @request.session[:user_id] = 1 # admin | |
510 |
|
510 | |||
511 | assert_no_difference 'Project.count' do |
|
511 | assert_no_difference 'Project.count' do | |
512 | delete :destroy, :id => 1 |
|
512 | delete :destroy, :id => 1 | |
513 | assert_response :success |
|
513 | assert_response :success | |
514 | assert_template 'destroy' |
|
514 | assert_template 'destroy' | |
515 | end |
|
515 | end | |
516 | assert_select 'strong', |
|
516 | assert_select 'strong', | |
517 | :text => ['Private child of eCookbook', |
|
517 | :text => ['Private child of eCookbook', | |
518 | 'Child of private child, eCookbook Subproject 1', |
|
518 | 'Child of private child, eCookbook Subproject 1', | |
519 | 'eCookbook Subproject 2'].join(', ') |
|
519 | 'eCookbook Subproject 2'].join(', ') | |
520 | end |
|
520 | end | |
521 |
|
521 | |||
522 | def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects |
|
522 | def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects | |
523 | @request.session[:user_id] = 1 # admin |
|
523 | @request.session[:user_id] = 1 # admin | |
524 |
|
524 | |||
525 | assert_difference 'Project.count', -5 do |
|
525 | assert_difference 'Project.count', -5 do | |
526 | delete :destroy, :id => 1, :confirm => 1 |
|
526 | delete :destroy, :id => 1, :confirm => 1 | |
527 | assert_redirected_to '/admin/projects' |
|
527 | assert_redirected_to '/admin/projects' | |
528 | end |
|
528 | end | |
529 | assert_nil Project.find_by_id(1) |
|
529 | assert_nil Project.find_by_id(1) | |
530 | end |
|
530 | end | |
531 |
|
531 | |||
532 | def test_archive |
|
532 | def test_archive | |
533 | @request.session[:user_id] = 1 # admin |
|
533 | @request.session[:user_id] = 1 # admin | |
534 | post :archive, :id => 1 |
|
534 | post :archive, :id => 1 | |
535 | assert_redirected_to '/admin/projects' |
|
535 | assert_redirected_to '/admin/projects' | |
536 | assert !Project.find(1).active? |
|
536 | assert !Project.find(1).active? | |
537 | end |
|
537 | end | |
538 |
|
538 | |||
539 | def test_archive_with_failure |
|
539 | def test_archive_with_failure | |
540 | @request.session[:user_id] = 1 |
|
540 | @request.session[:user_id] = 1 | |
541 | Project.any_instance.stubs(:archive).returns(false) |
|
541 | Project.any_instance.stubs(:archive).returns(false) | |
542 | post :archive, :id => 1 |
|
542 | post :archive, :id => 1 | |
543 | assert_redirected_to '/admin/projects' |
|
543 | assert_redirected_to '/admin/projects' | |
544 | assert_match /project cannot be archived/i, flash[:error] |
|
544 | assert_match /project cannot be archived/i, flash[:error] | |
545 | end |
|
545 | end | |
546 |
|
546 | |||
547 | def test_unarchive |
|
547 | def test_unarchive | |
548 | @request.session[:user_id] = 1 # admin |
|
548 | @request.session[:user_id] = 1 # admin | |
549 | Project.find(1).archive |
|
549 | Project.find(1).archive | |
550 | post :unarchive, :id => 1 |
|
550 | post :unarchive, :id => 1 | |
551 | assert_redirected_to '/admin/projects' |
|
551 | assert_redirected_to '/admin/projects' | |
552 | assert Project.find(1).active? |
|
552 | assert Project.find(1).active? | |
553 | end |
|
553 | end | |
554 |
|
554 | |||
555 | def test_close |
|
555 | def test_close | |
556 | @request.session[:user_id] = 2 |
|
556 | @request.session[:user_id] = 2 | |
557 | post :close, :id => 1 |
|
557 | post :close, :id => 1 | |
558 | assert_redirected_to '/projects/ecookbook' |
|
558 | assert_redirected_to '/projects/ecookbook' | |
559 | assert_equal Project::STATUS_CLOSED, Project.find(1).status |
|
559 | assert_equal Project::STATUS_CLOSED, Project.find(1).status | |
560 | end |
|
560 | end | |
561 |
|
561 | |||
562 | def test_reopen |
|
562 | def test_reopen | |
563 | Project.find(1).close |
|
563 | Project.find(1).close | |
564 | @request.session[:user_id] = 2 |
|
564 | @request.session[:user_id] = 2 | |
565 | post :reopen, :id => 1 |
|
565 | post :reopen, :id => 1 | |
566 | assert_redirected_to '/projects/ecookbook' |
|
566 | assert_redirected_to '/projects/ecookbook' | |
567 | assert Project.find(1).active? |
|
567 | assert Project.find(1).active? | |
568 | end |
|
568 | end | |
569 |
|
569 | |||
570 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
|
570 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors | |
571 | CustomField.delete_all |
|
571 | CustomField.delete_all | |
572 | parent = nil |
|
572 | parent = nil | |
573 | 6.times do |i| |
|
573 | 6.times do |i| | |
574 | p = Project.generate_with_parent!(parent) |
|
574 | p = Project.generate_with_parent!(parent) | |
575 | get :show, :id => p |
|
575 | get :show, :id => p | |
576 | assert_select '#header h1' do |
|
576 | assert_select '#header h1' do | |
577 | assert_select 'a', :count => [i, 3].min |
|
577 | assert_select 'a', :count => [i, 3].min | |
578 | end |
|
578 | end | |
579 |
|
579 | |||
580 | parent = p |
|
580 | parent = p | |
581 | end |
|
581 | end | |
582 | end |
|
582 | end | |
583 |
|
583 | |||
584 | def test_get_copy |
|
584 | def test_get_copy | |
585 | @request.session[:user_id] = 1 # admin |
|
585 | @request.session[:user_id] = 1 # admin | |
586 | get :copy, :id => 1 |
|
586 | get :copy, :id => 1 | |
587 | assert_response :success |
|
587 | assert_response :success | |
588 | assert_template 'copy' |
|
588 | assert_template 'copy' | |
589 | assert assigns(:project) |
|
589 | assert assigns(:project) | |
590 | assert_equal Project.find(1).description, assigns(:project).description |
|
590 | assert_equal Project.find(1).description, assigns(:project).description | |
591 | assert_nil assigns(:project).id |
|
591 | assert_nil assigns(:project).id | |
592 |
|
592 | |||
593 | assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1 |
|
593 | assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1 | |
594 | end |
|
594 | end | |
595 |
|
595 | |||
596 | def test_get_copy_with_invalid_source_should_respond_with_404 |
|
596 | def test_get_copy_with_invalid_source_should_respond_with_404 | |
597 | @request.session[:user_id] = 1 |
|
597 | @request.session[:user_id] = 1 | |
598 | get :copy, :id => 99 |
|
598 | get :copy, :id => 99 | |
599 | assert_response 404 |
|
599 | assert_response 404 | |
600 | end |
|
600 | end | |
601 |
|
601 | |||
602 | def test_post_copy_should_copy_requested_items |
|
602 | def test_post_copy_should_copy_requested_items | |
603 | @request.session[:user_id] = 1 # admin |
|
603 | @request.session[:user_id] = 1 # admin | |
604 | CustomField.delete_all |
|
604 | CustomField.delete_all | |
605 |
|
605 | |||
606 | assert_difference 'Project.count' do |
|
606 | assert_difference 'Project.count' do | |
607 | post :copy, :id => 1, |
|
607 | post :copy, :id => 1, | |
608 | :project => { |
|
608 | :project => { | |
609 | :name => 'Copy', |
|
609 | :name => 'Copy', | |
610 | :identifier => 'unique-copy', |
|
610 | :identifier => 'unique-copy', | |
611 | :tracker_ids => ['1', '2', '3', ''], |
|
611 | :tracker_ids => ['1', '2', '3', ''], | |
612 | :enabled_module_names => %w(issue_tracking time_tracking) |
|
612 | :enabled_module_names => %w(issue_tracking time_tracking) | |
613 | }, |
|
613 | }, | |
614 | :only => %w(issues versions) |
|
614 | :only => %w(issues versions) | |
615 | end |
|
615 | end | |
616 | project = Project.find('unique-copy') |
|
616 | project = Project.find('unique-copy') | |
617 | source = Project.find(1) |
|
617 | source = Project.find(1) | |
618 | assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort |
|
618 | assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort | |
619 |
|
619 | |||
620 | assert_equal source.versions.count, project.versions.count, "All versions were not copied" |
|
620 | assert_equal source.versions.count, project.versions.count, "All versions were not copied" | |
621 | assert_equal source.issues.count, project.issues.count, "All issues were not copied" |
|
621 | assert_equal source.issues.count, project.issues.count, "All issues were not copied" | |
622 | assert_equal 0, project.members.count |
|
622 | assert_equal 0, project.members.count | |
623 | end |
|
623 | end | |
624 |
|
624 | |||
625 | def test_post_copy_should_redirect_to_settings_when_successful |
|
625 | def test_post_copy_should_redirect_to_settings_when_successful | |
626 | @request.session[:user_id] = 1 # admin |
|
626 | @request.session[:user_id] = 1 # admin | |
627 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} |
|
627 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} | |
628 | assert_response :redirect |
|
628 | assert_response :redirect | |
629 | assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' |
|
629 | assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' | |
630 | end |
|
630 | end | |
631 |
|
631 | |||
632 | def test_post_copy_with_failure |
|
632 | def test_post_copy_with_failure | |
633 | @request.session[:user_id] = 1 |
|
633 | @request.session[:user_id] = 1 | |
634 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => ''} |
|
634 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => ''} | |
635 | assert_response :success |
|
635 | assert_response :success | |
636 | assert_template 'copy' |
|
636 | assert_template 'copy' | |
637 | end |
|
637 | end | |
638 |
|
638 | |||
639 | def test_jump_should_redirect_to_active_tab |
|
639 | def test_jump_should_redirect_to_active_tab | |
640 | get :show, :id => 1, :jump => 'issues' |
|
640 | get :show, :id => 1, :jump => 'issues' | |
641 | assert_redirected_to '/projects/ecookbook/issues' |
|
641 | assert_redirected_to '/projects/ecookbook/issues' | |
642 | end |
|
642 | end | |
643 |
|
643 | |||
644 | def test_jump_should_not_redirect_to_inactive_tab |
|
644 | def test_jump_should_not_redirect_to_inactive_tab | |
645 | get :show, :id => 3, :jump => 'documents' |
|
645 | get :show, :id => 3, :jump => 'documents' | |
646 | assert_response :success |
|
646 | assert_response :success | |
647 | assert_template 'show' |
|
647 | assert_template 'show' | |
648 | end |
|
648 | end | |
649 |
|
649 | |||
650 | def test_jump_should_not_redirect_to_unknown_tab |
|
650 | def test_jump_should_not_redirect_to_unknown_tab | |
651 | get :show, :id => 3, :jump => 'foobar' |
|
651 | get :show, :id => 3, :jump => 'foobar' | |
652 | assert_response :success |
|
652 | assert_response :success | |
653 | assert_template 'show' |
|
653 | assert_template 'show' | |
654 | end |
|
654 | end | |
655 |
|
655 | |||
656 | def test_body_should_have_project_css_class |
|
656 | def test_body_should_have_project_css_class | |
657 | get :show, :id => 1 |
|
657 | get :show, :id => 1 | |
658 | assert_select 'body.project-ecookbook' |
|
658 | assert_select 'body.project-ecookbook' | |
659 | end |
|
659 | end | |
660 |
|
660 | |||
661 | def test_project_menu_should_include_new_issue_link |
|
661 | def test_project_menu_should_include_new_issue_link | |
662 | @request.session[:user_id] = 2 |
|
662 | @request.session[:user_id] = 2 | |
663 | get :show, :id => 1 |
|
663 | get :show, :id => 1 | |
664 | assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]', :text => 'New issue' |
|
664 | assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]', :text => 'New issue' | |
665 | end |
|
665 | end | |
666 |
|
666 | |||
667 | def test_project_menu_should_not_include_new_issue_link_for_project_without_trackers |
|
667 | def test_project_menu_should_not_include_new_issue_link_for_project_without_trackers | |
668 | Project.find(1).trackers.clear |
|
668 | Project.find(1).trackers.clear | |
669 |
|
669 | |||
670 | @request.session[:user_id] = 2 |
|
670 | @request.session[:user_id] = 2 | |
671 | get :show, :id => 1 |
|
671 | get :show, :id => 1 | |
672 | assert_select '#main-menu a.new-issue', 0 |
|
672 | assert_select '#main-menu a.new-issue', 0 | |
673 | end |
|
673 | end | |
|
674 | ||||
|
675 | def test_project_menu_should_not_include_new_issue_link_for_users_with_copy_issues_permission_only | |||
|
676 | role = Role.find(1) | |||
|
677 | role.remove_permission! :add_issues | |||
|
678 | role.add_permission! :copy_issues | |||
|
679 | ||||
|
680 | @request.session[:user_id] = 2 | |||
|
681 | get :show, :id => 1 | |||
|
682 | assert_select '#main-menu a.new-issue', 0 | |||
|
683 | end | |||
674 | end |
|
684 | end |
General Comments 0
You need to be logged in to leave comments.
Login now