]> source.dussan.org Git - redmine.git/commitdiff
Use regular edit/update actions and named routes for JournalsController.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 21 Jan 2016 04:39:56 +0000 (04:39 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 21 Jan 2016 04:39:56 +0000 (04:39 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15074 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/journals_controller.rb
app/helpers/issues_helper.rb
app/helpers/journals_helper.rb
app/views/journals/_notes_form.html.erb
config/routes.rb
lib/redmine.rb
test/functional/journals_controller_test.rb
test/integration/routing/journals_test.rb
test/unit/mailer_test.rb

index bae6ca2bc1053eecfb8d8875ed943be2a3f7fcb7..382a84eb0de990c3b9dfd9547fa17a32806e6ccd 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class JournalsController < ApplicationController
-  before_filter :find_journal, :only => [:edit, :diff]
+  before_filter :find_journal, :only => [:edit, :update, :diff]
   before_filter :find_issue, :only => [:new]
   before_filter :find_optional_project, :only => [:index]
-  before_filter :authorize, :only => [:new, :edit, :diff]
+  before_filter :authorize, :only => [:new, :edit, :update, :diff]
   accept_rss_auth :index
   menu_item :issues
 
@@ -82,19 +82,20 @@ class JournalsController < ApplicationController
 
   def edit
     (render_403; return false) unless @journal.editable_by?(User.current)
-    if request.post?
-      @journal.update_attributes(:notes => params[:notes]) if params[:notes]
-      @journal.destroy if @journal.details.empty? && @journal.notes.blank?
-      call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
-      respond_to do |format|
-        format.html { redirect_to issue_path(@journal.journalized) }
-        format.js { render :action => 'update' }
-      end
-    else
-      respond_to do |format|
-        # TODO: implement non-JS journal update
-        format.js
-      end
+    respond_to do |format|
+      # TODO: implement non-JS journal update
+      format.js
+    end
+  end
+
+  def update
+    (render_403; return false) unless @journal.editable_by?(User.current)
+    @journal.update_attributes(:notes => params[:notes]) if params[:notes]
+    @journal.destroy if @journal.details.empty? && @journal.notes.blank?
+    call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
+    respond_to do |format|
+      format.html { redirect_to issue_path(@journal.journalized) }
+      format.js
     end
   end
 
index 4353e5033c8fa12ee24c4a828637ad2e2e1bbe21..5fdc6bf8c8f5d1d16c54eb36cffa5ced529114de 100644 (file)
@@ -456,8 +456,7 @@ module IssuesHelper
       s = l(:text_journal_changed_no_detail, :label => label)
       unless no_html
         diff_link = link_to 'diff',
-          {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
-           :detail_id => detail.id, :only_path => options[:only_path]},
+          diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
           :title => l(:label_view_diff)
         s << " (#{ diff_link })"
       end
index 0b57e1acb6875caa91689aef9f3378132eb771af..2a0a7d3518116afbd459135de449b83b73ac568e 100644 (file)
@@ -31,23 +31,23 @@ module JournalsHelper
     links = []
     if !journal.notes.blank?
       links << link_to('',
-                       {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal},
+                       quoted_issue_path(issue, :journal_id => journal),
                        :remote => true,
                        :method => 'post',
                        :title => l(:button_quote),
                        :class => 'icon-only icon-comment'
                       ) if options[:reply_links]
       links << link_to('',
-                       {:controller => 'journals', :action => 'edit', :id => journal},
+                       edit_journal_path(journal),
                        :remote => true,
                        :method => 'get',
                        :title => l(:button_edit),
                        :class => 'icon-only icon-edit'
                       ) if editable
       links << link_to('',
-                       {:controller => 'journals', :action => 'edit', :id => journal, :notes => ""},
+                       journal_path(journal, :notes => ""),
                        :remote => true,
-                       :method => :post, :data => {:confirm => l(:text_are_you_sure)}, 
+                       :method => 'put', :data => {:confirm => l(:text_are_you_sure)}, 
                        :title => l(:button_delete),
                        :class => 'icon-only icon-del'
                       ) if editable
index 63b87883a7a4f4cd0f322f502b529eed5c483111..41650c5d312f653c487e6008d90de10ea5726f17 100644 (file)
@@ -1,5 +1,6 @@
-<%= form_tag({:controller => 'journals', :action => 'edit', :id => @journal},
+<%= form_tag(journal_path(@journal),
              :remote => true,
+             :method => 'put',
              :id => "journal-#{@journal.id}-form") do %>
     <%= label_tag "notes", l(:description_notes), :class => "hidden-for-sighted" %>
     <%= text_area_tag :notes, @journal.notes,
index 47451453f0c7e6ce0d714f24d87cddab769c5bfe..3b469d7e9c7e113464c1f29a08b6544822461c24 100644 (file)
@@ -49,8 +49,11 @@ Rails.application.routes.draw do
   match '/issues/changes', :to => 'journals#index', :as => 'issue_changes', :via => :get
   match '/issues/:id/quoted', :to => 'journals#new', :id => /\d+/, :via => :post, :as => 'quoted_issue'
 
-  match '/journals/diff/:id', :to => 'journals#diff', :id => /\d+/, :via => :get
-  match '/journals/edit/:id', :to => 'journals#edit', :id => /\d+/, :via => [:get, :post]
+  resources :journals, :only => [:edit, :update] do
+    member do
+      get 'diff'
+    end
+  end
 
   get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt'
   get '/issues/gantt', :to => 'gantts#show'
index a7e29c8918e3696c5c96040b0db1ce889f969a1a..d797a017c80863d1099753b29d7c6c125f592d28 100644 (file)
@@ -105,8 +105,8 @@ Redmine::AccessControl.map do |map|
     map.permission :set_issues_private, {}
     map.permission :set_own_issues_private, {}, :require => :loggedin
     map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
-    map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
-    map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
+    map.permission :edit_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
+    map.permission :edit_own_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
     map.permission :view_private_notes, {}, :read => true, :require => :member
     map.permission :set_notes_private, {}, :require => :member
     map.permission :delete_issues, {:issues => :destroy}, :require => :member
index c82d2e58851bceec328834cbbc0eece884b90659..cc1446c7a4a203aefadaffb2de34c9d03e2ca067 100644 (file)
@@ -199,7 +199,7 @@ class JournalsControllerTest < ActionController::TestCase
 
   def test_update_xhr
     @request.session[:user_id] = 1
-    xhr :post, :edit, :id => 2, :notes => 'Updated notes'
+    xhr :post, :update, :id => 2, :notes => 'Updated notes'
     assert_response :success
     assert_template 'update'
     assert_equal 'text/javascript', response.content_type
@@ -210,7 +210,7 @@ class JournalsControllerTest < ActionController::TestCase
   def test_update_xhr_with_empty_notes_should_delete_the_journal
     @request.session[:user_id] = 1
     assert_difference 'Journal.count', -1 do
-      xhr :post, :edit, :id => 2, :notes => ''
+      xhr :post, :update, :id => 2, :notes => ''
       assert_response :success
       assert_template 'update'
       assert_equal 'text/javascript', response.content_type
index c0bcf0ea342564fe179382e6af79b45b60297d07..33e161e35c381b0f5224b7e45d01d21ea8def118 100644 (file)
@@ -21,9 +21,9 @@ class RoutingJournalsTest < Redmine::RoutingTest
   def test_journals
     should_route 'POST /issues/1/quoted' => 'journals#new', :id => '1'
     should_route 'GET /issues/changes' => 'journals#index'
-    should_route 'GET /journals/diff/1' => 'journals#diff', :id => '1'
+    should_route 'GET /journals/1/diff' => 'journals#diff', :id => '1'
 
-    should_route 'GET /journals/edit/1' => 'journals#edit', :id => '1'
-    should_route 'POST /journals/edit/1' => 'journals#edit', :id => '1'
+    should_route 'GET /journals/1/edit' => 'journals#edit', :id => '1'
+    should_route 'PUT /journals/1' => 'journals#update', :id => '1'
   end
 end
index f3742c2b5e3777ad2762f9d44de4ec491b73db89..8de5bfe563da0564b2f013afbf188425cc86f080 100644 (file)
@@ -68,7 +68,7 @@ class MailerTest < ActiveSupport::TestCase
                     # should be https://mydomain.foo/journals/diff/3?detail_id=4
                     # but the Rails 4.2 DOM assertion doesn't handle the ? in the
                     # attribute value
-                    'https://mydomain.foo/journals/diff/3',
+                    'https://mydomain.foo/journals/3/diff',
                     'View differences',
                     :text => 'diff'
       # link to an attachment
@@ -109,7 +109,7 @@ class MailerTest < ActiveSupport::TestCase
                     # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
                     # but the Rails 4.2 DOM assertion doesn't handle the ? in the
                     # attribute value
-                    'http://mydomain.foo/rdm/journals/diff/3',
+                    'http://mydomain.foo/rdm/journals/3/diff',
                     'View differences',
                     :text => 'diff'
       # link to an attachment
@@ -179,7 +179,7 @@ class MailerTest < ActiveSupport::TestCase
                     # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
                     # but the Rails 4.2 DOM assertion doesn't handle the ? in the
                     # attribute value
-                    'http://mydomain.foo/rdm/journals/diff/3',
+                    'http://mydomain.foo/rdm/journals/3/diff',
                     'View differences',
                     :text => 'diff'
       # link to an attachment