Symfony sfGuardPlugin: disable default routes - symfony1

I'm using the sfGuardPlugin in symfony 1.4 and I'm wondering how to get rid of its "default" routes. I mean by that the "guard/users", "guard/permissions" and "guard/groups" routes.
Indeed I have designed my own backend without admin generator, and I've recreated these three pages with customs urls. So how can I disable the access to the default sfGuard pages ?

app.yml:
all:
sf_guard_plugin:
routes_register: false
as stated in the documentation.

You should update the file
/config/sfDoctrineGuardPluginConfiguration.class.php
to the lasted version.
Before the lasted update, despite the documentation, the routes did get registed anyway.
It seems you are using the previous version of this file.

To desactivate these 3 modules : you just have to remove the sfGuardGroup, sfGuardUser, sfGuardPermission from the settings.yml for backend application.
all:
.settings:
enabled_modules: [default, sfGuardAuth, sfGuardGroup, sfGuardUser, sfGuardPermission]
In order to keep only the authentification module
all:
.settings:
enabled_modules: [default, sfGuardAuth]
However I have no idea what default is.

If you (i) still want to use the modules provided by the plugin, (ii) using your own routes, (iii) preventing people from using the default sfGuard routes and (iv) still have the default /:module/:action route (which is rather useful), you can override the sfGuardRouting class, which is here
plugins/sfGuardPlugin/lib/routing/sfGuardRouting.class.php
You can simply copy this file to your
lib/
directory and then play with the methods. For instance I just commented all the code of all methods of the class (since I made my own routes in my apps/myApp/config/routing.yml file) for the modules of the sfGuardPlugin), like this
class sfGuardRouting
{
static public function listenToRoutingLoadConfigurationEvent(sfEvent $event)
{
// $r = $event->getSubject();
// preprend our routes
// $r->prependRoute('sf_guard_signin', new sfRoute('/guard/login', array('module' => 'sfGuardAuth', 'action' => 'signin')));
// $r->prependRoute('sf_guard_signout', new sfRoute('/guard/logout', array('module' => 'sfGuardAuth', 'action' => 'signout')));
}
}

Related

Rails - Add a route prefix to a specific directory

I have a messy rails 3 application that's come from a different developer and I need to refactor it.
What I want to do is move the contents of "app" into a subfolder called "classic".
app/classic
And then have all URL's with a classic prefix such as
localhost:3000/classic/wills/new
Route to controllers inside of the "app/classic" folder.
And then every regular url that does not contain the classic prefix - route in the standard way to app/
Is it possible to do this? The only thing I've discovered so far is that I can add a scope inside of my routes file.
scope(:path => '/classic')
But all that does is require a prefix for every URL. I'm really not sure how to go about this!
This is a route namespace. Take a look at this section in Rails Routing from the Outside In: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
namespace :classic do
# your routes here
end
This will do 3 things -
the path to the controller files need to be under /app/controllers/classic/
the name of the controllers need to change to Classic::ControllerName
the url is now /classic/controller/action
This sounds like what you want, but you can modify this to get just the parts you want if you don't want all 3.
In route.rb file:
#Of course, you have to configure the right http method.
get 'wills/new' => 'wills#new', as: 'to_classic_wills_new'
Hope this helps!

How can I restrict the API calls in rails?

I am the admin and multiple people are working on the project. New routes are being created everyday(basically APIs). I want a central record of all the routes(controllers and respective actions). I want a route to work only if it is listed in that record(yml file).
I have heard that it is possible to manage the resources by creating a yml file, though being new to rails I am not sure how to do it.
Suggestions would be highly appreciated.
I think I need to be more explicit about the query I have.
Agreed that we need to list all the GET,POST PUT AND DELETE requests in route in order to redirect a call.
What I am looking for is another YML file which will have the contollers and respective actions listed. The actions listed here should only be allowed to be routed and not others present in the route.rb.
Example :
I have the following route:
GET "fetch_ids" => "get_id#select"
Now if "get_id#select" is listed in my YML only then a route would be allowed.
How can I set this up?
It already works like that. No matter if you create a controller or an action, the controller and the action will be accessible only if they are somehow listed in the routes.rb file.
You can have 10 controllers, but just one in the routes.rb. The other 9 will not be reachable.
To list all the routes simply run
$ rake routes
To have a list of all routes that available, please try this Rack app (part of config/routes.rb)
match "/secret_routes" => proc { |env| [ 200, {'Content-Type' => 'text/plain'}, [Application.routes.routes.collect{|i| i.path.spec.to_s}.join("\n")] ] }

Rails ActiveAdmin Routing new Resources

I'm just starting out with Rails and I decided to try out ActiveAdmin last night. I was able to register a new resource name 'Pages' in my ActiveAdmin app, but there's one thing I can't figure out how to customize with it.
I create a new Page with ActiveAdmin, but it's published within the admin/.. path.
(e.g. mydomain/admin/page/1)
How do I change the routing so the page can be viewed at mydomain/page/1?
Are you able to change the routing of existing resources in ActiveAdmin?
I'm very new at Rails so I assume this is a pretty easy fix. I plan to run through some more tutorials/books so I can better understand routing.
You can change the default admin namespace.
To do so you have to go to config/initializers/active_admin.rb file and find the following configuration:
# Default:
# config.default_namespace = :admin
Uncomment the line and set the default_namespace to whatever you need.
However, if you need to turn off the namespace at all, you will have to set the default_namespace to false:
config.default_namespace = false
This will allow you to run the AA from the root.
By doing so be aware of changes in routes:
if changed the namespace to hello, the admin_games_path becomes hello_games_path;
if changed to no namespace, use normal routes: admin_games_path becomes games_path.

Prepend path prefix to all rails routes

I have a setup where nginx serves a rails application inside a specific subfolder
eg. http://myserver/railsapp/ and everything inside gets proxied to rails, if the first subfolder is different, it servers static files from another folder.
I haven't been able to find how to specify this behaviour in rails in an intelligent way. I mean, what I want is to specify an option like Rails.server_prefix = /railsapp so that all the routes get prepended automagically, both on the incoming requests and on the generated links.
You probably want to use the router's scope method with the :path argument:
Rails.application.routes do
scope(:path => '/railsapp') do
# the rest of your routes go here
end
end
See the docs for more info.

Namespaced routes in rails 1

I'm working with some legacy code with the last version of rails 1. Upgrading to a later version of rails isn't possible and as such map.namespace is a private method in this version, otherwise I'd be using it.
I have several resources which I have nested into a submenu for simplicity. Their controllers are all within the folder of that submenu and all inherit that controller's namespace.
I'm having major issues with the sub elements. I have mapped the resources and applied a prefix to them in the form of
map.resources :subitem, :path_prefix => "/sub_menu"
but I'm having major issues with using RESTFul methods on these nested objects. The paths that I'm trying to use, say to delete an object simply do not work.
I'm refactoring this current code base so there's very little I can do, and there's very little I can find on rails 1 routes online. It's a bit of a finicky issue but maybe I've missed something simple about routes.
Do I simply need to manually write out every particular route I can use and then manually prefix it, or is there a simpler way?
My other routes work fine, I simply cannot use the
subitem_path(subitem) :method => :delete
function in my link to
So I figured out how to layout the routes appropriately so I could access the paths
Add to the above route the specified controller you're using and the routes will map accordingly
map.resources :subitem, :path_prefix => "/sub_menu, :controller => "submenu/subitem"
Thanks!

Resources