-1

This might be a duplicate of a question already asked but i haven't found the one that suits my condition yet.

I am developing a system where there's a user (not an admin) who is registering himself using devise. What i want is to allow this user to create different users and provide them different set of permissions (so can't be predefined permissions and hence, cant use cancan as far as i am aware). To clarify more, this is the table structure i have come up with yet. Please guide me if i am going on the wrong path here.

USER:

id,
name,
other-details

PERMISSION

id,
name, (name of the section such as gallery, report or users)
create,
edit,
view,
user_id (the user whose permissions are defined here)

Here, create, edit and view are the permissions that the user would have. If the edit is true, he'll be able to edit that particular section. I'm sorry if this is not clear. I found Johan's answer (last one) Database schema for ACL match my scenario however i am not sure if its the right way. Also, i am not sure how to implement the SET mentioned there.

Thanx in advance. Also please feel free to ask for more details if required. I'm clueless about how right this method will be.

P.S: Newbie in Rails Here.

Community
  • 1
  • 1
Aakanksha
  • 956
  • 1
  • 13
  • 26

1 Answers1

0

You should use gem devise , cancancan & rolify for it. Check here for references https://github.com/RolifyCommunity/rolify/wiki/Devise---CanCanCan---rolify-Tutorial.

You should add your all roles with permissions in the ability.rb file

Chakreshwar Sharma
  • 2,571
  • 1
  • 11
  • 35
  • this is what i don't want. You see as far as i understood, i would need predefined roles but i don't have that in my system. Except the user, there is no subuser who will be definitely to have the permission to edit or create a new one. I apologise if i ma not clear here. – Aakanksha Apr 25 '16 at 12:26
  • No problem in creating roles using rolify but if u want the solution of above then you need to add a field "role" in user model in devise for sign up .https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address – Chakreshwar Sharma Apr 25 '16 at 12:33
  • i have no problem adding fields to the User table in devise. Its fun stuff and i have got a grip on it. or i think i have. I'll look for in the answer you suggested deeply. Meanwhile i'll wait for other suggestions as well. Thanx – Aakanksha Apr 25 '16 at 12:38
  • Also, i dont want roles. The role in the USER table is just to identify the parent or child user. Please see my updated post. – Aakanksha Apr 25 '16 at 12:46