Hello, I need help. I have an application that has two user types (A and B), each with their own model/table. User Type A can create information within their sub-domain account (I''m using account_location plugin for this). They have access to three controllers. User Type B has no such powers. She can only browse the home-page and sub-domain accounts, and maybe, in the future , organise content for her own viewing. I''m using some basic authentication for User Type A, with a before_filter in application.rb that determines account ID (from the sub-domain) and whether the appropriate user has logged in. For the home-page, I have a skip_before_filter for the application.rb authentication functions. So now, an anonymous user can access functions within the home-page controller in order to view content. How can I authenticate user type B so that she can have a few extra privileges than an anonymous user, throughout the homepage controller and another controller that will cater for viewing of sub-domain accounts, without interfering with User Type A authentication? Can I still use the application.rb for additional authentication functions for User Type B? Thank you for your time. Camilo Cienfuegos -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Camilo Cienfuegos wrote:> Hello, > > I need help. I have an application that has two user types (A and B), > each with their own model/table. User Type A can create information > within their sub-domain account (I''m using account_location plugin for > this). They have access to three controllers. > > User Type B has no such powers. She can only browse the home-page and > sub-domain accounts, and maybe, in the future , organise content for her > own viewing. > > I''m using some basic authentication for User Type A, with a > before_filter in application.rb that determines account ID (from the > sub-domain) and whether the appropriate user has logged in. For the > home-page, I have a skip_before_filter for the application.rb > authentication functions. So now, an anonymous user can access functions > within the home-page controller in order to view content. How can I > authenticate user type B so that she can have a few extra privileges > than an anonymous user, throughout the homepage controller and another > controller that will cater for viewing of sub-domain accounts, without > interfering with User Type A authentication? Can I still use the > application.rb for additional authentication functions for User Type B? > > Thank you for your time. > > Camilo Cienfuegos > > -- > Posted via http://www.ruby-forum.com/.Couple of points here. First, check to see if your user models are similar enough that you may actually want to use single table inheritance. Second, take a look at the User/Login Engines. They allow you to define which actions a user can access based on their ''role''. This sounds a lot like what you are trying to do. _Kevin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
>> -- >> Posted via http://www.ruby-forum.com/. > > Couple of points here. > > First, check to see if your user models are similar enough that you may > actually want to use single table inheritance.Hello, The two user models are fundamentally different. User Type A has a a dozen or more attributes, whereas User B has a password, username and name. Would it be sound practice to have a centralised model for users, holding just the basic fields (username, password, user type) and separate tables to hold additional attributes for each of the two user types? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rails && users && roles Reply Reply to all Reply to allForward Forward Print Add Chris to Contacts list Delete this message Show original Message text garbled? Chris Kilmer to Lee show details 11:58 am (3½ hours ago) Okay, I''ve been thing about this whole user/role business with Rails. Simple scenario: A restaurateur has multiple restaurants A restaurant has multiple restauranteurs A restaurant has multiple chefs Both restaurateurs and chefs can be any other kind of user as well, i.e. ''marketer, member'' The base data for all users is the same: create table user ( email password first_name last_name ) create table restaurateur ( is_admin is_owner ) Rails STI won''t work because a user is not limited to a single user_type. So, has_many :through seems the way to go. However, I want concrete models for each user type, i.e. Restaurateur, Member, Chef, etc. class user has_many :restaurateurs has_many :restaurants, :through => :restaurateurs end class restaurant has_many :restaurateurs has_many :users, :through => :restaurateurs end class restaurateur belongs_to :user belongs_to :restaurant end With this setup, if I wanted to iterate through each restaurateur and print out the email address, I would have to do something like restaurant.restaurateurs.each do puts restaurateur.user.email end I want to clean the api up so that I can just do restaurateur.email. My thought was to create a UserProxy module: module UserProxy def name self.user.name end ... end and then include the proxy in each user based class, i.e. class Restaurteur include UserProxy end This cleans up the api significantly and allows the proxy to be used between all user types. Of course, if the user class changes, so does the proxy, which is a big pain in the ass for maintenance. So, I''m interested in what your thoughts are: 1. This particular solution 2. How to build the proxy so that I don''t have to define each method/attribute by hand within the proxy, i.e. how to copy the User definition to the UserProxy in the most efficient manner. I''ve looked into delegate, Forwardable and missing_method. I can''t seem to get the syntax right or I''m just missing some concept. Any ideas, thoughts, code (especially code :-) ... would be appreciated. Cheers -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ryan.raaum-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-19 14:07 UTC
Re: Different User Types
On Dec 18, 7:01 pm, Chris Kilmer <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> rails && users && roles > > Reply > Reply to all Reply to allForward Forward Print Add Chris to Contacts > list Delete this message Show original Message text garbled? > Chris Kilmer > to Lee > > show details > 11:58 am (3½ hours ago) > > Okay, I''ve been thing about this whole user/role business with Rails. > > Simple scenario: > A restaurateur has multiple restaurants > A restaurant has multiple restauranteurs > A restaurant has multiple chefs > > Both restaurateurs and chefs can be any other kind of user as well, i.e. > ''marketer, member'' > > The base data for all users is the same: > > create table user > ( > email > password > first_name > last_name > ) > > create table restaurateur > ( > is_admin > is_owner > ) > > Rails STI won''t work because a user is not limited to a single > user_type. > > So, has_many :through seems the way to go. However, I want concrete > models for each user type, i.e. Restaurateur, Member, Chef, etc. > > class user > has_many :restaurateurs > has_many :restaurants, :through => :restaurateurs > end > > class restaurant > has_many :restaurateurs > has_many :users, :through => :restaurateurs > end > > class restaurateur > belongs_to :user > belongs_to :restaurant > end > > With this setup, if I wanted to iterate through each restaurateur and > print out the email address, I would have to do something like > > restaurant.restaurateurs.each do > puts restaurateur.user.email > end > > I want to clean the api up so that I can just do restaurateur.email. > > My thought was to create a UserProxy module: > > module UserProxy > def name > self.user.name > end > > ... > end > > and then include the proxy in each user based class, i.e. > > class Restaurteur > include UserProxy > end > > This cleans up the api significantly and allows the proxy to be used > between all user types. > > Of course, if the user class changes, so does the proxy, which is a big > pain in the ass for maintenance.Well, if the user class changes, updating the proxy is the least of your concerns. You''ll also have to update the associations in every class, change the db column names or add the :class_name option to all your associations, and so on. So I''m not sure that''s a good strike against your current solution. I haven''t really thought it through in detail, but have you considered a "Role" model and join table. A user has many roles (owner, chef, marketer, etc.). You can hook up the associations with using the foreign_key and conditions options, _and_ it gives you some flexibility to add more roles in the future without necessarily adding more tables and classes...> > So, I''m interested in what your thoughts are: > > 1. This particular solution > 2. How to build the proxy so that I don''t have to define each > method/attribute by hand within the proxy, i.e. how to copy the User > definition to the UserProxy in the most efficient manner. > > I''ve looked into delegate, Forwardable and missing_method. I can''t seem > to get the syntax right or I''m just missing some concept. > > Any ideas, thoughts, code (especially code :-) ... would be appreciated. > > Cheers > > -- > Posted viahttp://www.ruby-forum.com/.-- Ryan Raaum http://raaum.org http://rails.raaum.org -- Rails docs http://locomotive.raaum.org -- Self contained Rails for Mac OS X --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---