Hello list, I have an app that has a very simple authorization scheme. A person can have many roles and roles can have many people. In my app, I''d like to do before_filter :login_required (since no role name is provided, it accepts any users with credentials) before_filter :login_required ("administrator") (only accepts those with role administrator) before_filter :login_required {"administrator", "buyer", "seller"} (accepts those with roles admin, buyer, seller) Now, I know the only way you can achieve this is to use the lambda function, but to me it looks very ugly. Right now I have multiple before_filter, first checking if they are logged in, then checking their role, etc. Is there any other way around this that Im not seeing? I tried to come up with an answer using sessions, but it got far too complicated. Any help would be fantastic, Jin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060227/ff960575/attachment.html
Ezra Zygmuntowicz
2006-Feb-27 22:36 UTC
[Rails] Send parameter along with method in before_filter
On Feb 27, 2006, at 2:18 PM, Jin Lee wrote:> Hello list, > > I have an app that has a very simple authorization scheme. A person > can have many roles and roles can have many people. > > In my app, I''d like to do > > before_filter :login_required (since no role name is provided, it > accepts any users with credentials) > before_filter :login_required ("administrator") (only accepts those > with role administrator) > before_filter :login_required {"administrator", "buyer", "seller"} > (accepts those with roles admin, buyer, seller) > > Now, I know the only way you can achieve this is to use the lambda > function, but to me it looks very ugly. Right now I have multiple > before_filter, first checking if they are logged in, then checking > their role, etc. > > Is there any other way around this that Im not seeing? I tried to > come up with an answer using sessions, but it got far too complicated. > > Any help would be fantastic, > > Jin > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsJin- I have a simple plugin that does thing for you with an easy declarative syntax and then it defines all the before filters for you. There is a write up here: http://brainspl.at/articles/2006/02/20/new-plugin-acl_system Cheers- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra@yakima-herald.com
Erza, lovely! I was able to get your acl system running, and its working smooth as butter now. I wasn''t being DRY in my code and this really cleaned things up. Thank you very much, Jin On 2/27/06, Ezra Zygmuntowicz <ezra@yakima-herald.com> wrote:> > > On Feb 27, 2006, at 2:18 PM, Jin Lee wrote: > > > Hello list, > > > > I have an app that has a very simple authorization scheme. A person > > can have many roles and roles can have many people. > > > > In my app, I''d like to do > > > > before_filter :login_required (since no role name is provided, it > > accepts any users with credentials) > > before_filter :login_required ("administrator") (only accepts those > > with role administrator) > > before_filter :login_required {"administrator", "buyer", "seller"} > > (accepts those with roles admin, buyer, seller) > > > > Now, I know the only way you can achieve this is to use the lambda > > function, but to me it looks very ugly. Right now I have multiple > > before_filter, first checking if they are logged in, then checking > > their role, etc. > > > > Is there any other way around this that Im not seeing? I tried to > > come up with an answer using sessions, but it got far too complicated. > > > > Any help would be fantastic, > > > > Jin > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > Jin- > > I have a simple plugin that does thing for you with an easy > declarative syntax and then it defines all the before filters for > you. There is a write up here: > > http://brainspl.at/articles/2006/02/20/new-plugin-acl_system > > Cheers- > -Ezra Zygmuntowicz > Yakima Herald-Republic > WebMaster > http://yakimaherald.com > 509-577-7732 > ezra@yakima-herald.com > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060228/c412bee9/attachment.html
Ezra Zygmuntowicz
2006-Feb-28 18:51 UTC
[Rails] Send parameter along with method in before_filter
Lin- Your welcome! I''m glad you could use it. Please do give feedback if you run into any issues or you have an idea you wold like to see added to the plugin. -Ezra On Feb 28, 2006, at 10:08 AM, Jin Lee wrote:> Erza, > > lovely! I was able to get your acl system running, and its working > smooth as butter now. I wasn''t being DRY in my code and this really > cleaned things up. Thank you very much, > > Jin > > On 2/27/06, Ezra Zygmuntowicz <ezra@yakima-herald.com> wrote: > On Feb 27, 2006, at 2:18 PM, Jin Lee wrote: > > > Hello list, > > > > I have an app that has a very simple authorization scheme. A person > > can have many roles and roles can have many people. > > > > In my app, I''d like to do > > > > before_filter :login_required (since no role name is provided, it > > accepts any users with credentials) > > before_filter :login_required ("administrator") (only accepts those > > with role administrator) > > before_filter :login_required {"administrator", "buyer", "seller"} > > (accepts those with roles admin, buyer, seller) > > > > Now, I know the only way you can achieve this is to use the lambda > > function, but to me it looks very ugly. Right now I have multiple > > before_filter, first checking if they are logged in, then checking > > their role, etc. > > > > Is there any other way around this that Im not seeing? I tried to > > come up with an answer using sessions, but it got far too > complicated. > > > > Any help would be fantastic, > > > > Jin > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > Jin- > > I have a simple plugin that does thing for you with an easy > declarative syntax and then it defines all the before filters for > you. There is a write up here: > > http://brainspl.at/articles/2006/02/20/new-plugin-acl_system > > Cheers- > -Ezra Zygmuntowicz > Yakima Herald-Republic > WebMaster > http://yakimaherald.com > 509-577-7732 > ezra@yakima-herald.com > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra@yakima-herald.com