@@ -22,11 +22,11 class JournalsController < ApplicationController | |||||
22 | def edit |
|
22 | def edit | |
23 | if request.post? |
|
23 | if request.post? | |
24 | @journal.update_attributes(:notes => params[:notes]) if params[:notes] |
|
24 | @journal.update_attributes(:notes => params[:notes]) if params[:notes] | |
|
25 | @journal.destroy if @journal.details.empty? && @journal.notes.blank? | |||
25 | respond_to do |format| |
|
26 | respond_to do |format| | |
26 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } |
|
27 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } | |
27 | format.js { render :action => 'update' } |
|
28 | format.js { render :action => 'update' } | |
28 | end |
|
29 | end | |
29 | return |
|
|||
30 | end |
|
30 | end | |
31 | end |
|
31 | end | |
32 |
|
32 |
@@ -19,7 +19,7 module JournalsHelper | |||||
19 | def render_notes(journal, options={}) |
|
19 | def render_notes(journal, options={}) | |
20 | content = '' |
|
20 | content = '' | |
21 | editable = journal.editable_by?(User.current) |
|
21 | editable = journal.editable_by?(User.current) | |
22 | if editable |
|
22 | if editable && !journal.notes.blank? | |
23 | links = [] |
|
23 | links = [] | |
24 | links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", |
|
24 | links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", | |
25 | { :controller => 'journals', :action => 'edit', :id => journal }, |
|
25 | { :controller => 'journals', :action => 'edit', :id => journal }, |
@@ -51,6 +51,7 class Journal < ActiveRecord::Base | |||||
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def editable_by?(usr) |
|
53 | def editable_by?(usr) | |
54 | usr && usr.admin? |
|
54 | project = journalized.project | |
|
55 | usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project))) | |||
55 | end |
|
56 | end | |
56 | end |
|
57 | end |
@@ -1,5 +1,6 | |||||
1 | <% note_id = 1 %> |
|
1 | <% note_id = 1 %> | |
2 | <% for journal in journals %> |
|
2 | <% for journal in journals %> | |
|
3 | <div id="change-<%= journal.id %>"> | |||
3 | <h4><div style="float:right;"><%= link_to "##{note_id}", :anchor => "note-#{note_id}" %></div> |
|
4 | <h4><div style="float:right;"><%= link_to "##{note_id}", :anchor => "note-#{note_id}" %></div> | |
4 | <%= content_tag('a', '', :name => "note-#{note_id}")%> |
|
5 | <%= content_tag('a', '', :name => "note-#{note_id}")%> | |
5 | <%= format_time(journal.created_on) %> - <%= journal.user.name %></h4> |
|
6 | <%= format_time(journal.created_on) %> - <%= journal.user.name %></h4> | |
@@ -9,5 +10,6 | |||||
9 | <% end %> |
|
10 | <% end %> | |
10 | </ul> |
|
11 | </ul> | |
11 | <%= render_notes(journal) unless journal.notes.blank? %> |
|
12 | <%= render_notes(journal) unless journal.notes.blank? %> | |
|
13 | </div> | |||
12 | <% note_id += 1 %> |
|
14 | <% note_id += 1 %> | |
13 | <% end %> |
|
15 | <% end %> |
@@ -1,3 +1,8 | |||||
1 | page.replace "journal-#{@journal.id}-notes", render_notes(@journal) |
|
1 | if @journal.frozen? | |
2 | page.show "journal-#{@journal.id}-notes" |
|
2 | # journal was destroyed | |
3 |
page.remove " |
|
3 | page.remove "change-#{@journal.id}" | |
|
4 | else | |||
|
5 | page.replace "journal-#{@journal.id}-notes", render_notes(@journal) | |||
|
6 | page.show "journal-#{@journal.id}-notes" | |||
|
7 | page.remove "journal-#{@journal.id}-form" | |||
|
8 | end |
@@ -34,6 +34,8 Redmine::AccessControl.map do |map| | |||||
34 | map.permission :edit_issues, {:issues => [:edit, :bulk_edit, :destroy_attachment]} |
|
34 | map.permission :edit_issues, {:issues => [:edit, :bulk_edit, :destroy_attachment]} | |
35 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} |
|
35 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} | |
36 | map.permission :add_issue_notes, {:issues => :edit} |
|
36 | map.permission :add_issue_notes, {:issues => :edit} | |
|
37 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin | |||
|
38 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin | |||
37 | map.permission :move_issues, {:issues => :move}, :require => :loggedin |
|
39 | map.permission :move_issues, {:issues => :move}, :require => :loggedin | |
38 | map.permission :delete_issues, {:issues => :destroy}, :require => :member |
|
40 | map.permission :delete_issues, {:issues => :destroy}, :require => :member | |
39 | # Queries |
|
41 | # Queries |
@@ -48,4 +48,12 class JournalsControllerTest < ActionController::TestCase | |||||
48 | assert_select_rjs :replace, 'journal-2-notes' |
|
48 | assert_select_rjs :replace, 'journal-2-notes' | |
49 | assert_equal 'Updated notes', Journal.find(2).notes |
|
49 | assert_equal 'Updated notes', Journal.find(2).notes | |
50 | end |
|
50 | end | |
|
51 | ||||
|
52 | def test_post_edit_with_empty_notes | |||
|
53 | @request.session[:user_id] = 1 | |||
|
54 | xhr :post, :edit, :id => 2, :notes => '' | |||
|
55 | assert_response :success | |||
|
56 | assert_select_rjs :remove, 'change-2' | |||
|
57 | assert_nil Journal.find_by_id(2) | |||
|
58 | end | |||
51 | end |
|
59 | end |
General Comments 0
You need to be logged in to leave comments.
Login now