Eine Historie wer wann etwas erstellt oder geändert hat. Dazu noch Bestätigung durch Passworteingabe.
Meine Verwendung entstand darin, dass ich das Anlegen und Bearbeiten von Berichten absichern wollte. Des weiteren wollte ich nachvollziehen können wer alles daran gearbeitet hat. Logging oder die Basis-Attribute wie created_by und updated_by waren mir dabei zu wenig. Es musste mehr her!
Was muss man machen:
Der Klasse User beibringen wer der current_user ist.
Durch z.B.:
User.rb: cattr_accessor :current_user
Application.rb: before_filter :set_current_user
protected
def set_current_user
User.current_user = self.current_user
end
Engines usw werden wie immer gebraucht.
Der Modelklasse sagen:
legitimized
Keine Parameter, nichts. Arbeitet in Form einer Validierung und als virtuelles Attribut wird legitimization hinzugefügt.
In der Form das folgende eintragen:
<%= legitimization_field(formname) %>
Was muss ich tun wenn ich nun noch für eine bestimmte Instanz die Geschichte möchte?
<%= link_to “Legitimizations”.t, :controller => “legitimizations”, :action => “report”, :modeltype => “Type”, :id => @instance %>
Feedback ist hier gern gesehen!!!
————-
————
English (taken from README):
Description:
Ever had the Problem that an User should not only have the Permission to create or edit somithing, but also
sign it when he does so? Well, here comes legitimizations.
Once set for an ModelClass, whenever an Instance is created or edited, we want to have an Attribute legitimization to be present and
compare it to the current_user’s password. Than we Log it for this instance.
What has been done can always be viewed. Like an Histroy.
What to do?
well, first thing: set up your User-Model to have an attribute called current_user for reference.
Example: User.rb: cattr_accessor :current_user
Application.rb: before_filter :set_current_user
protected
def set_current_user
User.current_user = self.current_user
end
If someone knows an better way to do this, tell me
So what really needs to be done?
1. Migrate using the migrations
2. have Engine Additions!!!
3. add legitimized to your desired models (for options see API)
4. in the correct forms add: <%= legitimization_field(formname) %>
That’s all!
No your users have to pass their password to us, when they want to do an create or update.
Pretty simple and cool, isn’t it?
Oh, and when you want to have an report for an Instance:
<%= link_to “Legitimizations”.t, :controller => “legitimizations”, :action => “report”, :modeltype => “Type”, :id => @instance %>
Subversion: http://svn.sjoker.net/svn/railsplugins/trunk/legitimizations