简体   繁体   中英

What are the pros and cons of using separate user models for regular users and admin users?

I wonder what are the pros and cons of using separate user models for regular users and admin users like User and AdminUser models.

One advantage that I can think of is authorization will be easier and it will lessen the chance that you'll make mistakes in authorizing users.

I'm currently planning to switch to using separate user models for one of our projects. Since I think its a good fit for our use case since admin users don't really have to be able to do the things that a logged-in regular user can do (like view his/her purchase history, wish list, etc...) and logged-in regular users can't do the things that admin users can do (like view reports, ban a user, etc...) but I wanted to know its pros/cons first.

To give some additional context, our project uses the following tools:

  • Ruby on Rails
  • Active Admin gem
  • Pundit gem
  • Devise gem

Your project has got all you need for convinient role model user management and authorization. Pundit is a beautiful tool that was developed exactly for avoiding code duplication, unnesessary controllers and views grows. One pros to divide users and admins I can imagine is maybe nice looking url and routes helpers like admin_path, app/admins/2 etc, but if you want you can implement this for your role based projects also. So I see no point in this approach, but maybe I miss something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM