I have been following 2 separate tutorials to build a rails 3 app each of which covers modelling users. however they don't cover segregating users into groups. specifically im trying to create a users model where one group of users (consumers) would be limited to browsing, making purchases updating their own accounts when logged in, and a 2nd group (admins) would be able to add and maintain products and update their own accounts and possibly create other accounts to manage their products. any assistance on how to pull this off would be much appreciated.
This sort of thing is called roles (admins, consumers) and authorization (purchasing, updating). Gems are available which can help you with both.
I use CanCan for the authorization and make my own roles table. I'd recommend looking at Rubytoolbox to find out what your options are: https://www.ruby-toolbox.com/categories/rails_authorization
Related
We are trying to create different groups of users with restricted database
functionality using the railsAdmin plugin in Rails. Specifically, there is a
table in the database that indexes all personnel. We want to create two
levels of user accounts. "Admins" have access to all personnel. "Moderators"
have access to a subset of personnel only. Further, moderators should be
able to add personnel to the database, but they should be visible only to
that moderator and the admins. As an example, if user A is a moderator and
adds a person named "Dave,", we don't want Dave to be visible in the
dashboard for other moderators (e.g., B, C, etc). Similarly, if moderator B
adds a person, s/he should be visible only to moderator B. We are having
difficulty determining where in the code this type of functionality should
be added. Any pointers would be appreciated. Thank you.
Have you considered using CanCan with rails_admin?
There is a pretty good guide on authorisation using CanCan with rails_admin on their wiki:
https://github.com/sferik/rails_admin/wiki/Cancan
p.s. you might prefer to use CanCanCan which is more actively maintained
I am working on a job portal. I am confused on how I should create and manage users. For example: there will be 3 types of users(which may expand later) in my application: Company, Consultancy, and Candidates. Each of them will have a completely different role and access to the admin(i.e. account) panel/console, or you can say they will have a completely different views for managing their account. So, if a user logs in with a company account, he/she should be able to create jobs and update company profile, if a user logs in as a consultant then he/ she should be able post jobs on behalf of other companies(who may or may not be registered on the website/app) and should also be to surf/ search the jobs from companies and should be able to post applications(i.e. apply for a job) of candidates on candidates(who may or may not be registered yet on the website/app) behalf. And, if a user logs in as a candidate then he/she should be able to create their resumes/ cvs, search jobs, and apply for jobs posted by companies.
Here is what I'd thought: Create a User model and then have STI(Single table inheritance) for Company, Consultancy, and Candidate. But, STI gets complicated sooner than later. Later, I thought of creating different models for each, but then code will be repeated for login/ signups and other similar activities, which means no DRY.
I would like to follow the best approach possible. So, would like to know how experts will go about solving such a scenario? Thanks.
Some suggestions:
Look at the CanCan gem for user roles.
Look at devise for a login system where you can login users.
You can use active admin gem to create an administration backend ( crud, create remove update delete ) users. Or build an admin backend yourself
Also checkout railscasts.com ( theres a cast on cancan and devise also!) for general ruby on rails tips and tricks. http://railscasts.com/episodes/192-authorization-with-cancan
Checkout "micheal hartl ruby on rails course " for some general understanding of how models, controllers and views all relate to each other.
I have a web app that will have 4 different users on it:
Owner Admin (My Team and I)
Common User of the App (the everyday people using the site
Company Admins (The people who pay the bills)
Company Users
Of these the last 3 will require profiles and other controller and Model relations.
My question is do I create separate controllers for each of these users and have them link through their current devise ID to their individual profile, or should I edit the devise DB tables to accommodate for profiles and different levels of access?
Cheers,
Andrew
Mostly depends on what you want. I prefer to use a single table for all user types.
should I edit the devise DB tables to accommodate for profiles and different levels of access?
Again depends on what you want since there are many ways to provide different levels of access.
Edit user table (ie. roll your own solution on top of devise)
use authorization gem (eg. cancan)
Therefore no hard answers.
I am working on Rails 3.2. I am currently building tenant-based site which provides registration to the users. For users those want to register to the site, they need to get subscription plan provided from the site. Based on these subscriptions, I am supposed to provide different authorizations to users. For example, Plan A-subscription will allow user to create some 100 contacts, 100 events and no document uploads, while Plan B-subscription will allow user to create some 250 contacts, 200 events with document uploading features, etc. with further plans.
For this, I require data access authorizations at model level too.
In a nutshell, these functioning specifically lists all authorizations and Access Control lists for the users.
As working on Rails 3.2, I have found few gems which will help to declare authorization-rules for users.
fat_model_auth
declarative_authorization
These gems allow to specify authorization-rules for the application. But I need authorization-rules also at Model level while limiting the access to the database from the user's side. Please suggest me with few documentation or gems to get through...
Any suggestions would be helpful..
I would suggest
CanCan
there is a nice screencast on it aswell.
As the creator of fat_model_auth I can recommend it.
https://github.com/brentgreeff/fat_model_auth
Just released a new gem which works great with Rails 5.
I'm building out a SaaS application that allows an individual to signup and create an exclusive Group. The admin will then be able to add people to the group by e-mailing them (this will be used primarily internally by companies).
Unfortunately, I'm quite new to Rails and thereby not too sure where to begin.
All groups should be mutually exclusive and users should only be able to belong to one group.
Any suggestions of where to begin in terms of the Group / user relationship?
Thanks a lot.
In terms of the relationship between Users and Groups, it will be a one (Group) to many (Users) relationship. Bringing rails into context, you can take a look at ActiveRecord associations to give yourself the right knowledge about the types of functionality that's exposed. Everyone user :belongs_to only one Group, and Groups :has_many Users. If you need a primer on database relationships, you can check out any primer like this or any link you can find with some diligent googling.
You can try out some things and come back once you have something going, then others will be able to help you out more. If you are REALLY new to Rails, you can check out and try the running example here. Good luck.