##// END OF EJS Templates
Merged r5021 from trunk....
Jean-Philippe Lang -
r4902:465534a2989d
parent child
Show More
@@ -1,105 +1,106
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 before_filter :authorize, :only => [:new, :edit]
23 accept_key_auth :index
23 accept_key_auth :index
24
24
25 helper :issues
25 helper :issues
26 helper :custom_fields
26 helper :queries
27 helper :queries
27 include QueriesHelper
28 include QueriesHelper
28 helper :sort
29 helper :sort
29 include SortHelper
30 include SortHelper
30
31
31 def index
32 def index
32 retrieve_query
33 retrieve_query
33 sort_init 'id', 'desc'
34 sort_init 'id', 'desc'
34 sort_update(@query.sortable_columns)
35 sort_update(@query.sortable_columns)
35
36
36 if @query.valid?
37 if @query.valid?
37 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
38 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
38 :limit => 25)
39 :limit => 25)
39 end
40 end
40 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
41 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
41 render :layout => false, :content_type => 'application/atom+xml'
42 render :layout => false, :content_type => 'application/atom+xml'
42 rescue ActiveRecord::RecordNotFound
43 rescue ActiveRecord::RecordNotFound
43 render_404
44 render_404
44 end
45 end
45
46
46 def new
47 def new
47 journal = Journal.find(params[:journal_id]) if params[:journal_id]
48 journal = Journal.find(params[:journal_id]) if params[:journal_id]
48 if journal
49 if journal
49 user = journal.user
50 user = journal.user
50 text = journal.notes
51 text = journal.notes
51 else
52 else
52 user = @issue.author
53 user = @issue.author
53 text = @issue.description
54 text = @issue.description
54 end
55 end
55 # Replaces pre blocks with [...]
56 # Replaces pre blocks with [...]
56 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
57 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
57 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
58 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
58 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
59 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
59
60
60 render(:update) { |page|
61 render(:update) { |page|
61 page.<< "$('notes').value = \"#{escape_javascript content}\";"
62 page.<< "$('notes').value = \"#{escape_javascript content}\";"
62 page.show 'update'
63 page.show 'update'
63 page << "Form.Element.focus('notes');"
64 page << "Form.Element.focus('notes');"
64 page << "Element.scrollTo('update');"
65 page << "Element.scrollTo('update');"
65 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
66 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
66 }
67 }
67 end
68 end
68
69
69 def edit
70 def edit
70 if request.post?
71 if request.post?
71 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
72 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
72 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
73 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
73 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
74 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
74 respond_to do |format|
75 respond_to do |format|
75 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
76 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
76 format.js { render :action => 'update' }
77 format.js { render :action => 'update' }
77 end
78 end
78 else
79 else
79 respond_to do |format|
80 respond_to do |format|
80 format.html {
81 format.html {
81 # TODO: implement non-JS journal update
82 # TODO: implement non-JS journal update
82 render :nothing => true
83 render :nothing => true
83 }
84 }
84 format.js
85 format.js
85 end
86 end
86 end
87 end
87 end
88 end
88
89
89 private
90 private
90 def find_journal
91 def find_journal
91 @journal = Journal.find(params[:id])
92 @journal = Journal.find(params[:id])
92 (render_403; return false) unless @journal.editable_by?(User.current)
93 (render_403; return false) unless @journal.editable_by?(User.current)
93 @project = @journal.journalized.project
94 @project = @journal.journalized.project
94 rescue ActiveRecord::RecordNotFound
95 rescue ActiveRecord::RecordNotFound
95 render_404
96 render_404
96 end
97 end
97
98
98 # TODO: duplicated in IssuesController
99 # TODO: duplicated in IssuesController
99 def find_issue
100 def find_issue
100 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
101 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
101 @project = @issue.project
102 @project = @issue.project
102 rescue ActiveRecord::RecordNotFound
103 rescue ActiveRecord::RecordNotFound
103 render_404
104 render_404
104 end
105 end
105 end
106 end
@@ -1,22 +1,29
1 ---
1 ---
2 journal_details_001:
2 journal_details_001:
3 old_value: "1"
3 old_value: "1"
4 property: attr
4 property: attr
5 id: 1
5 id: 1
6 value: "2"
6 value: "2"
7 prop_key: status_id
7 prop_key: status_id
8 journal_id: 1
8 journal_id: 1
9 journal_details_002:
9 journal_details_002:
10 old_value: "40"
10 old_value: "40"
11 property: attr
11 property: attr
12 id: 2
12 id: 2
13 value: "30"
13 value: "30"
14 prop_key: done_ratio
14 prop_key: done_ratio
15 journal_id: 1
15 journal_id: 1
16 journal_details_003:
16 journal_details_003:
17 old_value: nil
17 old_value: nil
18 property: attr
18 property: attr
19 id: 3
19 id: 3
20 value: "6"
20 value: "6"
21 prop_key: fixed_version_id
21 prop_key: fixed_version_id
22 journal_id: 4
22 journal_id: 4
23 journal_details_005:
24 old_value: Old value
25 property: cf
26 id: 5
27 value: New value
28 prop_key: 2
29 journal_id: 3
@@ -1,86 +1,87
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 :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects
26
27
27 def setup
28 def setup
28 @controller = JournalsController.new
29 @controller = JournalsController.new
29 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
31 User.current = nil
32 User.current = nil
32 end
33 end
33
34
34 def test_index
35 def test_index
35 get :index, :project_id => 1
36 get :index, :project_id => 1
36 assert_response :success
37 assert_response :success
37 assert_not_nil assigns(:journals)
38 assert_not_nil assigns(:journals)
38 assert_equal 'application/atom+xml', @response.content_type
39 assert_equal 'application/atom+xml', @response.content_type
39 end
40 end
40
41
41 def test_reply_to_issue
42 def test_reply_to_issue
42 @request.session[:user_id] = 2
43 @request.session[:user_id] = 2
43 get :new, :id => 6
44 get :new, :id => 6
44 assert_response :success
45 assert_response :success
45 assert_select_rjs :show, "update"
46 assert_select_rjs :show, "update"
46 end
47 end
47
48
48 def test_reply_to_issue_without_permission
49 def test_reply_to_issue_without_permission
49 @request.session[:user_id] = 7
50 @request.session[:user_id] = 7
50 get :new, :id => 6
51 get :new, :id => 6
51 assert_response 403
52 assert_response 403
52 end
53 end
53
54
54 def test_reply_to_note
55 def test_reply_to_note
55 @request.session[:user_id] = 2
56 @request.session[:user_id] = 2
56 get :new, :id => 6, :journal_id => 4
57 get :new, :id => 6, :journal_id => 4
57 assert_response :success
58 assert_response :success
58 assert_select_rjs :show, "update"
59 assert_select_rjs :show, "update"
59 end
60 end
60
61
61 def test_get_edit
62 def test_get_edit
62 @request.session[:user_id] = 1
63 @request.session[:user_id] = 1
63 xhr :get, :edit, :id => 2
64 xhr :get, :edit, :id => 2
64 assert_response :success
65 assert_response :success
65 assert_select_rjs :insert, :after, 'journal-2-notes' do
66 assert_select_rjs :insert, :after, 'journal-2-notes' do
66 assert_select 'form[id=journal-2-form]'
67 assert_select 'form[id=journal-2-form]'
67 assert_select 'textarea'
68 assert_select 'textarea'
68 end
69 end
69 end
70 end
70
71
71 def test_post_edit
72 def test_post_edit
72 @request.session[:user_id] = 1
73 @request.session[:user_id] = 1
73 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
74 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
74 assert_response :success
75 assert_response :success
75 assert_select_rjs :replace, 'journal-2-notes'
76 assert_select_rjs :replace, 'journal-2-notes'
76 assert_equal 'Updated notes', Journal.find(2).notes
77 assert_equal 'Updated notes', Journal.find(2).notes
77 end
78 end
78
79
79 def test_post_edit_with_empty_notes
80 def test_post_edit_with_empty_notes
80 @request.session[:user_id] = 1
81 @request.session[:user_id] = 1
81 xhr :post, :edit, :id => 2, :notes => ''
82 xhr :post, :edit, :id => 2, :notes => ''
82 assert_response :success
83 assert_response :success
83 assert_select_rjs :remove, 'change-2'
84 assert_select_rjs :remove, 'change-2'
84 assert_nil Journal.find_by_id(2)
85 assert_nil Journal.find_by_id(2)
85 end
86 end
86 end
87 end
General Comments 0
You need to be logged in to leave comments. Login now