Audit Trail

  • Tags: auditing
  • Latest: 2.0.0
  • Last Updated: 04 January 2012
  • Grails version: 1.3 > *
  • Authors: Joshua Burnett
1 vote
Dependency:
compile ":audit-trail:2.0.0"

 Documentation

Summary

Please use version 2.0.1,Version 2.0.0 has a big bug when use with spring-securite-ui

Description

See the docs here https://github.com/9ci/grails-audit-trail

https://github.com/9ci/grails-audit-trail

The Docs below are valid for versions 1.2 and earlier which will work with Grails < 1.3.6 For Grails version 1.3.6+ and 2.0.0+ please See the docs here https://github.com/9ci/grails-audit-trail the 2.0.0 version of this is compatible with Grails 1.3.7 and 2+ Stick with 1.2 for anything pre 1.3.6

~

~

This plugin lets you add an annotation to your domain classes so they will get stamped after a new insert or update. It release under the same Apache V2 license as Grails. It will automatically add fields based on your settings in Config.groovy. Provides an AST transfomation annotation and hibernate events to take care of stamping for your gorm objects with the user who edited or created the record.

Will also allow you to specify a default custom id mapping and generator so you don't have to add them to every class.

Overview

Currently works with Spring Security Core 1.0.1 and allows you to specify which domain object and what the fields will be called for stamping the id of a user who made a change or created the entity

Step-by-Step

1) Install the plugin for your project (you should already have the acegi plugin)

grails install-plugin audit-trail

2) stamp your domain classes and add the audit fields

@gorm.AuditStamp
class Note{
	String note
	static mapping = {} 
	static constraints = {}
}

3) edit your Config.groovy

setup your Config.groovy to map the appropriate fields. If you don't want a field added then just leave the configuration out

stamp{
	audit{
		//the created and edited fields should be present or they won't get added during AST
		createdBy="createdBy" //id who created
		createdDate="createdDate" // if you want a date stamp that is not the grails default dateCreated
		editedBy="updatedBy" //id who updated/edited
		editedDate="editedDate"//use this field instead of the grails default lastUpdate
	}
}

4) clean your project and recompile and make a change or add new to see if it got stamped

An AST transformation will add the createdBy and updateBy to your domain as Long fields and uses the principal().id from Spring Security to "stamp" the domain during a save.

Using without the annotation

The annotation only works with Gorm/groovy domains. The annotation is just an AST transformation as a convenience. You can add the fields manually to your any of your domains (grom or not) that match whats in the config.grooy and the events will work. This includes other hibernate/java entities. It uses the AuditTrailInterceptor to stamp the fields on the hibernate objects if they exists.

Versions

9/30/2010 version 1.0 - companyId no longer gets trampled on insert if it has a value. BREAKIING change. The nineci.grenbill.Stamp is now gorm.AuditStamp

10/5/2010 Version 1.1 - Requires spring-security-core instead of acegi, and hibernate 1.3