Skip to content

Commit

Permalink
fix: store editor information in text_version model (pupilfirst#816)
Browse files Browse the repository at this point in the history
Co-authored-by: Mahesh Krishna Kumar <[email protected]>
  • Loading branch information
a-c-sreedhar-reddy and mahesh-krishnakumar authored Oct 14, 2021
1 parent 65cf698 commit 8275e0d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions app/presenters/posts/versions_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def updated_at(object)
object.updated_at.to_formatted_s(:long)
end

private

def versions_count
@versions_count ||= versions.count
end
Expand Down
2 changes: 1 addition & 1 deletion app/queries/update_post_mutator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UpdatePostMutator < ApplicationQuery

def update_post
Post.transaction do
post.text_versions.create!(value: post.body, user: post.creator, edited_at: post.updated_at, reason: post.edit_reason)
post.text_versions.create!(value: post.body, user: post.editor, edited_at: post.updated_at, reason: post.edit_reason)
post.update!(body: body, editor: current_user, edit_reason: sanitized_edit_reason)
post
end
Expand Down
8 changes: 6 additions & 2 deletions app/views/posts/versions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@
</div>

</div>
<% presenter.versions.each_with_index do |version, index| %>
<% presenter.versions.order(created_at: :desc).each_with_index do |version, index| %>
<div class="flex items-start mt-4">
<div class="w-1/12 font-bold text-lg md:text-4xl mr-2 md:mr-3 text-center text-gray-500"><%= presenter.version_number(index) %></div>
<div class="flex-1 relative bg-orange-100 border border-orange-200 rounded p-5 overflow-hidden">
<div data-json-props="<%= presenter.markdown_prop(version.value) %>" class="convert-markdown">
<%= version.value %>
</div>
<div class="mt-4 text-xs">
<% if index == (presenter.versions_count - 1) %>
<span>Created by</span>
<% else %>
<span>Edited by</span>
<span class="font-semibold"><%= version.user&.name || 'Unknown' %></span>
<% end %>
<span class="font-semibold"><%= version.user&.name|| 'Unknown' %></span>
<span><%= presenter.updated_at(version) %></span>
</div>
<% if version.reason? %>
Expand Down

0 comments on commit 8275e0d

Please sign in to comment.