Skip to content

Instantly share code, notes, and snippets.

@aadrian
Last active August 29, 2015 14:19
Show Gist options
  • Save aadrian/d0b2ff0e29c23ae2831f to your computer and use it in GitHub Desktop.
Save aadrian/d0b2ff0e29c23ae2831f to your computer and use it in GitHub Desktop.
Grails "Created By" and "Last Updated By" Fields.
// domain
class MyDomainEntity {
transient springSecurityService
// usual fields ...
String name
// ...
Date dateCreated
Date lastUpdated
String createdBy
String lastUpdatedBy
static transients = ['springSecurityService']
static constraints = {
// ... usual fields
dateCreated nullable: true
lastUpdated nullable: true
createdBy nullable: true
lastUpdatedBy nullable: true
}
String toString() { name }
def beforeInsert(){ createdBy = springSecurityService.getPrincipal()?.getUsername() }
def beforeUpdate(){ lastUpdatedBy = springSecurityService.getPrincipal()?.getUsername() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment