Audit information specified in a model … part 2
- One minute read - 174 wordsIn the first part of this post, I wanted to show how easy it is to access information from the currently logged in user and store this information in an action the user executes (who created/changed a record).
Now, what happens, if we have several groups of users (roles)? Well, I could create some IF..ELSE block for each role, but this would probably be not a good idea. A much better approach is to create a base class within the model and inherit all roles from this. So, the model could for instance look like this:
The service to create a new customer will then look like this:
So, in order to access information from the currently logged in user, I would refer to the login attribute of the base class named “RoleBase” with the keyword “AGENT_RoleBase.login”. Using a construct like this, I do not have to take care of different roles and the field in the table will always contain the login ID of the user … whatever role he may refer to.