@@ -1,85 +1,89 | |||||
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 AdminController < ApplicationController |
|
18 | class AdminController < ApplicationController | |
19 | before_filter :require_admin |
|
19 | before_filter :require_admin | |
20 |
|
20 | |||
21 | helper :sort |
|
21 | helper :sort | |
22 | include SortHelper |
|
22 | include SortHelper | |
23 |
|
23 | |||
24 | def index |
|
24 | def index | |
25 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? |
|
25 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def projects |
|
28 | def projects | |
29 | sort_init 'name', 'asc' |
|
29 | sort_init 'name', 'asc' | |
30 | sort_update |
|
30 | sort_update | |
31 |
|
31 | |||
32 |
@status = params[:status] ? params[:status].to_i : |
|
32 | @status = params[:status] ? params[:status].to_i : 1 | |
33 | conditions = nil |
|
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
34 | conditions = ["status=?", @status] unless @status == 0 |
|
|||
35 |
|
34 | |||
36 | @project_count = Project.count(:conditions => conditions) |
|
35 | unless params[:name].blank? | |
|
36 | name = "%#{params[:name].strip.downcase}%" | |||
|
37 | c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name] | |||
|
38 | end | |||
|
39 | ||||
|
40 | @project_count = Project.count(:conditions => c.conditions) | |||
37 | @project_pages = Paginator.new self, @project_count, |
|
41 | @project_pages = Paginator.new self, @project_count, | |
38 | per_page_option, |
|
42 | per_page_option, | |
39 | params['page'] |
|
43 | params['page'] | |
40 | @projects = Project.find :all, :order => sort_clause, |
|
44 | @projects = Project.find :all, :order => sort_clause, | |
41 | :conditions => conditions, |
|
45 | :conditions => c.conditions, | |
42 | :limit => @project_pages.items_per_page, |
|
46 | :limit => @project_pages.items_per_page, | |
43 | :offset => @project_pages.current.offset |
|
47 | :offset => @project_pages.current.offset | |
44 |
|
48 | |||
45 | render :action => "projects", :layout => false if request.xhr? |
|
49 | render :action => "projects", :layout => false if request.xhr? | |
46 | end |
|
50 | end | |
47 |
|
51 | |||
48 | # Loads the default configuration |
|
52 | # Loads the default configuration | |
49 | # (roles, trackers, statuses, workflow, enumerations) |
|
53 | # (roles, trackers, statuses, workflow, enumerations) | |
50 | def default_configuration |
|
54 | def default_configuration | |
51 | if request.post? |
|
55 | if request.post? | |
52 | begin |
|
56 | begin | |
53 | Redmine::DefaultData::Loader::load(params[:lang]) |
|
57 | Redmine::DefaultData::Loader::load(params[:lang]) | |
54 | flash[:notice] = l(:notice_default_data_loaded) |
|
58 | flash[:notice] = l(:notice_default_data_loaded) | |
55 | rescue Exception => e |
|
59 | rescue Exception => e | |
56 | flash[:error] = l(:error_can_t_load_default_data, e.message) |
|
60 | flash[:error] = l(:error_can_t_load_default_data, e.message) | |
57 | end |
|
61 | end | |
58 | end |
|
62 | end | |
59 | redirect_to :action => 'index' |
|
63 | redirect_to :action => 'index' | |
60 | end |
|
64 | end | |
61 |
|
65 | |||
62 | def test_email |
|
66 | def test_email | |
63 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors |
|
67 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors | |
64 | # Force ActionMailer to raise delivery errors so we can catch it |
|
68 | # Force ActionMailer to raise delivery errors so we can catch it | |
65 | ActionMailer::Base.raise_delivery_errors = true |
|
69 | ActionMailer::Base.raise_delivery_errors = true | |
66 | begin |
|
70 | begin | |
67 | @test = Mailer.deliver_test(User.current) |
|
71 | @test = Mailer.deliver_test(User.current) | |
68 | flash[:notice] = l(:notice_email_sent, User.current.mail) |
|
72 | flash[:notice] = l(:notice_email_sent, User.current.mail) | |
69 | rescue Exception => e |
|
73 | rescue Exception => e | |
70 | flash[:error] = l(:notice_email_error, e.message) |
|
74 | flash[:error] = l(:notice_email_error, e.message) | |
71 | end |
|
75 | end | |
72 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors |
|
76 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors | |
73 | redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications' |
|
77 | redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications' | |
74 | end |
|
78 | end | |
75 |
|
79 | |||
76 | def info |
|
80 | def info | |
77 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name |
|
81 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name | |
78 | @flags = { |
|
82 | @flags = { | |
79 | :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?, |
|
83 | :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?, | |
80 | :file_repository_writable => File.writable?(Attachment.storage_path), |
|
84 | :file_repository_writable => File.writable?(Attachment.storage_path), | |
81 | :rmagick_available => Object.const_defined?(:Magick) |
|
85 | :rmagick_available => Object.const_defined?(:Magick) | |
82 | } |
|
86 | } | |
83 | @plugins = Redmine::Plugin.registered_plugins |
|
87 | @plugins = Redmine::Plugin.registered_plugins | |
84 | end |
|
88 | end | |
85 | end |
|
89 | end |
@@ -1,23 +1,23 | |||||
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 | module AdminHelper |
|
18 | module AdminHelper | |
19 | def project_status_options_for_select(selected) |
|
19 | def project_status_options_for_select(selected) | |
20 |
options_for_select([[l(:label_all), |
|
20 | options_for_select([[l(:label_all), ''], | |
21 | [l(:status_active), 1]], selected) |
|
21 | [l(:status_active), 1]], selected) | |
22 | end |
|
22 | end | |
23 | end |
|
23 | end |
@@ -1,50 +1,52 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 | <%= link_to l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add' %> |
|
2 | <%= link_to l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add' %> | |
3 | </div> |
|
3 | </div> | |
4 |
|
4 | |||
5 | <h2><%=l(:label_project_plural)%></h2> |
|
5 | <h2><%=l(:label_project_plural)%></h2> | |
6 |
|
6 | |||
7 | <% form_tag() do %> |
|
7 | <% form_tag({}, :method => :get) do %> | |
8 | <fieldset><legend><%= l(:label_filter_plural) %></legend> |
|
8 | <fieldset><legend><%= l(:label_filter_plural) %></legend> | |
9 | <label><%= l(:field_status) %> :</label> |
|
9 | <label><%= l(:field_status) %> :</label> | |
10 | <%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> |
|
10 | <%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> | |
11 | <%= submit_tag l(:button_apply), :class => "small" %> |
|
11 | <label><%= l(:label_project) %>:</label> | |
|
12 | <%= text_field_tag 'name', params[:name], :size => 30 %> | |||
|
13 | <%= submit_tag l(:button_apply), :class => "small", :name => nil %> | |||
12 | </fieldset> |
|
14 | </fieldset> | |
13 | <% end %> |
|
15 | <% end %> | |
14 | |
|
16 | | |
15 |
|
17 | |||
16 | <table class="list"> |
|
18 | <table class="list"> | |
17 | <thead><tr> |
|
19 | <thead><tr> | |
18 | <%= sort_header_tag('name', :caption => l(:label_project)) %> |
|
20 | <%= sort_header_tag('name', :caption => l(:label_project)) %> | |
19 | <th><%=l(:field_description)%></th> |
|
21 | <th><%=l(:field_description)%></th> | |
20 | <th><%=l(:label_subproject_plural)%></th> |
|
22 | <th><%=l(:label_subproject_plural)%></th> | |
21 | <%= sort_header_tag('is_public', :caption => l(:field_is_public), :default_order => 'desc') %> |
|
23 | <%= sort_header_tag('is_public', :caption => l(:field_is_public), :default_order => 'desc') %> | |
22 | <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %> |
|
24 | <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %> | |
23 | <th></th> |
|
25 | <th></th> | |
24 | <th></th> |
|
26 | <th></th> | |
25 | </tr></thead> |
|
27 | </tr></thead> | |
26 | <tbody> |
|
28 | <tbody> | |
27 | <% for project in @projects %> |
|
29 | <% for project in @projects %> | |
28 | <tr class="<%= cycle("odd", "even") %>"> |
|
30 | <tr class="<%= cycle("odd", "even") %>"> | |
29 | <td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %> |
|
31 | <td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %> | |
30 | <td><%= textilizable project.short_description, :project => project %> |
|
32 | <td><%= textilizable project.short_description, :project => project %> | |
31 | <td align="center"><%= project.children.size %> |
|
33 | <td align="center"><%= project.children.size %> | |
32 | <td align="center"><%= image_tag 'true.png' if project.is_public? %> |
|
34 | <td align="center"><%= image_tag 'true.png' if project.is_public? %> | |
33 | <td align="center"><%= format_date(project.created_on) %> |
|
35 | <td align="center"><%= format_date(project.created_on) %> | |
34 | <td align="center" style="width:10%"> |
|
36 | <td align="center" style="width:10%"> | |
35 | <small> |
|
37 | <small> | |
36 | <%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-lock') if project.active? %> |
|
38 | <%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-lock') if project.active? %> | |
37 | <%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project }, :method => :post, :class => 'icon icon-unlock') if !project.active? && (project.parent.nil? || project.parent.active?) %> |
|
39 | <%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project }, :method => :post, :class => 'icon icon-unlock') if !project.active? && (project.parent.nil? || project.parent.active?) %> | |
38 | </small> |
|
40 | </small> | |
39 | </td> |
|
41 | </td> | |
40 | <td align="center" style="width:10%"> |
|
42 | <td align="center" style="width:10%"> | |
41 | <small><%= link_to(l(:button_delete), { :controller => 'projects', :action => 'destroy', :id => project }, :class => 'icon icon-del') %></small> |
|
43 | <small><%= link_to(l(:button_delete), { :controller => 'projects', :action => 'destroy', :id => project }, :class => 'icon icon-del') %></small> | |
42 | </td> |
|
44 | </td> | |
43 | </tr> |
|
45 | </tr> | |
44 | <% end %> |
|
46 | <% end %> | |
45 | </tbody> |
|
47 | </tbody> | |
46 | </table> |
|
48 | </table> | |
47 |
|
49 | |||
48 | <p class="pagination"><%= pagination_links_full @project_pages, @project_count %></p> |
|
50 | <p class="pagination"><%= pagination_links_full @project_pages, @project_count %></p> | |
49 |
|
51 | |||
50 | <% html_title(l(:label_project_plural)) -%> |
|
52 | <% html_title(l(:label_project_plural)) -%> |
@@ -1,75 +1,94 | |||||
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 'admin_controller' |
|
19 | require 'admin_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class AdminController; def rescue_action(e) raise e end; end |
|
22 | class AdminController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class AdminControllerTest < Test::Unit::TestCase |
|
24 | class AdminControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles |
|
25 | fixtures :projects, :users, :roles | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = AdminController.new |
|
28 | @controller = AdminController.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_index |
|
35 | def test_index | |
36 | get :index |
|
36 | get :index | |
37 | assert_no_tag :tag => 'div', |
|
37 | assert_no_tag :tag => 'div', | |
38 | :attributes => { :class => /nodata/ } |
|
38 | :attributes => { :class => /nodata/ } | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_index_with_no_configuration_data |
|
41 | def test_index_with_no_configuration_data | |
42 | delete_configuration_data |
|
42 | delete_configuration_data | |
43 | get :index |
|
43 | get :index | |
44 | assert_tag :tag => 'div', |
|
44 | assert_tag :tag => 'div', | |
45 | :attributes => { :class => /nodata/ } |
|
45 | :attributes => { :class => /nodata/ } | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
|
48 | def test_projects | |||
|
49 | get :projects | |||
|
50 | assert_response :success | |||
|
51 | assert_template 'projects' | |||
|
52 | assert_not_nil assigns(:projects) | |||
|
53 | # active projects only | |||
|
54 | assert_nil assigns(:projects).detect {|u| !u.active?} | |||
|
55 | end | |||
|
56 | ||||
|
57 | def test_projects_with_name_filter | |||
|
58 | get :projects, :name => 'store', :status => '' | |||
|
59 | assert_response :success | |||
|
60 | assert_template 'projects' | |||
|
61 | projects = assigns(:projects) | |||
|
62 | assert_not_nil projects | |||
|
63 | assert_equal 1, projects.size | |||
|
64 | assert_equal 'OnlineStore', projects.first.name | |||
|
65 | end | |||
|
66 | ||||
48 | def test_load_default_configuration_data |
|
67 | def test_load_default_configuration_data | |
49 | delete_configuration_data |
|
68 | delete_configuration_data | |
50 | post :default_configuration, :lang => 'fr' |
|
69 | post :default_configuration, :lang => 'fr' | |
51 | assert IssueStatus.find_by_name('Nouveau') |
|
70 | assert IssueStatus.find_by_name('Nouveau') | |
52 | end |
|
71 | end | |
53 |
|
72 | |||
54 | def test_test_email |
|
73 | def test_test_email | |
55 | get :test_email |
|
74 | get :test_email | |
56 | assert_redirected_to 'settings/edit' |
|
75 | assert_redirected_to 'settings/edit' | |
57 | mail = ActionMailer::Base.deliveries.last |
|
76 | mail = ActionMailer::Base.deliveries.last | |
58 | assert_kind_of TMail::Mail, mail |
|
77 | assert_kind_of TMail::Mail, mail | |
59 | user = User.find(1) |
|
78 | user = User.find(1) | |
60 | assert_equal [user.mail], mail.bcc |
|
79 | assert_equal [user.mail], mail.bcc | |
61 | end |
|
80 | end | |
62 |
|
81 | |||
63 | def test_info |
|
82 | def test_info | |
64 | get :info |
|
83 | get :info | |
65 | assert_response :success |
|
84 | assert_response :success | |
66 | assert_template 'info' |
|
85 | assert_template 'info' | |
67 | end |
|
86 | end | |
68 |
|
87 | |||
69 | def delete_configuration_data |
|
88 | def delete_configuration_data | |
70 | Role.delete_all('builtin = 0') |
|
89 | Role.delete_all('builtin = 0') | |
71 | Tracker.delete_all |
|
90 | Tracker.delete_all | |
72 | IssueStatus.delete_all |
|
91 | IssueStatus.delete_all | |
73 | Enumeration.delete_all |
|
92 | Enumeration.delete_all | |
74 | end |
|
93 | end | |
75 | end |
|
94 | end |
General Comments 0
You need to be logged in to leave comments.
Login now