From: Jean-Philippe Lang Date: Sun, 4 Jan 2009 13:03:34 +0000 (+0000) Subject: Merged r2209 to r2211 from trunk. X-Git-Tag: 0.8.1~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c9d4d3a2be3da849343c2737b753a547d0adc875;p=redmine.git Merged r2209 to r2211 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.8-stable@2229 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 2851f91a6..c10834c11 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -35,7 +35,9 @@ class AttachmentsController < ApplicationController end def download - @attachment.increment_download if @attachment.container.is_a?(Version) + if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) + @attachment.increment_download + end # images are sent inline send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8fd79533f..0f0805262 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -84,6 +84,11 @@ class ProjectsController < ApplicationController # Show @project def show + if params[:jump] + # try to redirect to the requested menu item + redirect_to_project_menu_item(@project, params[:jump]) && return + end + @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current)) @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 268b56497..402c46127 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -90,6 +90,13 @@ class MailHandler < ActionMailer::Base end issue.subject = email.subject.chomp.toutf8 issue.description = plain_text_body + # custom fields + issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c| + if value = get_keyword(c.name, :override => true) + h[c.id] = value + end + h + end issue.save! add_attachments(issue) logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info @@ -155,8 +162,8 @@ class MailHandler < ActionMailer::Base end end - def get_keyword(attr) - if @@handler_options[:allow_override].include?(attr.to_s) && plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i + def get_keyword(attr, options={}) + if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i $1.strip elsif !@@handler_options[:issue][attr].blank? @@handler_options[:issue][attr] diff --git a/app/views/layouts/_project_selector.rhtml b/app/views/layouts/_project_selector.rhtml index 7a2803534..d8e2a72c9 100644 --- a/app/views/layouts/_project_selector.rhtml +++ b/app/views/layouts/_project_selector.rhtml @@ -3,10 +3,10 @@ <% user_projects_by_root.keys.sort.each do |root| %> - <%= content_tag('option', h(root.name), :value => url_for(:controller => 'projects', :action => 'show', :id => root)) %> + <%= content_tag('option', h(root.name), :value => url_for(:controller => 'projects', :action => 'show', :id => root, :jump => current_menu_item)) %> <% user_projects_by_root[root].sort.each do |project| %> <% next if project == root %> - <%= content_tag('option', ('» ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project)) %> + <%= content_tag('option', ('» ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project, :jump => current_menu_item)) %> <% end %> <% end %> diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index f8fc5dd8d..7a89a32b9 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -52,8 +52,19 @@ module Redmine # Returns the menu item name according to the current action def current_menu_item - menu_items[controller_name.to_sym][:actions][action_name.to_sym] || - menu_items[controller_name.to_sym][:default] + @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] || + menu_items[controller_name.to_sym][:default] + end + + # Redirects user to the menu item of the given project + # Returns false if user is not authorized + def redirect_to_project_menu_item(project, name) + item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name.to_s == name.to_s} + if item && User.current.allowed_to?(item.url, project) && (item.condition.nil? || item.condition.call(project)) + redirect_to({item.param => project}.merge(item.url)) + return true + end + false end end diff --git a/test/fixtures/mail_handler/ticket_with_custom_fields.eml b/test/fixtures/mail_handler/ticket_with_custom_fields.eml new file mode 100644 index 000000000..f3798a4b6 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_with_custom_fields.eml @@ -0,0 +1,41 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: New ticket with custom field values +Date: Sun, 22 Jun 2008 12:28:07 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + format=flowed; + charset="iso-8859-1"; + reply-type=original +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet +turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus +blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti +sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In +in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras +sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum +id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus +eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique +sed, mauris. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse +platea dictumst. + +Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque +sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem. +Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et, +dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed, +massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo +pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. + +category: Stock management +searchable field: Value for a custom field diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index a8f8ecb76..8737b3c59 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -287,6 +287,23 @@ class ProjectsControllerTest < Test::Unit::TestCase assert Project.find(1).active? end + def test_jump_should_redirect_to_active_tab + get :show, :id => 1, :jump => 'issues' + assert_redirected_to 'projects/ecookbook/issues' + end + + def test_jump_should_not_redirect_to_inactive_tab + get :show, :id => 3, :jump => 'documents' + assert_response :success + assert_template 'show' + end + + def test_jump_should_not_redirect_to_unknown_tab + get :show, :id => 3, :jump => 'foobar' + assert_response :success + assert_template 'show' + end + def test_project_menu assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do Redmine::MenuManager.map :project_menu do |menu| diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 80f70a417..0df64425b 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -28,7 +28,9 @@ class MailHandlerTest < Test::Unit::TestCase :trackers, :projects_trackers, :enumerations, - :issue_categories + :issue_categories, + :custom_fields, + :custom_fields_trackers FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' @@ -102,6 +104,15 @@ class MailHandlerTest < Test::Unit::TestCase assert_equal 10790, issue.attachments.first.filesize end + def test_add_issue_with_custom_fields + issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) + assert issue.is_a?(Issue) + assert !issue.new_record? + issue.reload + assert_equal 'New ticket with custom field values', issue.subject + assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value + end + def test_add_issue_with_cc issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) assert issue.is_a?(Issue)