@@ -1,85 +1,89 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class AdminController < ApplicationController |
|
19 | 19 | before_filter :require_admin |
|
20 | 20 | |
|
21 | 21 | helper :sort |
|
22 | 22 | include SortHelper |
|
23 | 23 | |
|
24 | 24 | def index |
|
25 | 25 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def projects |
|
29 | 29 | sort_init 'name', 'asc' |
|
30 | 30 | sort_update |
|
31 | 31 | |
|
32 |
@status = params[:status] ? params[:status].to_i : |
|
|
33 | conditions = nil | |
|
34 | conditions = ["status=?", @status] unless @status == 0 | |
|
32 | @status = params[:status] ? params[:status].to_i : 1 | |
|
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
|
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 | 41 | @project_pages = Paginator.new self, @project_count, |
|
38 | 42 | per_page_option, |
|
39 | 43 | params['page'] |
|
40 | 44 | @projects = Project.find :all, :order => sort_clause, |
|
41 | :conditions => conditions, | |
|
45 | :conditions => c.conditions, | |
|
42 | 46 | :limit => @project_pages.items_per_page, |
|
43 | 47 | :offset => @project_pages.current.offset |
|
44 | 48 | |
|
45 | 49 | render :action => "projects", :layout => false if request.xhr? |
|
46 | 50 | end |
|
47 | 51 | |
|
48 | 52 | # Loads the default configuration |
|
49 | 53 | # (roles, trackers, statuses, workflow, enumerations) |
|
50 | 54 | def default_configuration |
|
51 | 55 | if request.post? |
|
52 | 56 | begin |
|
53 | 57 | Redmine::DefaultData::Loader::load(params[:lang]) |
|
54 | 58 | flash[:notice] = l(:notice_default_data_loaded) |
|
55 | 59 | rescue Exception => e |
|
56 | 60 | flash[:error] = l(:error_can_t_load_default_data, e.message) |
|
57 | 61 | end |
|
58 | 62 | end |
|
59 | 63 | redirect_to :action => 'index' |
|
60 | 64 | end |
|
61 | 65 | |
|
62 | 66 | def test_email |
|
63 | 67 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors |
|
64 | 68 | # Force ActionMailer to raise delivery errors so we can catch it |
|
65 | 69 | ActionMailer::Base.raise_delivery_errors = true |
|
66 | 70 | begin |
|
67 | 71 | @test = Mailer.deliver_test(User.current) |
|
68 | 72 | flash[:notice] = l(:notice_email_sent, User.current.mail) |
|
69 | 73 | rescue Exception => e |
|
70 | 74 | flash[:error] = l(:notice_email_error, e.message) |
|
71 | 75 | end |
|
72 | 76 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors |
|
73 | 77 | redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications' |
|
74 | 78 | end |
|
75 | 79 | |
|
76 | 80 | def info |
|
77 | 81 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name |
|
78 | 82 | @flags = { |
|
79 | 83 | :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?, |
|
80 | 84 | :file_repository_writable => File.writable?(Attachment.storage_path), |
|
81 | 85 | :rmagick_available => Object.const_defined?(:Magick) |
|
82 | 86 | } |
|
83 | 87 | @plugins = Redmine::Plugin.registered_plugins |
|
84 | 88 | end |
|
85 | 89 | end |
@@ -1,23 +1,23 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | module AdminHelper |
|
19 | 19 | def project_status_options_for_select(selected) |
|
20 |
options_for_select([[l(:label_all), |
|
|
20 | options_for_select([[l(:label_all), ''], | |
|
21 | 21 | [l(:status_active), 1]], selected) |
|
22 | 22 | end |
|
23 | 23 | end |
@@ -1,50 +1,52 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= link_to l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add' %> |
|
3 | 3 | </div> |
|
4 | 4 | |
|
5 | 5 | <h2><%=l(:label_project_plural)%></h2> |
|
6 | 6 | |
|
7 | <% form_tag() do %> | |
|
7 | <% form_tag({}, :method => :get) do %> | |
|
8 | 8 | <fieldset><legend><%= l(:label_filter_plural) %></legend> |
|
9 | 9 | <label><%= l(:field_status) %> :</label> |
|
10 | 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 | 14 | </fieldset> |
|
13 | 15 | <% end %> |
|
14 | 16 | |
|
15 | 17 | |
|
16 | 18 | <table class="list"> |
|
17 | 19 | <thead><tr> |
|
18 | 20 | <%= sort_header_tag('name', :caption => l(:label_project)) %> |
|
19 | 21 | <th><%=l(:field_description)%></th> |
|
20 | 22 | <th><%=l(:label_subproject_plural)%></th> |
|
21 | 23 | <%= sort_header_tag('is_public', :caption => l(:field_is_public), :default_order => 'desc') %> |
|
22 | 24 | <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %> |
|
23 | 25 | <th></th> |
|
24 | 26 | <th></th> |
|
25 | 27 | </tr></thead> |
|
26 | 28 | <tbody> |
|
27 | 29 | <% for project in @projects %> |
|
28 | 30 | <tr class="<%= cycle("odd", "even") %>"> |
|
29 | 31 | <td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %> |
|
30 | 32 | <td><%= textilizable project.short_description, :project => project %> |
|
31 | 33 | <td align="center"><%= project.children.size %> |
|
32 | 34 | <td align="center"><%= image_tag 'true.png' if project.is_public? %> |
|
33 | 35 | <td align="center"><%= format_date(project.created_on) %> |
|
34 | 36 | <td align="center" style="width:10%"> |
|
35 | 37 | <small> |
|
36 | 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 | 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 | 40 | </small> |
|
39 | 41 | </td> |
|
40 | 42 | <td align="center" style="width:10%"> |
|
41 | 43 | <small><%= link_to(l(:button_delete), { :controller => 'projects', :action => 'destroy', :id => project }, :class => 'icon icon-del') %></small> |
|
42 | 44 | </td> |
|
43 | 45 | </tr> |
|
44 | 46 | <% end %> |
|
45 | 47 | </tbody> |
|
46 | 48 | </table> |
|
47 | 49 | |
|
48 | 50 | <p class="pagination"><%= pagination_links_full @project_pages, @project_count %></p> |
|
49 | 51 | |
|
50 | 52 | <% html_title(l(:label_project_plural)) -%> |
@@ -1,75 +1,94 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'admin_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class AdminController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class AdminControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :users, :roles |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = AdminController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | @request.session[:user_id] = 1 # admin |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_index |
|
36 | 36 | get :index |
|
37 | 37 | assert_no_tag :tag => 'div', |
|
38 | 38 | :attributes => { :class => /nodata/ } |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_index_with_no_configuration_data |
|
42 | 42 | delete_configuration_data |
|
43 | 43 | get :index |
|
44 | 44 | assert_tag :tag => 'div', |
|
45 | 45 | :attributes => { :class => /nodata/ } |
|
46 | 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 | 67 | def test_load_default_configuration_data |
|
49 | 68 | delete_configuration_data |
|
50 | 69 | post :default_configuration, :lang => 'fr' |
|
51 | 70 | assert IssueStatus.find_by_name('Nouveau') |
|
52 | 71 | end |
|
53 | 72 | |
|
54 | 73 | def test_test_email |
|
55 | 74 | get :test_email |
|
56 | 75 | assert_redirected_to 'settings/edit' |
|
57 | 76 | mail = ActionMailer::Base.deliveries.last |
|
58 | 77 | assert_kind_of TMail::Mail, mail |
|
59 | 78 | user = User.find(1) |
|
60 | 79 | assert_equal [user.mail], mail.bcc |
|
61 | 80 | end |
|
62 | 81 | |
|
63 | 82 | def test_info |
|
64 | 83 | get :info |
|
65 | 84 | assert_response :success |
|
66 | 85 | assert_template 'info' |
|
67 | 86 | end |
|
68 | 87 | |
|
69 | 88 | def delete_configuration_data |
|
70 | 89 | Role.delete_all('builtin = 0') |
|
71 | 90 | Tracker.delete_all |
|
72 | 91 | IssueStatus.delete_all |
|
73 | 92 | Enumeration.delete_all |
|
74 | 93 | end |
|
75 | 94 | end |
General Comments 0
You need to be logged in to leave comments.
Login now