Skip to content

Commit

Permalink
Cleanup model
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Oct 18, 2023
1 parent bc37de1 commit 14b79bf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/controllers/changelog_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def scoped_object

klass = params[:object_type].camelize.singularize.safe_constantize

klass&.find(params[:object_id])
if klass.respond_to?(:friendly)
klass&.friendly&.find(params[:object_id])
else
klass&.find(params[:object_id])
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/changelogable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def changelog_entry_on_destroy
def _create_changelog_entry(action, object_changes: previous_changes, metadata: {})
changelog_entries.create!(
action: action,
object_changes: object_changes,
object_changed_attributes: object_changes,
metadata: ChangelogContext.metadata.to_h.merge(metadata)
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/changelog_entries/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</dl>

<h3>Changes</h3>
<%= debug @changelog_entry.object_changes %>
<%= debug @changelog_entry.object_changed_attributes %>

<h3>Metadatas</h3>
<dl class="dl-horizontal">
Expand Down
4 changes: 3 additions & 1 deletion db/migrate/20231004123921_create_changelog_entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def change
t.references :object, polymorphic: true, null: false
t.references :author, polymorphic: true, null: true
t.string :action, null: false
t.jsonb :object_changes, null: false, default: {}
t.jsonb :object_changed_attributes, null: false, default: {}
t.jsonb :object_pre_change_attributes, null: false, default: {}
t.jsonb :object_post_change_attributes, null: false, default: {}
t.jsonb :metadata, null: false, default: {}

t.timestamps
Expand Down
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tasks/convert_activities_to_changelog_entries.rake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ task convert_activities_to_changelog_entries: :environment do
author_id: activity.owner_id,
author_type: activity.owner_type,
action: activity.key.split(".").last,
object_changes: activity.parameters.presence || {},
object_changed_attributes: activity.parameters.presence || {},
metadata: {
activity_id: activity.id
}
Expand Down

0 comments on commit 14b79bf

Please sign in to comment.