@@ -1,104 +1,101 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class JournalsController < ApplicationController |
|
19 | 19 | before_filter :find_journal, :only => [:edit, :diff] |
|
20 | 20 | before_filter :find_issue, :only => [:new] |
|
21 | 21 | before_filter :find_optional_project, :only => [:index] |
|
22 | 22 | before_filter :authorize, :only => [:new, :edit, :diff] |
|
23 | 23 | accept_rss_auth :index |
|
24 | 24 | menu_item :issues |
|
25 | 25 | |
|
26 | 26 | helper :issues |
|
27 | 27 | helper :custom_fields |
|
28 | 28 | helper :queries |
|
29 | 29 | include QueriesHelper |
|
30 | 30 | helper :sort |
|
31 | 31 | include SortHelper |
|
32 | 32 | |
|
33 | 33 | def index |
|
34 | 34 | retrieve_query |
|
35 | 35 | sort_init 'id', 'desc' |
|
36 | 36 | sort_update(@query.sortable_columns) |
|
37 | 37 | if @query.valid? |
|
38 | 38 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
39 | 39 | :limit => 25) |
|
40 | 40 | end |
|
41 | 41 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
42 | 42 | render :layout => false, :content_type => 'application/atom+xml' |
|
43 | 43 | rescue ActiveRecord::RecordNotFound |
|
44 | 44 | render_404 |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def diff |
|
48 | 48 | @issue = @journal.issue |
|
49 | 49 | if params[:detail_id].present? |
|
50 | 50 | @detail = @journal.details.find_by_id(params[:detail_id]) |
|
51 | 51 | else |
|
52 | 52 | @detail = @journal.details.detect {|d| d.prop_key == 'description'} |
|
53 | 53 | end |
|
54 | 54 | (render_404; return false) unless @issue && @detail |
|
55 | 55 | @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value) |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def new |
|
59 | 59 | @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id] |
|
60 | 60 | if @journal |
|
61 | 61 | user = @journal.user |
|
62 | 62 | text = @journal.notes |
|
63 | 63 | else |
|
64 | 64 | user = @issue.author |
|
65 | 65 | text = @issue.description |
|
66 | 66 | end |
|
67 | 67 | # Replaces pre blocks with [...] |
|
68 | 68 | text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]') |
|
69 | 69 | @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " |
|
70 | 70 | @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" |
|
71 | 71 | rescue ActiveRecord::RecordNotFound |
|
72 | 72 | render_404 |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def edit |
|
76 | 76 | (render_403; return false) unless @journal.editable_by?(User.current) |
|
77 | 77 | if request.post? |
|
78 | 78 | @journal.update_attributes(:notes => params[:notes]) if params[:notes] |
|
79 | 79 | @journal.destroy if @journal.details.empty? && @journal.notes.blank? |
|
80 | 80 | call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) |
|
81 | 81 | respond_to do |format| |
|
82 | 82 | format.html { redirect_to issue_path(@journal.journalized) } |
|
83 | 83 | format.js { render :action => 'update' } |
|
84 | 84 | end |
|
85 | 85 | else |
|
86 | 86 | respond_to do |format| |
|
87 | format.html { | |
|
88 | # TODO: implement non-JS journal update | |
|
89 | render :nothing => true | |
|
90 | } | |
|
87 | # TODO: implement non-JS journal update | |
|
91 | 88 | format.js |
|
92 | 89 | end |
|
93 | 90 | end |
|
94 | 91 | end |
|
95 | 92 | |
|
96 | 93 | private |
|
97 | 94 | |
|
98 | 95 | def find_journal |
|
99 | 96 | @journal = Journal.visible.find(params[:id]) |
|
100 | 97 | @project = @journal.journalized.project |
|
101 | 98 | rescue ActiveRecord::RecordNotFound |
|
102 | 99 | render_404 |
|
103 | 100 | end |
|
104 | 101 | end |
@@ -1,143 +1,157 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class JournalsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules, |
|
22 | 22 | :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects |
|
23 | 23 | |
|
24 | 24 | def setup |
|
25 | 25 | User.current = nil |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_index |
|
29 | 29 | get :index, :project_id => 1 |
|
30 | 30 | assert_response :success |
|
31 | 31 | assert_not_nil assigns(:journals) |
|
32 | 32 | assert_equal 'application/atom+xml', @response.content_type |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | def test_index_with_invalid_query_id | |
|
36 | get :index, :project_id => 1, :query_id => 999 | |
|
37 | assert_response 404 | |
|
38 | end | |
|
39 | ||
|
35 | 40 | def test_index_should_return_privates_notes_with_permission_only |
|
36 | 41 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
|
37 | 42 | @request.session[:user_id] = 2 |
|
38 | 43 | |
|
39 | 44 | get :index, :project_id => 1 |
|
40 | 45 | assert_response :success |
|
41 | 46 | assert_include journal, assigns(:journals) |
|
42 | 47 | |
|
43 | 48 | Role.find(1).remove_permission! :view_private_notes |
|
44 | 49 | get :index, :project_id => 1 |
|
45 | 50 | assert_response :success |
|
46 | 51 | assert_not_include journal, assigns(:journals) |
|
47 | 52 | end |
|
48 | 53 | |
|
49 | 54 | def test_diff |
|
50 | 55 | get :diff, :id => 3, :detail_id => 4 |
|
51 | 56 | assert_response :success |
|
52 | 57 | assert_template 'diff' |
|
53 | 58 | |
|
54 | 59 | assert_select 'span.diff_out', :text => /removed/ |
|
55 | 60 | assert_select 'span.diff_in', :text => /added/ |
|
56 | 61 | end |
|
57 | 62 | |
|
63 | def test_diff_should_default_to_description_diff | |
|
64 | get :diff, :id => 3 | |
|
65 | assert_response :success | |
|
66 | assert_template 'diff' | |
|
67 | ||
|
68 | assert_select 'span.diff_out', :text => /removed/ | |
|
69 | assert_select 'span.diff_in', :text => /added/ | |
|
70 | end | |
|
71 | ||
|
58 | 72 | def test_reply_to_issue |
|
59 | 73 | @request.session[:user_id] = 2 |
|
60 | 74 | xhr :get, :new, :id => 6 |
|
61 | 75 | assert_response :success |
|
62 | 76 | assert_template 'new' |
|
63 | 77 | assert_equal 'text/javascript', response.content_type |
|
64 | 78 | assert_include '> This is an issue', response.body |
|
65 | 79 | end |
|
66 | 80 | |
|
67 | 81 | def test_reply_to_issue_without_permission |
|
68 | 82 | @request.session[:user_id] = 7 |
|
69 | 83 | xhr :get, :new, :id => 6 |
|
70 | 84 | assert_response 403 |
|
71 | 85 | end |
|
72 | 86 | |
|
73 | 87 | def test_reply_to_note |
|
74 | 88 | @request.session[:user_id] = 2 |
|
75 | 89 | xhr :get, :new, :id => 6, :journal_id => 4 |
|
76 | 90 | assert_response :success |
|
77 | 91 | assert_template 'new' |
|
78 | 92 | assert_equal 'text/javascript', response.content_type |
|
79 | 93 | assert_include '> A comment with a private version', response.body |
|
80 | 94 | end |
|
81 | 95 | |
|
82 | 96 | def test_reply_to_private_note_should_fail_without_permission |
|
83 | 97 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true) |
|
84 | 98 | @request.session[:user_id] = 2 |
|
85 | 99 | |
|
86 | 100 | xhr :get, :new, :id => 2, :journal_id => journal.id |
|
87 | 101 | assert_response :success |
|
88 | 102 | assert_template 'new' |
|
89 | 103 | assert_equal 'text/javascript', response.content_type |
|
90 | 104 | assert_include '> Privates notes', response.body |
|
91 | 105 | |
|
92 | 106 | Role.find(1).remove_permission! :view_private_notes |
|
93 | 107 | xhr :get, :new, :id => 2, :journal_id => journal.id |
|
94 | 108 | assert_response 404 |
|
95 | 109 | end |
|
96 | 110 | |
|
97 | 111 | def test_edit_xhr |
|
98 | 112 | @request.session[:user_id] = 1 |
|
99 | 113 | xhr :get, :edit, :id => 2 |
|
100 | 114 | assert_response :success |
|
101 | 115 | assert_template 'edit' |
|
102 | 116 | assert_equal 'text/javascript', response.content_type |
|
103 | 117 | assert_include 'textarea', response.body |
|
104 | 118 | end |
|
105 | 119 | |
|
106 | 120 | def test_edit_private_note_should_fail_without_permission |
|
107 | 121 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true) |
|
108 | 122 | @request.session[:user_id] = 2 |
|
109 | 123 | Role.find(1).add_permission! :edit_issue_notes |
|
110 | 124 | |
|
111 | 125 | xhr :get, :edit, :id => journal.id |
|
112 | 126 | assert_response :success |
|
113 | 127 | assert_template 'edit' |
|
114 | 128 | assert_equal 'text/javascript', response.content_type |
|
115 | 129 | assert_include 'textarea', response.body |
|
116 | 130 | |
|
117 | 131 | Role.find(1).remove_permission! :view_private_notes |
|
118 | 132 | xhr :get, :edit, :id => journal.id |
|
119 | 133 | assert_response 404 |
|
120 | 134 | end |
|
121 | 135 | |
|
122 | 136 | def test_update_xhr |
|
123 | 137 | @request.session[:user_id] = 1 |
|
124 | 138 | xhr :post, :edit, :id => 2, :notes => 'Updated notes' |
|
125 | 139 | assert_response :success |
|
126 | 140 | assert_template 'update' |
|
127 | 141 | assert_equal 'text/javascript', response.content_type |
|
128 | 142 | assert_equal 'Updated notes', Journal.find(2).notes |
|
129 | 143 | assert_include 'journal-2-notes', response.body |
|
130 | 144 | end |
|
131 | 145 | |
|
132 | 146 | def test_update_xhr_with_empty_notes_should_delete_the_journal |
|
133 | 147 | @request.session[:user_id] = 1 |
|
134 | 148 | assert_difference 'Journal.count', -1 do |
|
135 | 149 | xhr :post, :edit, :id => 2, :notes => '' |
|
136 | 150 | assert_response :success |
|
137 | 151 | assert_template 'update' |
|
138 | 152 | assert_equal 'text/javascript', response.content_type |
|
139 | 153 | end |
|
140 | 154 | assert_nil Journal.find_by_id(2) |
|
141 | 155 | assert_include 'change-2', response.body |
|
142 | 156 | end |
|
143 | 157 | end |
General Comments 0
You need to be logged in to leave comments.
Login now