diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/node_action.rb | 25 |
1 files changed, 15 insertions, 10 deletions
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 |
