I need to read out all available actions from any controller in my web-app. The reason for this is an authorization system where I need to give users a list of allowed actio
Grails does not support a straightforward way to do this. However, I was able to put together a puzzle from available grails methods and have come to this solution:
def actions = new HashSet()
def controllerClass = grailsApplication.getArtefactInfo(ControllerArtefactHandler.TYPE)
.getGrailsClassByLogicalPropertyName(controllerName)
for (String uri : controllerClass.uris ) {
actions.add(controllerClass.getMethodActionName(uri) )
}
Variables grailsApplication and controllerName are injected by grails.
As controller itself does not have necessary methods, this code retrieves its controllerClass (see GrailsControllerClass), which has what we need: property uris
and method getMethodActionName