Project

General

Profile

Feature #31505 » 31505-v2.patch

Go MAEDA, 2022-07-14 11:49

View differences:

app/controllers/journals_controller.rb
91 91

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

  
83
  def render_journal_update_info(journal)
84
    if journal.created_on != journal.updated_on
85
      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')
86
    end
87
  end
82 88
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

  
......
78 79
  safe_attributes(
79 80
    'private_notes',
80 81
    :if => lambda {|journal, user| user.allowed_to?(:set_notes_private, journal.project)})
82
  safe_attributes 'updated_by'
81 83

  
82 84
  # Returns a SQL condition to filter out journals with notes that are not visible to user
83 85
  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
  setupWikiTableSortableHeader();
11 18
<% end %>
12 19

  
config/locales/en.yml
1129 1129
  label_my_bookmarks: My bookmarks
1130 1130
  label_assign_to_me: Assign to me
1131 1131
  label_default_query: Default query
1132
  label_edited: Edited
1133
  label_time_by_author: "%{time} by %{author}"
1132 1134

  
1133 1135
  button_login: Login
1134 1136
  button_submit: Submit
db/migrate/20220714093000_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/20220714093010_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
610 610
div.journal ul.details a:hover, ul.revision-info a:hover {color:#D14848;}
611 611
body.avatars-on div.journal {padding-left:32px;}
612 612
div.journal h4 img.gravatar {margin-left:-32px;}
613
div.journal span.update-info {color: #666; font-size: 0.9em;}
613 614

  
614 615
#history .tab-content {
615 616
  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
2894 2894
    assert_select "#change-#{not_visible.id}", 0
2895 2895
  end
2896 2896

  
2897
  def test_show_should_mark_notes_as_edited_only_for_edited_notes
2898
    get :show, :params => {
2899
        :id => 1
2900
      }
2901
    assert_response :success
2902

  
2903
    journal = Journal.find(1)
2904
    journal_title = l(:label_time_by_author, :time => format_time(journal.updated_on), :author => journal.updated_by)
2905
    assert_select "#change-1 h4 span.update-info[title=?]", journal_title, :text => '· Edited'
2906
    assert_select "#change-2 h4 span.update-info", 0
2907
  end
2908

  
2897 2909
  def test_show_atom
2898 2910
    with_settings :text_formatting => 'textile' do
2899 2911
      get(
(3-3/3)