Ethan
Ethan

Reputation: 6913

Stop Grails Controller from showing add option

I am trying to use Grails to host a simple (personal) website, and was looking for a way to disable(or password protect them) the controller from showing the add and edit buttons for a Domain Object.

My Controller looks like this:

class DownloadsController {
    static scaffold = Download
}

My Domain Class looks like this:

class Download {

    static mapping = {
    }

    static constraints = {
        link(url: true)
    }

    String name
    String link

}

Any ideas?

Upvotes: 0

Views: 60

Answers (2)

aldrin
aldrin

Reputation: 4572

If you are using the Spring security plugin, you can secure the urls for edit and add (and the POST urls) in the controller. See http://grails-plugins.github.io/grails-spring-security-core/docs/manual/guide/5%20Configuring%20Request%20Mappings%20to%20Secure%20URLs.html

If you are not using Spring Security, you may want to consider it as it seems to fit your requirements well. There are also convenient tags for use in your views (see http://grails-plugins.github.io/grails-spring-security-core/docs/manual/guide/6%20Helper%20Classes.html)

Upvotes: 1

user553180
user553180

Reputation: 626

For a quick and dirty solution, you can override the edit/add scaffolded actions in your controller, like so:

class DownloadsController {
   static scaffold = Download

   //override scaffolded edit
   def edit() {
      redirect(action: "list")
   }

   //override scaffolded add
   def add() {
      redirect(action: "list")
   }
}

If you require a more sophisticated solution, have a look at the spring security core plugin

Upvotes: 0

Related Questions