Project

General

Profile

Feature #31505 » 0001-Mark-edited-journal-notes-as-Edited.patch

Marius BĂLTEANU, 2020-04-05 12:57

View differences:

app/controllers/journals_controller.rb
89 89

  
90 90
  def update
91 91
    (render_403; return false) unless @journal.editable_by?(User.current)
92
    @journal.safe_attributes = params[:journal]
92
    journal_attributes =  params[:journal]
93
    journal_attributes[:updated_by] = User.current
94
    @journal.safe_attributes = journal_attributes
93 95
    @journal.save
94 96
    @journal.destroy if @journal.details.empty? && @journal.notes.blank?
95 97
    call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
app/helpers/journals_helper.rb
68 68
    css_classes = journal.private_notes? ? 'badge badge-private private' : ''
69 69
    content_tag('span', content.html_safe, :id => "journal-#{journal.id}-private_notes", :class => css_classes)
70 70
  end
71

  
72
  def render_journal_update_info(journal)
73
    if journal.created_on != journal.updated_on
74
      content_tag('span', "· #{l(:label_edited)}", :title => l(:label_time_by_author, :time => format_time(journal.updated_on), :author => journal.updated_by), :class => 'update-info')
75
    end
76
  end
71 77
end
app/models/journal.rb
26 26
  belongs_to :issue, :foreign_key => :journalized_id
27 27

  
28 28
  belongs_to :user
29
  belongs_to :updated_by, :class_name => 'User'
29 30
  has_many :details, :class_name => "JournalDetail", :dependent => :delete_all, :inverse_of => :journal
30 31
  attr_accessor :indice
31 32

  
......
61 62
  safe_attributes(
62 63
    'private_notes',
63 64
    :if => lambda {|journal, user| user.allowed_to?(:set_notes_private, journal.project)})
65
  safe_attributes 'updated_by'
64 66

  
65 67
  # Returns a SQL condition to filter out journals with notes that are not visible to user
66 68
  def self.visible_notes_condition(user=User.current, options={})
app/views/issues/tabs/_history.html.erb
15 15
      <%= avatar(journal.user) %>
16 16
      <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>
17 17
      <%= render_private_notes_indicator(journal) %>
18
      <%= render_journal_update_info(journal) %>
18 19
    </h4>
19 20

  
20 21
    <% if journal.details.any? %>
app/views/journals/update.js.erb
7 7
  $("#journal-<%= @journal.id %>-notes").replaceWith('<%= escape_javascript(render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))) %>');
8 8
  $("#journal-<%= @journal.id %>-notes").show();
9 9
  $("#journal-<%= @journal.id %>-form").remove();
10
  var journal_header = $("#change-<%= @journal.id %> h4");
11
  var journal_updated_info = journal_header.find("span.update-info");
12
  if (journal_updated_info.length > 0) {
13
    journal_updated_info.replaceWith('<%= escape_javascript(render_journal_update_info(@journal)) %>');
14
  } else {
15
    journal_header.append('<%= escape_javascript(render_journal_update_info(@journal)) %>');
16
  }
10 17
<% end %>
11 18

  
12 19
<%= call_hook(:view_journals_update_js_bottom, { :journal => @journal }) %>
config/locales/en.yml
1087 1087
  label_display_type_board: Board
1088 1088
  label_my_bookmarks: My bookmarks
1089 1089
  label_assign_to_me: Assign to me
1090
  label_edited: Edited
1091
  label_time_by_author: "%{time} by %{author}"
1090 1092

  
1091 1093
  button_login: Login
1092 1094
  button_submit: Submit
db/migrate/20190802185259_add_journal_updated_on.rb
1
class AddJournalUpdatedOn < ActiveRecord::Migration[5.2]
2
  def up
3
    add_column :journals, :updated_on, :datetime, :after => :created_on
4
    Journal.update_all('updated_on = created_on')
5
  end
6

  
7
  def down
8
    remove_column :journals, :updated_on
9
  end
10
end
db/migrate/20190802185309_add_journal_updated_by.rb
1
class AddJournalUpdatedBy < ActiveRecord::Migration[5.2]
2
  def up
3
    add_column :journals, :updated_by_id, :integer, :default => nil, :after => :updated_on
4
  end
5

  
6
  def down
7
    remove_column :journals, :updated_by
8
  end
9
end
public/stylesheets/application.css
577 577
div.journal ul.details a:hover, ul.revision-info a:hover {color:#D14848;}
578 578
body.avatars-on div.journal {padding-left:32px;}
579 579
div.journal h4 img.gravatar {margin-left:-32px;}
580
div.journal span.update-info {color: #666; font-size: 0.9em;}
580 581

  
581 582
#history .tab-content {
582 583
  padding: 0 6px;
test/fixtures/journals.yml
1 1
---
2 2
journals_001:
3 3
  created_on: <%= 2.days.ago.to_date.to_s(:db) %>
4
  updated_on: <%= 1.days.ago.to_date.to_s(:db) %>
4 5
  notes: "Journal notes"
5 6
  id: 1
6 7
  journalized_type: Issue
7 8
  user_id: 1
8 9
  journalized_id: 1
10
  updated_by_id: 1
9 11
journals_002:
10 12
  created_on: <%= 1.days.ago.to_date.to_s(:db) %>
13
  updated_on: <%= 1.days.ago.to_date.to_s(:db) %>
11 14
  notes: "Some notes with Redmine links: #2, r2."
12 15
  id: 2
13 16
  journalized_type: Issue
......
15 18
  journalized_id: 1
16 19
journals_003:
17 20
  created_on: <%= 1.days.ago.to_date.to_s(:db) %>
21
  updated_on: <%= 1.days.ago.to_date.to_s(:db) %>
18 22
  notes: "A comment with inline image: !picture.jpg! and a reference to #1 and r2."
19 23
  id: 3
20 24
  journalized_type: Issue
......
22 26
  journalized_id: 2
23 27
journals_004:
24 28
  created_on: <%= 1.days.ago.to_date.to_s(:db) %>
29
  updated_on: <%= 1.days.ago.to_date.to_s(:db) %>
25 30
  notes: "A comment with a private version."
26 31
  id: 4
27 32
  journalized_type: Issue
......
30 35
journals_005:
31 36
  id: 5
32 37
  created_on: <%= 1.days.ago.to_date.to_s(:db) %>
38
  updated_on: <%= 1.days.ago.to_date.to_s(:db) %>
33 39
  notes: "A comment on a private issue."
34 40
  user_id: 2
35 41
  journalized_type: Issue
test/functional/issues_controller_test.rb
2714 2714
    assert_select "#change-#{not_visible.id}", 0
2715 2715
  end
2716 2716

  
2717
  def test_show_should_mark_notes_as_edited_only_for_edited_notes
2718
    get :show, :params => {
2719
        :id => 1
2720
      }
2721
    assert_response :success
2722

  
2723
    journal = Journal.find(1)
2724
    journal_title = l(:label_time_by_author, :time => format_time(journal.updated_on), :author => journal.updated_by)
2725
    assert_select "#change-1 h4 span.update-info[title=?]", journal_title, :text => '· Edited'
2726
    assert_select "#change-2 h4 span.update-info", 0
2727
  end
2728

  
2717 2729
  def test_show_atom
2718 2730
    get(
2719 2731
      :show,
(2-2/3)