##// END OF EJS Templates
Fixes a data disclosure issue introduced in r3941....
Jean-Philippe Lang -
r4421:93847ae33740
parent child
Show More
@@ -1,96 +1,97
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
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]
19 before_filter :find_journal, :only => [:edit]
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]
22 accept_key_auth :index
23 accept_key_auth :index
23
24
24 helper :issues
25 helper :issues
25 helper :queries
26 helper :queries
26 include QueriesHelper
27 include QueriesHelper
27 helper :sort
28 helper :sort
28 include SortHelper
29 include SortHelper
29
30
30 def index
31 def index
31 retrieve_query
32 retrieve_query
32 sort_init 'id', 'desc'
33 sort_init 'id', 'desc'
33 sort_update(@query.sortable_columns)
34 sort_update(@query.sortable_columns)
34
35
35 if @query.valid?
36 if @query.valid?
36 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
37 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
37 :limit => 25)
38 :limit => 25)
38 end
39 end
39 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
40 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
40 render :layout => false, :content_type => 'application/atom+xml'
41 render :layout => false, :content_type => 'application/atom+xml'
41 rescue ActiveRecord::RecordNotFound
42 rescue ActiveRecord::RecordNotFound
42 render_404
43 render_404
43 end
44 end
44
45
45 def new
46 def new
46 journal = Journal.find(params[:journal_id]) if params[:journal_id]
47 journal = Journal.find(params[:journal_id]) if params[:journal_id]
47 if journal
48 if journal
48 user = journal.user
49 user = journal.user
49 text = journal.notes
50 text = journal.notes
50 else
51 else
51 user = @issue.author
52 user = @issue.author
52 text = @issue.description
53 text = @issue.description
53 end
54 end
54 # Replaces pre blocks with [...]
55 # Replaces pre blocks with [...]
55 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
56 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
56 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
57 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
57 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
58 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
58
59
59 render(:update) { |page|
60 render(:update) { |page|
60 page.<< "$('notes').value = \"#{escape_javascript content}\";"
61 page.<< "$('notes').value = \"#{escape_javascript content}\";"
61 page.show 'update'
62 page.show 'update'
62 page << "Form.Element.focus('notes');"
63 page << "Form.Element.focus('notes');"
63 page << "Element.scrollTo('update');"
64 page << "Element.scrollTo('update');"
64 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
65 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
65 }
66 }
66 end
67 end
67
68
68 def edit
69 def edit
69 if request.post?
70 if request.post?
70 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
71 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
71 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
72 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
72 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
73 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
73 respond_to do |format|
74 respond_to do |format|
74 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
75 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
75 format.js { render :action => 'update' }
76 format.js { render :action => 'update' }
76 end
77 end
77 end
78 end
78 end
79 end
79
80
80 private
81 private
81 def find_journal
82 def find_journal
82 @journal = Journal.find(params[:id])
83 @journal = Journal.find(params[:id])
83 (render_403; return false) unless @journal.editable_by?(User.current)
84 (render_403; return false) unless @journal.editable_by?(User.current)
84 @project = @journal.journalized.project
85 @project = @journal.journalized.project
85 rescue ActiveRecord::RecordNotFound
86 rescue ActiveRecord::RecordNotFound
86 render_404
87 render_404
87 end
88 end
88
89
89 # TODO: duplicated in IssuesController
90 # TODO: duplicated in IssuesController
90 def find_issue
91 def find_issue
91 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
92 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
92 @project = @issue.project
93 @project = @issue.project
93 rescue ActiveRecord::RecordNotFound
94 rescue ActiveRecord::RecordNotFound
94 render_404
95 render_404
95 end
96 end
96 end
97 end
@@ -1,80 +1,86
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
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 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'journals_controller'
19 require 'journals_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class JournalsController; def rescue_action(e) raise e end; end
22 class JournalsController; def rescue_action(e) raise e end; end
23
23
24 class JournalsControllerTest < ActionController::TestCase
24 class JournalsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules
25 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules
26
26
27 def setup
27 def setup
28 @controller = JournalsController.new
28 @controller = JournalsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_index
34 def test_index
35 get :index, :project_id => 1
35 get :index, :project_id => 1
36 assert_response :success
36 assert_response :success
37 assert_not_nil assigns(:journals)
37 assert_not_nil assigns(:journals)
38 assert_equal 'application/atom+xml', @response.content_type
38 assert_equal 'application/atom+xml', @response.content_type
39 end
39 end
40
40
41 def test_reply_to_issue
41 def test_reply_to_issue
42 @request.session[:user_id] = 2
42 @request.session[:user_id] = 2
43 get :new, :id => 1
43 get :new, :id => 6
44 assert_response :success
44 assert_response :success
45 assert_select_rjs :show, "update"
45 assert_select_rjs :show, "update"
46 end
46 end
47
48 def test_reply_to_issue_without_permission
49 @request.session[:user_id] = 7
50 get :new, :id => 6
51 assert_response 403
52 end
47
53
48 def test_reply_to_note
54 def test_reply_to_note
49 @request.session[:user_id] = 2
55 @request.session[:user_id] = 2
50 get :new, :id => 1, :journal_id => 2
56 get :new, :id => 6, :journal_id => 4
51 assert_response :success
57 assert_response :success
52 assert_select_rjs :show, "update"
58 assert_select_rjs :show, "update"
53 end
59 end
54
60
55 def test_get_edit
61 def test_get_edit
56 @request.session[:user_id] = 1
62 @request.session[:user_id] = 1
57 xhr :get, :edit, :id => 2
63 xhr :get, :edit, :id => 2
58 assert_response :success
64 assert_response :success
59 assert_select_rjs :insert, :after, 'journal-2-notes' do
65 assert_select_rjs :insert, :after, 'journal-2-notes' do
60 assert_select 'form[id=journal-2-form]'
66 assert_select 'form[id=journal-2-form]'
61 assert_select 'textarea'
67 assert_select 'textarea'
62 end
68 end
63 end
69 end
64
70
65 def test_post_edit
71 def test_post_edit
66 @request.session[:user_id] = 1
72 @request.session[:user_id] = 1
67 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
73 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
68 assert_response :success
74 assert_response :success
69 assert_select_rjs :replace, 'journal-2-notes'
75 assert_select_rjs :replace, 'journal-2-notes'
70 assert_equal 'Updated notes', Journal.find(2).notes
76 assert_equal 'Updated notes', Journal.find(2).notes
71 end
77 end
72
78
73 def test_post_edit_with_empty_notes
79 def test_post_edit_with_empty_notes
74 @request.session[:user_id] = 1
80 @request.session[:user_id] = 1
75 xhr :post, :edit, :id => 2, :notes => ''
81 xhr :post, :edit, :id => 2, :notes => ''
76 assert_response :success
82 assert_response :success
77 assert_select_rjs :remove, 'change-2'
83 assert_select_rjs :remove, 'change-2'
78 assert_nil Journal.find_by_id(2)
84 assert_nil Journal.find_by_id(2)
79 end
85 end
80 end
86 end
General Comments 0
You need to be logged in to leave comments. Login now