diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/node_actions_helper.rb | 74 | ||||
| -rw-r--r-- | app/models/node_action.rb | 25 | ||||
| -rw-r--r-- | app/views/node_actions/_change_details.html.erb | 30 | ||||
| -rw-r--r-- | app/views/node_actions/index.html.erb | 25 |
4 files changed, 108 insertions, 46 deletions
diff --git a/app/helpers/node_actions_helper.rb b/app/helpers/node_actions_helper.rb index 55ca982..996f98d 100644 --- a/app/helpers/node_actions_helper.rb +++ b/app/helpers/node_actions_helper.rb | |||
| @@ -16,8 +16,57 @@ module NodeActionsHelper | |||
| 16 | :action => h(action.action), :subject => subject_ref(action)).html_safe | 16 | :action => h(action.action), :subject => subject_ref(action)).html_safe |
| 17 | end | 17 | end |
| 18 | 18 | ||
| 19 | |||
| 20 | def action_details? action | ||
| 21 | m = action.metadata | ||
| 22 | return true if m["translation_diff"].present? | ||
| 23 | return true if m["title"].is_a?(Hash) && m.dig("title", "from") != m.dig("title", "to") | ||
| 24 | %w[author tags template_changed assets_changed | ||
| 25 | abstract_changed body_changed].any? { |key| m[key].present? } | ||
| 26 | end | ||
| 27 | |||
| 28 | # Plain strings by design -- safe_join in the template escapes them. | ||
| 29 | def default_locale_changes action | ||
| 30 | m = action.metadata | ||
| 31 | items = [] | ||
| 32 | if m["title"].is_a?(Hash) && m.dig("title", "from") && m.dig("title", "from") != m.dig("title", "to") | ||
| 33 | items << t("node_actions.detail_title", | ||
| 34 | :from => m.dig("title", "from"), :to => m.dig("title", "to")) | ||
| 35 | end | ||
| 36 | items << t("node_actions.detail_author", | ||
| 37 | :from => m.dig("author", "from"), :to => m.dig("author", "to")) if m["author"] | ||
| 38 | items << t("node_actions.detail_tags", | ||
| 39 | :from => Array(m.dig("tags", "from")).join(", "), | ||
| 40 | :to => Array(m.dig("tags", "to")).join(", ")) if m["tags"] | ||
| 41 | items << t("node_actions.abstract_changed") if m["abstract_changed"] | ||
| 42 | items << t("node_actions.body_changed") if m["body_changed"] | ||
| 43 | items << t("node_actions.template_changed") if m["template_changed"] | ||
| 44 | items << t("node_actions.assets_changed") if m["assets_changed"] | ||
| 45 | items | ||
| 46 | end | ||
| 47 | |||
| 48 | def translation_changes diff | ||
| 49 | case diff["status"] | ||
| 50 | when "added" then [t("node_actions.locale_added", :title => diff.dig("title", "to"))] | ||
| 51 | when "removed" then [t("node_actions.locale_removed", :title => diff.dig("title", "from"))] | ||
| 52 | else | ||
| 53 | items = [] | ||
| 54 | items << t("node_actions.detail_title", | ||
| 55 | :from => diff.dig("title", "from"), :to => diff.dig("title", "to")) if diff["title"] | ||
| 56 | items << t("node_actions.abstract_changed") if diff["abstract_changed"] | ||
| 57 | items << t("node_actions.body_changed") if diff["body_changed"] | ||
| 58 | items | ||
| 59 | end | ||
| 60 | end | ||
| 61 | |||
| 19 | private | 62 | private |
| 20 | 63 | ||
| 64 | def revision_ref action, key | ||
| 65 | label = t(key) | ||
| 66 | return label unless action.node && action.page | ||
| 67 | link_to(label, node_revision_path(action.node, action.page)) | ||
| 68 | end | ||
| 69 | |||
| 21 | def actor_ref action | 70 | def actor_ref action |
| 22 | action.user ? link_to(h(action.actor_name), admin_log_path(:user_id => action.user_id)) | 71 | action.user ? link_to(h(action.actor_name), admin_log_path(:user_id => action.user_id)) |
| 23 | : h(action.actor_name) | 72 | : h(action.actor_name) |
| @@ -29,17 +78,20 @@ module NodeActionsHelper | |||
| 29 | end | 78 | end |
| 30 | 79 | ||
| 31 | def summarize_publish action | 80 | def summarize_publish action |
| 32 | key = if action.metadata["via"] == "revision" | 81 | if action.metadata["via"] == "revision" |
| 33 | "node_actions.publish_rollback" | 82 | t("node_actions.publish_rollback", |
| 34 | elsif action.metadata.dig("title", "from").nil? | 83 | :actor => actor_ref(action), :subject => subject_ref(action), |
| 35 | "node_actions.publish_first" | 84 | :revision => revision_ref(action, "node_actions.revision_earlier")).html_safe |
| 36 | else | 85 | elsif action.metadata.dig("title", "from").nil? |
| 37 | "node_actions.publish" | 86 | author = action.metadata.dig("author", "to") |
| 38 | end | 87 | key = author ? "node_actions.publish_first_with_author" : "node_actions.publish_first" |
| 39 | 88 | t(key, :actor => actor_ref(action), :subject => subject_ref(action), | |
| 40 | t(key, :actor => actor_ref(action), :subject => subject_ref(action), | 89 | :author => h(author)).html_safe |
| 41 | :from => h(action.metadata.dig("title", "from")), | 90 | else |
| 42 | :to => h(action.metadata.dig("title", "to"))).html_safe | 91 | t("node_actions.publish", |
| 92 | :actor => actor_ref(action), :subject => subject_ref(action), | ||
| 93 | :revision => revision_ref(action, "node_actions.revision_new")).html_safe | ||
| 94 | end | ||
| 43 | end | 95 | end |
| 44 | 96 | ||
| 45 | def summarize_move action | 97 | def summarize_move action |
diff --git a/app/models/node_action.rb b/app/models/node_action.rb index 39935c7..792ae1e 100644 --- a/app/models/node_action.rb +++ b/app/models/node_action.rb | |||
| @@ -82,21 +82,23 @@ class NodeAction < ApplicationRecord | |||
| 82 | # user agent, ever. Success only -- rejected attempts are not | 82 | # user agent, ever. Success only -- rejected attempts are not |
| 83 | # logged. | 83 | # logged. |
| 84 | 84 | ||
| 85 | def self.record!(node:, action:, user: nil, page: nil, locale: nil, **extra) | 85 | def self.record!(node:, action:, user: nil, page: nil, locale: nil, |
| 86 | occurred_at: nil, inferred_from: nil, **extra) | ||
| 86 | create!( | 87 | create!( |
| 87 | :node => node, | 88 | :node => node, |
| 88 | :page => page, | 89 | :page => page, |
| 89 | :user => user, | 90 | :user => user, |
| 90 | :action => action, | 91 | :action => action, |
| 91 | :locale => locale, | 92 | :locale => locale, |
| 92 | :occurred_at => Time.now, | 93 | :occurred_at => occurred_at || Time.now, |
| 93 | :metadata => { | 94 | :inferred_from => inferred_from, |
| 95 | :metadata => { | ||
| 94 | "username" => user&.login, | 96 | "username" => user&.login, |
| 95 | "human_readable_node_name" => Globalize.with_locale(I18n.default_locale) { | 97 | "human_readable_node_name" => Globalize.with_locale(I18n.default_locale) { |
| 96 | node&.head&.title || node&.draft&.title | 98 | node&.head&.title || node&.draft&.title |
| 97 | }, | 99 | }, |
| 98 | }.merge(extra.stringify_keys) | 100 | }.merge(extra.stringify_keys) |
| 99 | ) | 101 | ) |
| 100 | end | 102 | end |
| 101 | 103 | ||
| 102 | # Computes the publish-entry diff between an outgoing head and the | 104 | # Computes the publish-entry diff between an outgoing head and the |
| @@ -113,7 +115,10 @@ class NodeAction < ApplicationRecord | |||
| 113 | title_of = ->(page) { page&.translations&.find_by(:locale => default)&.title } | 115 | title_of = ->(page) { page&.translations&.find_by(:locale => default)&.title } |
| 114 | diff = { :title => { "from" => title_of.call(old_page), | 116 | diff = { :title => { "from" => title_of.call(old_page), |
| 115 | "to" => title_of.call(new_page) } } | 117 | "to" => title_of.call(new_page) } } |
| 116 | return diff unless old_page | 118 | unless old_page |
| 119 | diff[:author] = { "from" => nil, "to" => new_page.user&.login } if new_page.user | ||
| 120 | return diff | ||
| 121 | end | ||
| 117 | 122 | ||
| 118 | old_author, new_author = old_page.user&.login, new_page.user&.login | 123 | old_author, new_author = old_page.user&.login, new_page.user&.login |
| 119 | diff[:author] = { "from" => old_author, "to" => new_author } if old_author != new_author | 124 | diff[:author] = { "from" => old_author, "to" => new_author } if old_author != new_author |
diff --git a/app/views/node_actions/_change_details.html.erb b/app/views/node_actions/_change_details.html.erb index 383f53a..2583e8b 100644 --- a/app/views/node_actions/_change_details.html.erb +++ b/app/views/node_actions/_change_details.html.erb | |||
| @@ -1,27 +1,27 @@ | |||
| 1 | <details class="node_action_details"> | 1 | <details class="node_action_details"> |
| 2 | <summary><%= t("node_actions.show_changes") %></summary> | 2 | <summary><%= t("node_actions.show_changes") %></summary> |
| 3 | <table> | 3 | <table> |
| 4 | <% action_entry.metadata["translation_diff"].each do |locale, diff| %> | 4 | <% if (default_items = default_locale_changes(action_entry)).any? %> |
| 5 | <tr> | ||
| 6 | <th><%= I18n.default_locale.to_s.upcase %></th> | ||
| 7 | <td> | ||
| 8 | <%= safe_join(default_items, ", ") %> | ||
| 9 | <% if action_entry.page && action_entry.node %> | ||
| 10 | <%= link_to t("node_actions.view_revision"), node_revision_path(action_entry.node, action_entry.page) %> | ||
| 11 | <% end %> | ||
| 12 | </td> | ||
| 13 | </tr> | ||
| 14 | <% end %> | ||
| 15 | <% (action_entry.metadata["translation_diff"] || {}).each do |locale, diff| %> | ||
| 5 | <tr> | 16 | <tr> |
| 6 | <th><%= locale.upcase %></th> | 17 | <th><%= locale.upcase %></th> |
| 7 | <td> | 18 | <td> |
| 8 | <% case diff["status"] %> | 19 | <%= safe_join(translation_changes(diff), ", ") %> |
| 9 | <% when "added" %> | 20 | <% if action_entry.page && action_entry.node %> |
| 10 | <%= t("node_actions.locale_added", :title => diff.dig("title", "to")) %> | 21 | <%= link_to t("node_actions.view_revision"), node_revision_path(action_entry.node, action_entry.page, :locale => locale) %> |
| 11 | <% when "removed" %> | ||
| 12 | <%= t("node_actions.locale_removed", :title => diff.dig("title", "from")) %> | ||
| 13 | <% else %> | ||
| 14 | <% if diff["title"] %> | ||
| 15 | <%= diff.dig("title", "from") %> → <%= diff.dig("title", "to") %> | ||
| 16 | <% end %> | ||
| 17 | <%= t("node_actions.abstract_changed") if diff["abstract_changed"] %> | ||
| 18 | <%= t("node_actions.body_changed") if diff["body_changed"] %> | ||
| 19 | <% end %> | 22 | <% end %> |
| 20 | </td> | 23 | </td> |
| 21 | </tr> | 24 | </tr> |
| 22 | <% end %> | 25 | <% end %> |
| 23 | </table> | 26 | </table> |
| 24 | <% if action_entry.page && action_entry.node %> | ||
| 25 | <%= link_to t("node_actions.view_revision"), node_revision_path(action_entry.node, action_entry.page) %> | ||
| 26 | <% end %> | ||
| 27 | </details> | 27 | </details> |
diff --git a/app/views/node_actions/index.html.erb b/app/views/node_actions/index.html.erb index 92740cd..ee06213 100644 --- a/app/views/node_actions/index.html.erb +++ b/app/views/node_actions/index.html.erb | |||
| @@ -6,17 +6,22 @@ | |||
| 6 | 6 | ||
| 7 | <%= will_paginate @actions %> | 7 | <%= will_paginate @actions %> |
| 8 | 8 | ||
| 9 | <ul id="node_action_list"> | 9 | <table id="node_action_list"> |
| 10 | <% @actions.each do |action| %> | 10 | <% @actions.each do |action| %> |
| 11 | <li class="node_action node_action--<%= action.action %>"> | 11 | <tr class="node_action node_action--<%= action.action %>"> |
| 12 | <span class="node_action_time"><%= l(action.occurred_at, :format => :ccc) %></span> | 12 | <td class="node_action_time"><%= action.occurred_at.strftime("%Y-%m-%d %H:%M") %></td> |
| 13 | <% if action.inferred_from %> | 13 | <td class="node_action_body"> |
| 14 | <span class="node_action_inferred" title="<%= action.inferred_from %>"><%= t("node_actions.backfilled") %></span> | 14 | <%= action_summary(action) %> |
| 15 | <% end %> | 15 | <% if action.node_id && params[:node_id].blank? %> |
| 16 | <span class="node_action_summary"><%= action_summary(action) %></span> | 16 | <%= link_to t("node_actions.node_history"), admin_log_path(:node_id => action.node_id), :class => "node_action_zoom" %> |
| 17 | <%= render "change_details", :action_entry => action if action.metadata["translation_diff"].present? %> | 17 | <% end %> |
| 18 | </li> | 18 | <% if action.inferred_from %> |
| 19 | <span class="node_action_inferred" title="<%= action.inferred_from %>"><%= t("node_actions.backfilled") %></span> | ||
| 20 | <% end %> | ||
| 21 | <%= render "change_details", :action_entry => action if action_details?(action) %> | ||
| 22 | </td> | ||
| 23 | </tr> | ||
| 19 | <% end %> | 24 | <% end %> |
| 20 | </ul> | 25 | </table> |
| 21 | 26 | ||
| 22 | <%= will_paginate @actions %> | 27 | <%= will_paginate @actions %> |
