diff options
Diffstat (limited to 'app/helpers/node_actions_helper.rb')
| -rw-r--r-- | app/helpers/node_actions_helper.rb | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/app/helpers/node_actions_helper.rb b/app/helpers/node_actions_helper.rb index 4041ffa9..a4d13d22 100644 --- a/app/helpers/node_actions_helper.rb +++ b/app/helpers/node_actions_helper.rb | |||
| @@ -44,7 +44,8 @@ module NodeActionsHelper | |||
| 44 | :action => h(action.action), :subject => subject_ref(action)).html_safe | 44 | :action => h(action.action), :subject => subject_ref(action)).html_safe |
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | 47 | # Plain strings by design, safe_join in the template escapes them. | |
| 48 | # Exception: the asset items carry zoom links and arrive pre-escaped. | ||
| 48 | def action_details? action | 49 | def action_details? action |
| 49 | m = action.metadata | 50 | m = action.metadata |
| 50 | return true if m["translation_diff"].present? | 51 | return true if m["translation_diff"].present? |
| @@ -53,7 +54,6 @@ module NodeActionsHelper | |||
| 53 | abstract_changed body_changed].any? { |key| m[key].present? } | 54 | abstract_changed body_changed].any? { |key| m[key].present? } |
| 54 | end | 55 | end |
| 55 | 56 | ||
| 56 | # Plain strings by design -- safe_join in the template escapes them. | ||
| 57 | def default_locale_changes action | 57 | def default_locale_changes action |
| 58 | m = action.metadata | 58 | m = action.metadata |
| 59 | items = [] | 59 | items = [] |
| @@ -70,10 +70,14 @@ module NodeActionsHelper | |||
| 70 | items << t("node_actions.body_changed") if m["body_changed"] | 70 | items << t("node_actions.body_changed") if m["body_changed"] |
| 71 | items << t("node_actions.template_changed") if m["template_changed"] | 71 | items << t("node_actions.template_changed") if m["template_changed"] |
| 72 | if m["assets"] | 72 | if m["assets"] |
| 73 | items << t("node_actions.detail_assets_added", | 73 | if (names = m.dig("assets", "added")) |
| 74 | :names => Array(m.dig("assets", "added")).join(", ")) if m.dig("assets", "added") | 74 | items << t("node_actions.detail_assets_added", |
| 75 | items << t("node_actions.detail_assets_removed", | 75 | :names => linked_asset_names(action, names)).html_safe |
| 76 | :names => Array(m.dig("assets", "removed")).join(", ")) if m.dig("assets", "removed") | 76 | end |
| 77 | if (names = m.dig("assets", "removed")) | ||
| 78 | items << t("node_actions.detail_assets_removed", | ||
| 79 | :names => linked_asset_names(action, names)).html_safe | ||
| 80 | end | ||
| 77 | end | 81 | end |
| 78 | items << t("node_actions.assets_reordered") if m["assets_reordered"] | 82 | items << t("node_actions.assets_reordered") if m["assets_reordered"] |
| 79 | items << t("node_actions.assets_changed") if m["assets_changed"] | 83 | items << t("node_actions.assets_changed") if m["assets_changed"] |
| @@ -138,6 +142,38 @@ module NodeActionsHelper | |||
| 138 | : h(action.subject_name) | 142 | : h(action.subject_name) |
| 139 | end | 143 | end |
| 140 | 144 | ||
| 145 | def asset_ref action | ||
| 146 | asset = action.action_participants.detect { |p| p.subject_type == "Asset" }&.subject | ||
| 147 | name = action.metadata["asset_name"].presence || action.metadata["path"] | ||
| 148 | return h(name) unless asset | ||
| 149 | |||
| 150 | parts = [link_to(h(name), asset_path(asset))] | ||
| 151 | unless params[:asset_id].to_s == asset.id.to_s | ||
| 152 | parts << link_to(t("node_actions.asset_history"), | ||
| 153 | admin_log_path(:asset_id => asset.id), | ||
| 154 | :class => "node_action_zoom") | ||
| 155 | end | ||
| 156 | safe_join(parts, " ") | ||
| 157 | end | ||
| 158 | |||
| 159 | def linked_asset_names action, names | ||
| 160 | by_name = action.action_participants.includes(:subject) | ||
| 161 | .select { |p| p.subject_type == "Asset" } | ||
| 162 | .filter_map(&:subject).index_by(&:name) | ||
| 163 | safe_join(names.map { |n| | ||
| 164 | asset = by_name[n] | ||
| 165 | next h(n) unless asset | ||
| 166 | |||
| 167 | parts = [link_to(h(n), asset_path(asset))] | ||
| 168 | unless params[:asset_id].to_s == asset.id.to_s | ||
| 169 | parts << link_to(t("node_actions.asset_history"), | ||
| 170 | admin_log_path(:asset_id => asset.id), | ||
| 171 | :class => "node_action_zoom") | ||
| 172 | end | ||
| 173 | safe_join(parts, " ") | ||
| 174 | }, ", ") | ||
| 175 | end | ||
| 176 | |||
| 141 | def summarize_publish action | 177 | def summarize_publish action |
| 142 | if action.metadata["via"] == "revision" | 178 | if action.metadata["via"] == "revision" |
| 143 | t("node_actions.publish_rollback", | 179 | t("node_actions.publish_rollback", |
| @@ -193,20 +229,20 @@ module NodeActionsHelper | |||
| 193 | 229 | ||
| 194 | def summarize_asset_create action | 230 | def summarize_asset_create action |
| 195 | t("node_actions.asset_create", :actor => actor_ref(action), | 231 | t("node_actions.asset_create", :actor => actor_ref(action), |
| 196 | :asset => h(action.metadata["asset_name"].presence || action.metadata["path"])).html_safe | 232 | :asset => asset_ref(action)).html_safe |
| 197 | end | 233 | end |
| 198 | 234 | ||
| 199 | def summarize_asset_attach action | 235 | def summarize_asset_attach action |
| 200 | m = action.metadata | 236 | m = action.metadata |
| 201 | key = m["headline"] ? "node_actions.asset_attach_headline" : "node_actions.asset_attach" | 237 | key = m["headline"] ? "node_actions.asset_attach_headline" : "node_actions.asset_attach" |
| 202 | t(key, :actor => actor_ref(action), :subject => subject_ref(action), | 238 | t(key, :actor => actor_ref(action), :subject => subject_ref(action), |
| 203 | :asset => h(m["asset_name"].presence || m["path"])).html_safe | 239 | :asset => asset_ref(action)).html_safe |
| 204 | end | 240 | end |
| 205 | 241 | ||
| 206 | def summarize_asset_destroy action | 242 | def summarize_asset_destroy action |
| 207 | m = action.metadata | 243 | m = action.metadata |
| 208 | parts = [t("node_actions.asset_destroy", :actor => actor_ref(action), | 244 | parts = [t("node_actions.asset_destroy", :actor => actor_ref(action), |
| 209 | :asset => h(m["asset_name"].presence || m["path"]))] | 245 | :asset => asset_ref(action))] |
| 210 | parts << t("node_actions.asset_destroy_detached", | 246 | parts << t("node_actions.asset_destroy_detached", |
| 211 | :paths => h(Array(m["detached_from"]).join(", "))) if m["detached_from"].present? | 247 | :paths => h(Array(m["detached_from"]).join(", "))) if m["detached_from"].present? |
| 212 | parts << t("node_actions.asset_destroy_headlines", | 248 | parts << t("node_actions.asset_destroy_headlines", |
