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
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 },
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
<% note_id = 1 %>
<% for journal in journals %>
+ <div id="change-<%= journal.id %>">
<h4><div style="float:right;"><%= link_to "##{note_id}", :anchor => "note-#{note_id}" %></div>
<%= content_tag('a', '', :name => "note-#{note_id}")%>
<%= format_time(journal.created_on) %> - <%= journal.user.name %></h4>
<% end %>
</ul>
<%= render_notes(journal) unless journal.notes.blank? %>
+ </div>
<% note_id += 1 %>
<% end %>
-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
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
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