How do I implement a many-to-many relationship with a checkbox to assign permissions to a role in Nova 4? - laravel-nova

How do I implement a many-to-many relationship with a checkbox to assign permissions to a role in Nova 4?
I have tables (roles and permissions and role_permission), I want to apply multiple permissions to a role in the role page.
BelongsToMany::make('permissions')

Related

pundit rails - how to user .has_role? in another table other than role?

In using rails I run in to a situation where I have to use my own tables in authorizing the user rather that using the default role and user tables (i.e. user.has_role? on role table,).
how do I implement (authorize) using my own created tables in policy file for a certain model/class - as the roles and permissions are stored in another table: permissions table, where i have a user id, role id.
Thanks

SimpleMembershipProvider: Separate user profile tables for user and admin accounts

I am using WebMatrix.WebSecurity in my ASP.NET MVC 5 application.
The Problem:
I need to separate regular user accounts and admin accounts in my application and I want to store them in two different tables like [UserAccounts] and [AdminAccounts]. Is that possible with the SimpleMembershipProvider and WebSecurity to have two different user profile tables?
For example, when I create a customer account, I want the [UserAccounts] table to be referenced from the [webpages_Membership] table, but when I am creating an admin account the [AdminAccounts] table should be referenced as a user profile table.
Actually I feel like I am on the wrong way. What is basically the best approach to separate customer and admin accounts?
you can seperate two roles. Admin and User... SimpleMembership creates the UserInRoles table..
This is best approach to seperate customer and admin accounts.
you can control to users which account with the User.IsInRole() method as programaticly..
I know about roles. My question was about having two different tables for customers and administrators with two different sets of columns and handle it with one SimpleMembershipProvider. My research on this topic showed this is not possible.

Where to store user role in database in Rails? Using CanCan, Devise, and Role_Model

I have a rails app with authentication already set up using Devise. I'm adding CanCan and Role_Model. Adding abilities seems easy enough. However I'm unsure where to store the user's role. Should I:
Add a column in the user db table for role?
Add a separate table or tables for role and role_user?
Add the role somewhere else?
This depends on how roles will be implemented in your application.
If roles will be inherited, for example admin < registered user < guest, meaning that admin is able to do everything reg. user and guest are capable of (and so on) then you may want to only add a single role field on a common user model.
If "actions" in your app a tied to a special roles that do not inherit permissions (unlike above), i.e. you need to have multiple roles on admin in order to do some common interaction with application (like guest does), then you need a join table, populated with user_id, role_id pairs.
I personally prefer the first option.

How do I add protected registration fields with devise?

I'm using devise for authentication on Rails 3.1. Users are to be registered by administrators on my site (it's a site internal to a school, unknown people should not register.) Each user is alloted a role (Eg, student, teacher, admin, resource_person) on registration, and this role is used for authorizing activities.
Now I don't want the user to be able to edit their role, hence it's not placed under attr_accessible. Because of this, I'll have to manually set the role from the parameters when registering a user. Is there any simple way to do this with devise, or must I create a custom controller that inherits from the devise registration controller?
Assuming you simply want to be able to manage users as an admin, I think the best way is to simply create a CRUD interface for your users model (https://github.com/plataformatec/devise/wiki/How-To:-Manage-users-through-a-CRUD-interface).
If you want users to be able to manage some of their model (e.g. password changing), simply authorize them according to their role.

Roles that are User<>Project Based

Currently I'm using Devise & CanCan which allows me to create
Users with Roles using a (Roles_Users) table.
That's nice, but what I want is to Have Projects in my app and for
each project for a user to possibly have a role like (Admin, Viewer,
etc) IE, roles are not assigned to users but to users based on what projects they are a member of.
Examples:
User X belong to Project A with an Admin Role
User X belong to Project B with an Guest Role
User Y belong to Project B with an Observer Role
What kind of Model would work for this?
Models
Users
has_many: projects
Projects
?
Roles
?
Users_Roles_Projects (user_id, project_id, role_id)
What do you think? I'm a newbie and could use the understanding and
thinking from you fine experienced folks. Thanks!
You should have a look in to has_many :through. This Railscast should get you up and running: http://railscasts.com/episodes/47-two-many-to-many
For example, you could have User has_many Projects through Memberships (I'm sure you can come up with a better name!)
Your Users model would contain the standard user details, the Projects model would contain the project details and presumably you have some Roles model somewhere (I've not used either of the libraries you mentioned so I can't comment in terms of how they work). The key is the Memberships model.
The membership model would contain the userID, projectID and a roleID. In the database there should only be one instance of any given userID and projectID pairing so by storing the roleID along side this pairing you can assign the role to that user on the specified project.

Resources