##// END OF EJS Templates
Use regular edit/update actions and named routes for JournalsController....
Jean-Philippe Lang -
r14692:6bb1ea8ae8a1
parent child
Show More
@@ -16,10 +16,10
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class JournalsController < ApplicationController
18 class JournalsController < ApplicationController
19 before_filter :find_journal, :only => [:edit, :diff]
19 before_filter :find_journal, :only => [:edit, :update, :diff]
20 before_filter :find_issue, :only => [:new]
20 before_filter :find_issue, :only => [:new]
21 before_filter :find_optional_project, :only => [:index]
21 before_filter :find_optional_project, :only => [:index]
22 before_filter :authorize, :only => [:new, :edit, :diff]
22 before_filter :authorize, :only => [:new, :edit, :update, :diff]
23 accept_rss_auth :index
23 accept_rss_auth :index
24 menu_item :issues
24 menu_item :issues
25
25
@@ -82,19 +82,20 class JournalsController < ApplicationController
82
82
83 def edit
83 def edit
84 (render_403; return false) unless @journal.editable_by?(User.current)
84 (render_403; return false) unless @journal.editable_by?(User.current)
85 if request.post?
85 respond_to do |format|
86 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
86 # TODO: implement non-JS journal update
87 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
87 format.js
88 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
88 end
89 respond_to do |format|
89 end
90 format.html { redirect_to issue_path(@journal.journalized) }
90
91 format.js { render :action => 'update' }
91 def update
92 end
92 (render_403; return false) unless @journal.editable_by?(User.current)
93 else
93 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
94 respond_to do |format|
94 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
95 # TODO: implement non-JS journal update
95 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
96 format.js
96 respond_to do |format|
97 end
97 format.html { redirect_to issue_path(@journal.journalized) }
98 format.js
98 end
99 end
99 end
100 end
100
101
@@ -456,8 +456,7 module IssuesHelper
456 s = l(:text_journal_changed_no_detail, :label => label)
456 s = l(:text_journal_changed_no_detail, :label => label)
457 unless no_html
457 unless no_html
458 diff_link = link_to 'diff',
458 diff_link = link_to 'diff',
459 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
459 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
460 :detail_id => detail.id, :only_path => options[:only_path]},
461 :title => l(:label_view_diff)
460 :title => l(:label_view_diff)
462 s << " (#{ diff_link })"
461 s << " (#{ diff_link })"
463 end
462 end
@@ -31,23 +31,23 module JournalsHelper
31 links = []
31 links = []
32 if !journal.notes.blank?
32 if !journal.notes.blank?
33 links << link_to('',
33 links << link_to('',
34 {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal},
34 quoted_issue_path(issue, :journal_id => journal),
35 :remote => true,
35 :remote => true,
36 :method => 'post',
36 :method => 'post',
37 :title => l(:button_quote),
37 :title => l(:button_quote),
38 :class => 'icon-only icon-comment'
38 :class => 'icon-only icon-comment'
39 ) if options[:reply_links]
39 ) if options[:reply_links]
40 links << link_to('',
40 links << link_to('',
41 {:controller => 'journals', :action => 'edit', :id => journal},
41 edit_journal_path(journal),
42 :remote => true,
42 :remote => true,
43 :method => 'get',
43 :method => 'get',
44 :title => l(:button_edit),
44 :title => l(:button_edit),
45 :class => 'icon-only icon-edit'
45 :class => 'icon-only icon-edit'
46 ) if editable
46 ) if editable
47 links << link_to('',
47 links << link_to('',
48 {:controller => 'journals', :action => 'edit', :id => journal, :notes => ""},
48 journal_path(journal, :notes => ""),
49 :remote => true,
49 :remote => true,
50 :method => :post, :data => {:confirm => l(:text_are_you_sure)},
50 :method => 'put', :data => {:confirm => l(:text_are_you_sure)},
51 :title => l(:button_delete),
51 :title => l(:button_delete),
52 :class => 'icon-only icon-del'
52 :class => 'icon-only icon-del'
53 ) if editable
53 ) if editable
@@ -1,5 +1,6
1 <%= form_tag({:controller => 'journals', :action => 'edit', :id => @journal},
1 <%= form_tag(journal_path(@journal),
2 :remote => true,
2 :remote => true,
3 :method => 'put',
3 :id => "journal-#{@journal.id}-form") do %>
4 :id => "journal-#{@journal.id}-form") do %>
4 <%= label_tag "notes", l(:description_notes), :class => "hidden-for-sighted" %>
5 <%= label_tag "notes", l(:description_notes), :class => "hidden-for-sighted" %>
5 <%= text_area_tag :notes, @journal.notes,
6 <%= text_area_tag :notes, @journal.notes,
@@ -49,8 +49,11 Rails.application.routes.draw do
49 match '/issues/changes', :to => 'journals#index', :as => 'issue_changes', :via => :get
49 match '/issues/changes', :to => 'journals#index', :as => 'issue_changes', :via => :get
50 match '/issues/:id/quoted', :to => 'journals#new', :id => /\d+/, :via => :post, :as => 'quoted_issue'
50 match '/issues/:id/quoted', :to => 'journals#new', :id => /\d+/, :via => :post, :as => 'quoted_issue'
51
51
52 match '/journals/diff/:id', :to => 'journals#diff', :id => /\d+/, :via => :get
52 resources :journals, :only => [:edit, :update] do
53 match '/journals/edit/:id', :to => 'journals#edit', :id => /\d+/, :via => [:get, :post]
53 member do
54 get 'diff'
55 end
56 end
54
57
55 get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt'
58 get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt'
56 get '/issues/gantt', :to => 'gantts#show'
59 get '/issues/gantt', :to => 'gantts#show'
@@ -105,8 +105,8 Redmine::AccessControl.map do |map|
105 map.permission :set_issues_private, {}
105 map.permission :set_issues_private, {}
106 map.permission :set_own_issues_private, {}, :require => :loggedin
106 map.permission :set_own_issues_private, {}, :require => :loggedin
107 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
107 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
108 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
108 map.permission :edit_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
109 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
109 map.permission :edit_own_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
110 map.permission :view_private_notes, {}, :read => true, :require => :member
110 map.permission :view_private_notes, {}, :read => true, :require => :member
111 map.permission :set_notes_private, {}, :require => :member
111 map.permission :set_notes_private, {}, :require => :member
112 map.permission :delete_issues, {:issues => :destroy}, :require => :member
112 map.permission :delete_issues, {:issues => :destroy}, :require => :member
@@ -199,7 +199,7 class JournalsControllerTest < ActionController::TestCase
199
199
200 def test_update_xhr
200 def test_update_xhr
201 @request.session[:user_id] = 1
201 @request.session[:user_id] = 1
202 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
202 xhr :post, :update, :id => 2, :notes => 'Updated notes'
203 assert_response :success
203 assert_response :success
204 assert_template 'update'
204 assert_template 'update'
205 assert_equal 'text/javascript', response.content_type
205 assert_equal 'text/javascript', response.content_type
@@ -210,7 +210,7 class JournalsControllerTest < ActionController::TestCase
210 def test_update_xhr_with_empty_notes_should_delete_the_journal
210 def test_update_xhr_with_empty_notes_should_delete_the_journal
211 @request.session[:user_id] = 1
211 @request.session[:user_id] = 1
212 assert_difference 'Journal.count', -1 do
212 assert_difference 'Journal.count', -1 do
213 xhr :post, :edit, :id => 2, :notes => ''
213 xhr :post, :update, :id => 2, :notes => ''
214 assert_response :success
214 assert_response :success
215 assert_template 'update'
215 assert_template 'update'
216 assert_equal 'text/javascript', response.content_type
216 assert_equal 'text/javascript', response.content_type
@@ -21,9 +21,9 class RoutingJournalsTest < Redmine::RoutingTest
21 def test_journals
21 def test_journals
22 should_route 'POST /issues/1/quoted' => 'journals#new', :id => '1'
22 should_route 'POST /issues/1/quoted' => 'journals#new', :id => '1'
23 should_route 'GET /issues/changes' => 'journals#index'
23 should_route 'GET /issues/changes' => 'journals#index'
24 should_route 'GET /journals/diff/1' => 'journals#diff', :id => '1'
24 should_route 'GET /journals/1/diff' => 'journals#diff', :id => '1'
25
25
26 should_route 'GET /journals/edit/1' => 'journals#edit', :id => '1'
26 should_route 'GET /journals/1/edit' => 'journals#edit', :id => '1'
27 should_route 'POST /journals/edit/1' => 'journals#edit', :id => '1'
27 should_route 'PUT /journals/1' => 'journals#update', :id => '1'
28 end
28 end
29 end
29 end
@@ -68,7 +68,7 class MailerTest < ActiveSupport::TestCase
68 # should be https://mydomain.foo/journals/diff/3?detail_id=4
68 # should be https://mydomain.foo/journals/diff/3?detail_id=4
69 # but the Rails 4.2 DOM assertion doesn't handle the ? in the
69 # but the Rails 4.2 DOM assertion doesn't handle the ? in the
70 # attribute value
70 # attribute value
71 'https://mydomain.foo/journals/diff/3',
71 'https://mydomain.foo/journals/3/diff',
72 'View differences',
72 'View differences',
73 :text => 'diff'
73 :text => 'diff'
74 # link to an attachment
74 # link to an attachment
@@ -109,7 +109,7 class MailerTest < ActiveSupport::TestCase
109 # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
109 # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
110 # but the Rails 4.2 DOM assertion doesn't handle the ? in the
110 # but the Rails 4.2 DOM assertion doesn't handle the ? in the
111 # attribute value
111 # attribute value
112 'http://mydomain.foo/rdm/journals/diff/3',
112 'http://mydomain.foo/rdm/journals/3/diff',
113 'View differences',
113 'View differences',
114 :text => 'diff'
114 :text => 'diff'
115 # link to an attachment
115 # link to an attachment
@@ -179,7 +179,7 class MailerTest < ActiveSupport::TestCase
179 # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
179 # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
180 # but the Rails 4.2 DOM assertion doesn't handle the ? in the
180 # but the Rails 4.2 DOM assertion doesn't handle the ? in the
181 # attribute value
181 # attribute value
182 'http://mydomain.foo/rdm/journals/diff/3',
182 'http://mydomain.foo/rdm/journals/3/diff',
183 'View differences',
183 'View differences',
184 :text => 'diff'
184 :text => 'diff'
185 # link to an attachment
185 # link to an attachment
General Comments 0
You need to be logged in to leave comments. Login now