Skip to content

Modifier only changes when defined explicitly #80

Open
@ivobenedito

Description

@ivobenedito

Hi,

Let's imagine we're using mogoid-history for History Tracking on Articles and also using devise which implements current_user for the controllers.
Every time we create a new article, we need to define the modifier explicitly, for example:

def create
  @article = Article.create(params[:article].merge(modifier: current_user))
end

Now, every time we update an article, we need something similar to this:

def update
  @article = Article.find(params[:id])
  @article.update_attributes(params[:article]) # without merging current_user explicitly
end

The documentation says we don't need to define explicitly the modifier when updating attributes if we have the current_user available.
But looking at mongoid-history code itself, this is the before_create callback:

def before_create(track)
  modifier_field = track.trackable.history_trackable_options[:modifier_field]
  modifier = track.trackable.send modifier_field
  track.modifier = current_user unless modifier # this condition will always prevent a different current_user if there's a modifier already defined from the model creation
end

Is this a bug, or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions