Grails RestfulController覆盖资源更新

时间:2016-08-31 03:05:59

标签: database rest grails save override

所以我在Grails中更新资源时遇到了一些麻烦。所以这是我的控制器,我在其中覆盖了一些方法

@Override
protected saveResource(resource) {
    if (request.post) {
        permissionsService.addPermission(resource.id, springSecurityService.getCurrentUser(), 'Outing')
    }
    resource.save(flush: true)
}

@Override
protected updateResource(resource) {
    if (permissionsService.isAdmin()) {
        println 'doesnt print'
        saveResource(resource)
    } else if (permissionsService.canWrite('Outing', params.id, springSecurityService.getCurrentUser())) {
        println 'doesnt print'
        saveResource(resource)
    } else {
        println 'prints to console'
        response.status = 404
    }
}

这就是控制器顶部的样子

import grails.converters.JSON
import grails.rest.*

class OutingController extends RestfulController {

    static responseFormats = ['json']
    OutingController() {
         super(Outing)
    }
...............
}

我的问题是,当我执行PUT时,由于某种原因,资源仍然会更新并保存。我无法弄清楚为什么,因为它从来没有击中saveResource或任何其他保存功能据我所知。我希望它返回状态404,但我可以使用它的一些帮助。我基本上是在为restful controller添加权限。谢谢你的帮助

如果你想看,这是RestfulController。 https://github.com/grails/grails-core/blob/master/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy

0 个答案:

没有答案
相关问题