From 1c8cf4ef8338736ebcaa905f8932545a24e817c6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 16 Feb 2008 13:19:33 +0000 Subject: [PATCH] Added the following permissions (#527, #585, #627): * edit_issue_notes: let user edit any notes * edit_own_issue_notes: let user edit his own notes only git-svn-id: http://redmine.rubyforge.org/svn/trunk@1152 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/journals_controller.rb | 2 +- app/helpers/journals_helper.rb | 2 +- app/models/journal.rb | 3 ++- app/views/issues/_history.rhtml | 2 ++ app/views/journals/update.rjs | 11 ++++++++--- lib/redmine.rb | 2 ++ test/functional/journals_controller_test.rb | 8 ++++++++ 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 05d41fa3..758b8507 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -22,11 +22,11 @@ class JournalsController < ApplicationController def edit if request.post? @journal.update_attributes(:notes => params[:notes]) if params[:notes] + @journal.destroy if @journal.details.empty? && @journal.notes.blank? respond_to do |format| format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } format.js { render :action => 'update' } end - return end end diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index 2f902432..234bfabc 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -19,7 +19,7 @@ module JournalsHelper def render_notes(journal, options={}) content = '' editable = journal.editable_by?(User.current) - if editable + if editable && !journal.notes.blank? links = [] links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", { :controller => 'journals', :action => 'edit', :id => journal }, diff --git a/app/models/journal.rb b/app/models/journal.rb index df730843..013e2644 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -51,6 +51,7 @@ class Journal < ActiveRecord::Base end def editable_by?(usr) - usr && usr.admin? + project = journalized.project + usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project))) end end diff --git a/app/views/issues/_history.rhtml b/app/views/issues/_history.rhtml index edfb9b94..7c1ee211 100644 --- a/app/views/issues/_history.rhtml +++ b/app/views/issues/_history.rhtml @@ -1,5 +1,6 @@ <% note_id = 1 %> <% for journal in journals %> +

<%= link_to "##{note_id}", :anchor => "note-#{note_id}" %>
<%= content_tag('a', '', :name => "note-#{note_id}")%> <%= format_time(journal.created_on) %> - <%= journal.user.name %>

@@ -9,5 +10,6 @@ <% end %> <%= render_notes(journal) unless journal.notes.blank? %> +
<% note_id += 1 %> <% end %> diff --git a/app/views/journals/update.rjs b/app/views/journals/update.rjs index 9da0ebea..2b5a54c0 100644 --- a/app/views/journals/update.rjs +++ b/app/views/journals/update.rjs @@ -1,3 +1,8 @@ -page.replace "journal-#{@journal.id}-notes", render_notes(@journal) -page.show "journal-#{@journal.id}-notes" -page.remove "journal-#{@journal.id}-form" +if @journal.frozen? + # journal was destroyed + page.remove "change-#{@journal.id}" +else + page.replace "journal-#{@journal.id}-notes", render_notes(@journal) + page.show "journal-#{@journal.id}-notes" + page.remove "journal-#{@journal.id}-form" +end diff --git a/lib/redmine.rb b/lib/redmine.rb index b235df32..e76d77e9 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -34,6 +34,8 @@ Redmine::AccessControl.map do |map| map.permission :edit_issues, {:issues => [:edit, :bulk_edit, :destroy_attachment]} map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} map.permission :add_issue_notes, {:issues => :edit} + map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin + map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin map.permission :move_issues, {:issues => :move}, :require => :loggedin map.permission :delete_issues, {:issues => :destroy}, :require => :member # Queries diff --git a/test/functional/journals_controller_test.rb b/test/functional/journals_controller_test.rb index f231d10e..e6a90185 100644 --- a/test/functional/journals_controller_test.rb +++ b/test/functional/journals_controller_test.rb @@ -48,4 +48,12 @@ class JournalsControllerTest < ActionController::TestCase assert_select_rjs :replace, 'journal-2-notes' assert_equal 'Updated notes', Journal.find(2).notes end + + def test_post_edit_with_empty_notes + @request.session[:user_id] = 1 + xhr :post, :edit, :id => 2, :notes => '' + assert_response :success + assert_select_rjs :remove, 'change-2' + assert_nil Journal.find_by_id(2) + end end