Adding Another Domain Class To Grails User App

First, create the domain class:

Next, add some fields and the SecUser class:

LInk it to SecUser:

Link SecUser to our new domain (we already had a Book class):

Add some constraints to our new domain:

Next, generate the controller and the views:

Add some imports in the MagazineController

Add the Spring Security Service:

Add the following annotation to the index and show methods:

Add the following annotation to everything else:

Change the save method to ensure the user ID is the logged in user:

Next, let’s change the views.

In index.gsp, wrap the link for the create action in a block to see if the user is logged in and has a “USER” role:

In show.gsp, we should put an if block around the links to delete and edit a magazine

There is no change at this time to create.gsp or edit.gsp.