Grails

Grails Controller filters should allow exclusion of actions/controllers

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.2-M1
  • Fix Version/s: 1.4-M1
  • Component/s: Commons
  • Labels:
    None
  • Environment:
    All

Description

Grails filter definitions should allow for exclusion of some actions, as follows:

myFilter(controller:'', action:'') {

}

could allow:

myFilter(includes:{controller:'*', action:'*'}, excludes:{controller:'notthisone', action:'book'}) {

}

or

myFilter(controller:['xxx','yyy'], action:['foo','bar']) {

}

Not sure of the exact format it should take, but you should be allowed to filter "all except", or you should be able to explicitly define what you want filtered such as "these four controllers" and "these three actions"

Activity

Hide
Vincent Coste added a comment -

This is a very annoying situation in deed.
If we only take the example of a really simple login system that must filter all the controllers except one, it keeps us from beeing dry.

Cheers,

Show
Vincent Coste added a comment - This is a very annoying situation in deed. If we only take the example of a really simple login system that must filter all the controllers except one, it keeps us from beeing dry. Cheers,
Hide
Rich Kroll added a comment -

A workaround to this problem is:

myFilter(controller:'', action:'') {
before = {
if(['controllerToExclude', 'anotherControllerToExclude']*.equals(controllerName)) { return true }

... other code ...
}
}

Show
Rich Kroll added a comment - A workaround to this problem is: myFilter(controller:'', action:'') { before = { if(['controllerToExclude', 'anotherControllerToExclude']*.equals(controllerName)) { return true } ... other code ... } }
Hide
Jeff Brown added a comment -

Feature added:

https://github.com/grails/grails-core/commit/0651aaa0536b3ae294410a7066f6e25dede4083e
https://github.com/grails/grails-core/commit/25b8265b96a01aeebb46ade63c85897ce4e8532c
https://github.com/grails/grails-functional-tests/commit/716fda34f0200d6464295de790d6d4778270d4e1
https://github.com/grails/grails-doc/commit/b0b0d671f544688c32d690a38947e67459389e5d

Exclusions can be expressed with actionExclude, controllerExclude or uriExclude.

filter1(actionExclude: 'log*') {
    before = {
        // ...
    }
}

filter2(controllerExclude: 'auth') {
    before = {
        // ...
    }
}

filter3(uriExclude: '/secure*') {
    before = {
        // ...
    }
}

More details in the user guide.

Show
Jeff Brown added a comment - Feature added: https://github.com/grails/grails-core/commit/0651aaa0536b3ae294410a7066f6e25dede4083e https://github.com/grails/grails-core/commit/25b8265b96a01aeebb46ade63c85897ce4e8532c https://github.com/grails/grails-functional-tests/commit/716fda34f0200d6464295de790d6d4778270d4e1 https://github.com/grails/grails-doc/commit/b0b0d671f544688c32d690a38947e67459389e5d Exclusions can be expressed with actionExclude, controllerExclude or uriExclude.
filter1(actionExclude: 'log*') {
    before = {
        // ...
    }
}

filter2(controllerExclude: 'auth') {
    before = {
        // ...
    }
}

filter3(uriExclude: '/secure*') {
    before = {
        // ...
    }
}
More details in the user guide.

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: