summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-07-10 10:33:48 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-07-10 10:33:48 +0000
commit7918285ac2e64fe046e590fbb1afb1e1f2fb9422 (patch)
treea9e81fdf1775055a3a6c2813bfb14a7aedd16373
parent07da3dc70cc47655ac07294dba714b57e9d61536 (diff)
downloadredmine-7918285ac2e64fe046e590fbb1afb1e1f2fb9422.tar.gz
redmine-7918285ac2e64fe046e590fbb1afb1e1f2fb9422.zip
Enable updating private_notes property on journal edit form (#22575).
Patch by Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@15620 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/journals_controller.rb5
-rw-r--r--app/helpers/journals_helper.rb6
-rw-r--r--app/views/issues/_history.html.erb2
-rw-r--r--app/views/journals/_notes_form.html.erb3
-rw-r--r--app/views/journals/update.js.erb2
-rw-r--r--test/functional/journals_controller_test.rb33
6 files changed, 49 insertions, 2 deletions
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb
index a0905aed1..6780916b7 100644
--- a/app/controllers/journals_controller.rb
+++ b/app/controllers/journals_controller.rb
@@ -90,7 +90,10 @@ class JournalsController < ApplicationController
def update
(render_403; return false) unless @journal.editable_by?(User.current)
- @journal.update_attributes(:notes => params[:notes]) if params[:notes]
+ @journal.notes = params[:notes] if params[:notes]
+ @journal.private_notes = params[:private_notes].present?
+ (render_403; return false) if @journal.private_notes_changed? && User.current.allowed_to?(:set_notes_private, @journal.issue.project) == false
+ @journal.save if @journal.changed?
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
respond_to do |format|
diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb
index f9dc7c9ea..e31ad2544 100644
--- a/app/helpers/journals_helper.rb
+++ b/app/helpers/journals_helper.rb
@@ -58,4 +58,10 @@ module JournalsHelper
css_classes << " editable" if editable
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
end
+
+ def render_private_notes(journal)
+ content = journal.private_notes? ? l(:field_is_private) : ''
+ css_classes = journal.private_notes? ? 'private' : ''
+ content_tag('span', content.html_safe, :id => "journal-#{journal.id}-private_notes", :class => css_classes)
+ end
end
diff --git a/app/views/issues/_history.html.erb b/app/views/issues/_history.html.erb
index 307ac909b..603e8f984 100644
--- a/app/views/issues/_history.html.erb
+++ b/app/views/issues/_history.html.erb
@@ -5,7 +5,7 @@
<h4><a href="#note-<%= journal.indice %>" class="journal-link">#<%= journal.indice %></a>
<%= avatar(journal.user, :size => "24") %>
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>
- <%= content_tag('span', l(:field_is_private), :class => 'private') if journal.private_notes? %></h4>
+ <%= render_private_notes(journal) %></h4>
<% if journal.details.any? %>
<ul class="details">
diff --git a/app/views/journals/_notes_form.html.erb b/app/views/journals/_notes_form.html.erb
index 41650c5d3..e8e73bb18 100644
--- a/app/views/journals/_notes_form.html.erb
+++ b/app/views/journals/_notes_form.html.erb
@@ -7,6 +7,9 @@
:id => "journal_#{@journal.id}_notes",
:class => 'wiki-edit',
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %>
+ <% if @journal.issue.safe_attribute? 'private_notes' %>
+ <%= 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>
+ <% end %>
<%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %>
<p><%= submit_tag l(:button_save) %>
<%= preview_link preview_edit_issue_path(:project_id => @project, :id => @journal.issue),
diff --git a/app/views/journals/update.js.erb b/app/views/journals/update.js.erb
index 65c198d59..34adf1567 100644
--- a/app/views/journals/update.js.erb
+++ b/app/views/journals/update.js.erb
@@ -1,7 +1,9 @@
<% if @journal.frozen? %>
$("#change-<%= @journal.id %>").remove();
<% else %>
+ $("#change-<%= @journal.id %>").attr('class', '<%= @journal.css_classes %>');
$("#journal-<%= @journal.id %>-notes").replaceWith('<%= escape_javascript(render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))) %>');
+ $("#journal-<%= @journal.id %>-private_notes").replaceWith('<%= escape_javascript(render_private_notes(@journal)) %>');
$("#journal-<%= @journal.id %>-notes").show();
$("#journal-<%= @journal.id %>-form").remove();
<% end %>
diff --git a/test/functional/journals_controller_test.rb b/test/functional/journals_controller_test.rb
index 097d0bd76..304f205f7 100644
--- a/test/functional/journals_controller_test.rb
+++ b/test/functional/journals_controller_test.rb
@@ -207,6 +207,39 @@ class JournalsControllerTest < ActionController::TestCase
assert_include 'journal-2-notes', response.body
end
+ def test_update_xhr_with_private_notes_checked
+ @request.session[:user_id] = 1
+ xhr :post, :update, :id => 2, :private_notes => '1'
+ assert_response :success
+ assert_template 'update'
+ assert_equal 'text/javascript', response.content_type
+ assert_equal true, Journal.find(2).private_notes
+ assert_include 'change-2', response.body
+ assert_include 'journal-2-private_notes', response.body
+ end
+
+ def test_update_xhr_with_private_notes_unchecked
+ Journal.find(2).update_attributes(:private_notes => true)
+ @request.session[:user_id] = 1
+ xhr :post, :update, :id => 2
+ assert_response :success
+ assert_template 'update'
+ assert_equal 'text/javascript', response.content_type
+ assert_equal false, Journal.find(2).private_notes
+ assert_include 'change-2', response.body
+ assert_include 'journal-2-private_notes', response.body
+ end
+
+ def test_update_xhr_with_private_notes_changes_and_without_set_private_notes_permission
+ @request.session[:user_id] = 2
+ Role.find(1).add_permission! :edit_issue_notes
+ Role.find(1).add_permission! :view_private_notes
+ Role.find(1).remove_permission! :set_notes_private
+
+ xhr :post, :update, :id => 2, :private_notes => '1'
+ assert_response 403
+ end
+
def test_update_xhr_with_empty_notes_should_delete_the_journal
@request.session[:user_id] = 1
assert_difference 'Journal.count', -1 do