From 2012c60bfdf613ad69e5f8abdac5774754ae6a1b Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 19 Aug 2010 04:33:46 +0000 Subject: [PATCH] Merged r3941 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.0-stable@3991 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 25 +-------------- app/controllers/journals_controller.rb | 34 ++++++++++++++++++++- app/helpers/journals_helper.rb | 2 +- config/routes.rb | 2 +- lib/redmine.rb | 4 +-- test/functional/issues_controller_test.rb | 14 --------- test/functional/journals_controller_test.rb | 14 +++++++++ test/integration/routing_test.rb | 2 +- 8 files changed, 53 insertions(+), 44 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 7518e3751c..eaa6dbc350 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -19,7 +19,7 @@ class IssuesController < ApplicationController menu_item :new_issue, :only => [:new, :create] default_search_scope :issues - before_filter :find_issue, :only => [:show, :edit, :update, :reply] + before_filter :find_issue, :only => [:show, :edit, :update] before_filter :find_issues, :only => [:bulk_edit, :move, :perform_move, :destroy] before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete] before_filter :authorize, :except => [:index, :changes, :preview, :context_menu] @@ -200,29 +200,6 @@ class IssuesController < ApplicationController end end - def reply - journal = Journal.find(params[:journal_id]) if params[:journal_id] - if journal - user = journal.user - text = journal.notes - else - user = @issue.author - text = @issue.description - end - # Replaces pre blocks with [...] - text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') - content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " - content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" - - render(:update) { |page| - page.<< "$('notes').value = \"#{escape_javascript content}\";" - page.show 'update' - page << "Form.Element.focus('notes');" - page << "Element.scrollTo('update');" - page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" - } - end - # Bulk edit a set of issues def bulk_edit @issues.sort! diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index e9fe9099de..10450970c7 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -16,7 +16,31 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class JournalsController < ApplicationController - before_filter :find_journal + before_filter :find_journal, :only => [:edit] + before_filter :find_issue, :only => [:new] + + def new + journal = Journal.find(params[:journal_id]) if params[:journal_id] + if journal + user = journal.user + text = journal.notes + else + user = @issue.author + text = @issue.description + end + # Replaces pre blocks with [...] + text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') + content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " + content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" + + render(:update) { |page| + page.<< "$('notes').value = \"#{escape_javascript content}\";" + page.show 'update' + page << "Form.Element.focus('notes');" + page << "Element.scrollTo('update');" + page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" + } + end def edit if request.post? @@ -38,4 +62,12 @@ private rescue ActiveRecord::RecordNotFound render_404 end + + # TODO: duplicated in IssuesController + def find_issue + @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) + @project = @issue.project + rescue ActiveRecord::RecordNotFound + render_404 + end end diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index cf87724307..c8d53f253b 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -22,7 +22,7 @@ module JournalsHelper links = [] if !journal.notes.blank? links << link_to_remote(image_tag('comment.png'), - { :url => {:controller => 'issues', :action => 'reply', :id => issue, :journal_id => journal} }, + { :url => {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal} }, :title => l(:button_quote)) if options[:reply_links] links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", { :controller => 'journals', :action => 'edit', :id => journal }, diff --git a/config/routes.rb b/config/routes.rb index 6f71cb6589..08cd100556 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -124,7 +124,7 @@ ActionController::Routing::Routes.draw do |map| issues_actions.connect 'projects/:project_id/issues', :action => 'create' issues_actions.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show' issues_actions.connect 'projects/:project_id/issues/calendar', :controller => 'calendars', :action => 'show' - issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/ + issues_actions.connect 'issues/:id/quoted', :controller => 'journals', :action => 'new', :id => /\d+/ issues_actions.connect 'issues/:id/:action', :action => /edit|destroy/, :id => /\d+/ issues_actions.connect 'issues.:format', :action => 'create', :format => /xml/ end diff --git a/lib/redmine.rb b/lib/redmine.rb index 1d8dbea18a..e92f67b73b 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -63,10 +63,10 @@ Redmine::AccessControl.map do |map| :queries => :index, :reports => [:issue_report, :issue_report_details]} map.permission :add_issues, {:issues => [:new, :create, :update_form]} - map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]} + map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :update_form], :journals => [:new]} map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} map.permission :manage_subtasks, {} - map.permission :add_issue_notes, {:issues => [:edit, :update, :reply]} + map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]} map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 6b23a65113..0c1172f602 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -634,20 +634,6 @@ class IssuesControllerTest < ActionController::TestCase assert_equal 'This is the test_new issue', issue.subject end - def test_reply_to_issue - @request.session[:user_id] = 2 - get :reply, :id => 1 - assert_response :success - assert_select_rjs :show, "update" - end - - def test_reply_to_note - @request.session[:user_id] = 2 - get :reply, :id => 1, :journal_id => 2 - assert_response :success - assert_select_rjs :show, "update" - end - def test_update_using_invalid_http_verbs @request.session[:user_id] = 2 subject = 'Updated by an invalid http verb' diff --git a/test/functional/journals_controller_test.rb b/test/functional/journals_controller_test.rb index 0a11bab3e4..7d8345b288 100644 --- a/test/functional/journals_controller_test.rb +++ b/test/functional/journals_controller_test.rb @@ -31,6 +31,20 @@ class JournalsControllerTest < ActionController::TestCase User.current = nil end + def test_reply_to_issue + @request.session[:user_id] = 2 + get :new, :id => 1 + assert_response :success + assert_select_rjs :show, "update" + end + + def test_reply_to_note + @request.session[:user_id] = 2 + get :new, :id => 1, :journal_id => 2 + assert_response :success + assert_select_rjs :show, "update" + end + def test_get_edit @request.session[:user_id] = 1 xhr :get, :edit, :id => 2 diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index af66f7417d..b9eac552e5 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -88,7 +88,7 @@ class RoutingTest < ActionController::IntegrationTest should_route :get, "/issues/move/new", :controller => 'issue_moves', :action => 'new' should_route :post, "/issues/move", :controller => 'issue_moves', :action => 'create' - should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1' + should_route :post, "/issues/1/quoted", :controller => 'journals', :action => 'new', :id => '1' should_route :get, "/issues/calendar", :controller => 'calendars', :action => 'show' should_route :post, "/issues/calendar", :controller => 'calendars', :action => 'show'