Revision 1152
Added by Jean-Philippe Lang over 17 years ago
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
trunk/app/controllers/journals_controller.rb | ||
---|---|---|
22 | 22 |
def edit |
23 | 23 |
if request.post? |
24 | 24 |
@journal.update_attributes(:notes => params[:notes]) if params[:notes] |
25 |
@journal.destroy if @journal.details.empty? && @journal.notes.blank? |
|
25 | 26 |
respond_to do |format| |
26 | 27 |
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } |
27 | 28 |
format.js { render :action => 'update' } |
28 | 29 |
end |
29 |
return |
|
30 | 30 |
end |
31 | 31 |
end |
32 | 32 |
|
trunk/app/helpers/journals_helper.rb | ||
---|---|---|
19 | 19 |
def render_notes(journal, options={}) |
20 | 20 |
content = '' |
21 | 21 |
editable = journal.editable_by?(User.current) |
22 |
if editable |
|
22 |
if editable && !journal.notes.blank?
|
|
23 | 23 |
links = [] |
24 | 24 |
links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", |
25 | 25 |
{ :controller => 'journals', :action => 'edit', :id => journal }, |
trunk/app/models/journal.rb | ||
---|---|---|
51 | 51 |
end |
52 | 52 |
|
53 | 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 | 56 |
end |
56 | 57 |
end |
trunk/app/views/issues/_history.rhtml | ||
---|---|---|
1 | 1 |
<% note_id = 1 %> |
2 | 2 |
<% for journal in journals %> |
3 |
<div id="change-<%= journal.id %>"> |
|
3 | 4 |
<h4><div style="float:right;"><%= link_to "##{note_id}", :anchor => "note-#{note_id}" %></div> |
4 | 5 |
<%= content_tag('a', '', :name => "note-#{note_id}")%> |
5 | 6 |
<%= format_time(journal.created_on) %> - <%= journal.user.name %></h4> |
... | ... | |
9 | 10 |
<% end %> |
10 | 11 |
</ul> |
11 | 12 |
<%= render_notes(journal) unless journal.notes.blank? %> |
13 |
</div> |
|
12 | 14 |
<% note_id += 1 %> |
13 | 15 |
<% end %> |
trunk/app/views/journals/update.rjs | ||
---|---|---|
1 |
page.replace "journal-#{@journal.id}-notes", render_notes(@journal) |
|
2 |
page.show "journal-#{@journal.id}-notes" |
|
3 |
page.remove "journal-#{@journal.id}-form" |
|
1 |
if @journal.frozen? |
|
2 |
# journal was destroyed |
|
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 |
trunk/lib/redmine.rb | ||
---|---|---|
34 | 34 |
map.permission :edit_issues, {:issues => [:edit, :bulk_edit, :destroy_attachment]} |
35 | 35 |
map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} |
36 | 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 | 39 |
map.permission :move_issues, {:issues => :move}, :require => :loggedin |
38 | 40 |
map.permission :delete_issues, {:issues => :destroy}, :require => :member |
39 | 41 |
# Queries |
trunk/test/functional/journals_controller_test.rb | ||
---|---|---|
48 | 48 |
assert_select_rjs :replace, 'journal-2-notes' |
49 | 49 |
assert_equal 'Updated notes', Journal.find(2).notes |
50 | 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 | 59 |
end |
Also available in: Unified diff