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
This commit is contained in:
Jean-Philippe Lang 2009-01-04 13:03:34 +00:00
parent 31178553f3
commit c9d4d3a2be
8 changed files with 102 additions and 8 deletions

View File

@ -35,7 +35,9 @@ class AttachmentsController < ApplicationController
end end
def download 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 # images are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),

View File

@ -84,6 +84,11 @@ class ProjectsController < ApplicationController
# Show @project # Show @project
def show 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} @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)) @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") @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")

View File

@ -90,6 +90,13 @@ class MailHandler < ActionMailer::Base
end end
issue.subject = email.subject.chomp.toutf8 issue.subject = email.subject.chomp.toutf8
issue.description = plain_text_body 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! issue.save!
add_attachments(issue) add_attachments(issue)
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
@ -155,8 +162,8 @@ class MailHandler < ActionMailer::Base
end end
end end
def get_keyword(attr) def get_keyword(attr, options={})
if @@handler_options[:allow_override].include?(attr.to_s) && plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i
$1.strip $1.strip
elsif !@@handler_options[:issue][attr].blank? elsif !@@handler_options[:issue][attr].blank?
@@handler_options[:issue][attr] @@handler_options[:issue][attr]

View File

@ -3,10 +3,10 @@
<option selected="selected"><%= l(:label_jump_to_a_project) %></option> <option selected="selected"><%= l(:label_jump_to_a_project) %></option>
<option disabled="disabled">---</option> <option disabled="disabled">---</option>
<% user_projects_by_root.keys.sort.each do |root| %> <% 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| %> <% user_projects_by_root[root].sort.each do |project| %>
<% next if project == root %> <% next if project == root %>
<%= content_tag('option', ('&#187; ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project)) %> <%= content_tag('option', ('&#187; ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project, :jump => current_menu_item)) %>
<% end %> <% end %>
<% end %> <% end %>
</select> </select>

View File

@ -52,9 +52,20 @@ module Redmine
# Returns the menu item name according to the current action # Returns the menu item name according to the current action
def current_menu_item def current_menu_item
menu_items[controller_name.to_sym][:actions][action_name.to_sym] || @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
menu_items[controller_name.to_sym][:default] menu_items[controller_name.to_sym][:default]
end 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 end
module MenuHelper module MenuHelper

View File

@ -0,0 +1,41 @@
Return-Path: <jsmith@somenet.foo>
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" <jsmith@somenet.foo>
To: <redmine@somenet.foo>
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

View File

@ -287,6 +287,23 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert Project.find(1).active? assert Project.find(1).active?
end 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 def test_project_menu
assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
Redmine::MenuManager.map :project_menu do |menu| Redmine::MenuManager.map :project_menu do |menu|

View File

@ -28,7 +28,9 @@ class MailHandlerTest < Test::Unit::TestCase
:trackers, :trackers,
:projects_trackers, :projects_trackers,
:enumerations, :enumerations,
:issue_categories :issue_categories,
:custom_fields,
:custom_fields_trackers
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
@ -102,6 +104,15 @@ class MailHandlerTest < Test::Unit::TestCase
assert_equal 10790, issue.attachments.first.filesize assert_equal 10790, issue.attachments.first.filesize
end 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 def test_add_issue_with_cc
issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
assert issue.is_a?(Issue) assert issue.is_a?(Issue)