Patch #22575 » enable_to_update_journal_notes_private_or_public_trunk_r15361.patch
app/controllers/journals_controller.rb | ||
---|---|---|
90 | 90 | |
91 | 91 |
def update |
92 | 92 |
(render_403; return false) unless @journal.editable_by?(User.current) |
93 |
@journal.update_attributes(:notes => params[:notes]) if params[:notes] |
|
93 |
@journal.notes = params[:notes] if params[:notes] |
|
94 |
@journal.private_notes = params[:private_notes].present? |
|
95 |
(render_403; return false) if @journal.private_notes_changed? && User.current.allowed_to?(:set_notes_private, @journal.issue.project) == false |
|
96 |
@journal.save if @journal.changed? |
|
94 | 97 |
@journal.destroy if @journal.details.empty? && @journal.notes.blank? |
95 | 98 |
call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) |
96 | 99 |
respond_to do |format| |
app/helpers/journals_helper.rb | ||
---|---|---|
58 | 58 |
css_classes << " editable" if editable |
59 | 59 |
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes) |
60 | 60 |
end |
61 | ||
62 |
def render_private_notes(journal) |
|
63 |
content = journal.private_notes? ? l(:field_is_private) : '' |
|
64 |
css_classes = journal.private_notes? ? 'private' : '' |
|
65 |
content_tag('span', content.html_safe, :id => "journal-#{journal.id}-private_notes", :class => css_classes) |
|
66 |
end |
|
61 | 67 |
end |
app/views/issues/_history.html.erb | ||
---|---|---|
5 | 5 |
<h4><a href="#note-<%= journal.indice %>" class="journal-link">#<%= journal.indice %></a> |
6 | 6 |
<%= avatar(journal.user, :size => "24") %> |
7 | 7 |
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %> |
8 |
<%= content_tag('span', l(:field_is_private), :class => 'private') if journal.private_notes? %></h4>
|
|
8 |
<%= render_private_notes(journal) %></h4>
|
|
9 | 9 | |
10 | 10 |
<% if journal.details.any? %> |
11 | 11 |
<ul class="details"> |
app/views/journals/_notes_form.html.erb | ||
---|---|---|
7 | 7 |
:id => "journal_#{@journal.id}_notes", |
8 | 8 |
:class => 'wiki-edit', |
9 | 9 |
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %> |
10 |
<% if @journal.issue.safe_attribute? 'private_notes' %> |
|
11 |
<%= check_box_tag 'private_notes', '1', @journal.private_notes, :id => "journal_#{@journal.id}_private_notes" %> <label for="journal_<%= @journal.id %>_private_notes"><%= l(:field_private_notes) %></label> |
|
12 |
<% end %> |
|
10 | 13 |
<%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %> |
11 | 14 |
<p><%= submit_tag l(:button_save) %> |
12 | 15 |
<%= preview_link preview_edit_issue_path(:project_id => @project, :id => @journal.issue), |
app/views/journals/update.js.erb | ||
---|---|---|
1 | 1 |
<% if @journal.frozen? %> |
2 | 2 |
$("#change-<%= @journal.id %>").remove(); |
3 | 3 |
<% else %> |
4 |
$("#change-<%= @journal.id %>").attr('class', '<%= @journal.css_classes %>'); |
|
4 | 5 |
$("#journal-<%= @journal.id %>-notes").replaceWith('<%= escape_javascript(render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))) %>'); |
6 |
$("#journal-<%= @journal.id %>-private_notes").replaceWith('<%= escape_javascript(render_private_notes(@journal)) %>'); |
|
5 | 7 |
$("#journal-<%= @journal.id %>-notes").show(); |
6 | 8 |
$("#journal-<%= @journal.id %>-form").remove(); |
7 | 9 |
<% end %> |
test/functional/journals_controller_test.rb | ||
---|---|---|
207 | 207 |
assert_include 'journal-2-notes', response.body |
208 | 208 |
end |
209 | 209 | |
210 |
def test_update_xhr_with_private_notes_checked |
|
211 |
@request.session[:user_id] = 1 |
|
212 |
xhr :post, :update, :id => 2, :private_notes => '1' |
|
213 |
assert_response :success |
|
214 |
assert_template 'update' |
|
215 |
assert_equal 'text/javascript', response.content_type |
|
216 |
assert_equal true, Journal.find(2).private_notes |
|
217 |
assert_include 'change-2', response.body |
|
218 |
assert_include 'journal-2-private_notes', response.body |
|
219 |
end |
|
220 | ||
221 |
def test_update_xhr_with_private_notes_unchecked |
|
222 |
Journal.find(2).update_attributes(:private_notes => true) |
|
223 |
@request.session[:user_id] = 1 |
|
224 |
xhr :post, :update, :id => 2 |
|
225 |
assert_response :success |
|
226 |
assert_template 'update' |
|
227 |
assert_equal 'text/javascript', response.content_type |
|
228 |
assert_equal false, Journal.find(2).private_notes |
|
229 |
assert_include 'change-2', response.body |
|
230 |
assert_include 'journal-2-private_notes', response.body |
|
231 |
end |
|
232 | ||
233 |
def test_update_xhr_with_private_notes_changes_and_without_set_private_notes_permission |
|
234 |
@request.session[:user_id] = 2 |
|
235 |
Role.find(1).add_permission! :edit_issue_notes |
|
236 |
Role.find(1).add_permission! :view_private_notes |
|
237 |
Role.find(1).remove_permission! :set_notes_private |
|
238 | ||
239 |
xhr :post, :update, :id => 2, :private_notes => '1' |
|
240 |
assert_response 403 |
|
241 |
end |
|
242 | ||
210 | 243 |
def test_update_xhr_with_empty_notes_should_delete_the_journal |
211 | 244 |
@request.session[:user_id] = 1 |
212 | 245 |
assert_difference 'Journal.count', -1 do |
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »