Sha256: abf5f617f7eba3ad75761b009a31f73dfb7c3a3e9d25c7c88a5eac57d6ee7b6a

Contents?: true

Size: 1.8 KB

Versions: 10

Compression:

Stored size: 1.8 KB

Contents

# Role and Permission Management

## Overview

We can manage the roles and permission through CmAdmin. CmAdmin creates pundit policies dynamically and helps us the manage the permission through a interface. 

## Features

- **Create Role:** We can create any role we want on the application
- **Manage Permissions:** All the possible actions are listed for each role and we can enable or disable permission for each role.

## Usage

- To add role and permission table

```
  rake cm_admin:install_role
```

- Rake task creates a default migration

- Create a role column on the user table. Note: The column name has to be `cm_role_id` else policy will fail

```
rails g migration AddCmRoleToUser cm_role:references
```

- Assign the role to the user. Right now only one role can be assigned to a user.

- Assigning the params in the current attribute.
```
In the `app/models/current.rb` add request_params as attribure

In the `app/controllers/concerns/authentation.rb` set the request_params. This helps cm-admin identify which action is being performed in the pundit policy.

module Authentication
  extend ActiveSupport::Concern

  included do
    before_action :check_current_user
    before_action :set_params
  end
  ...
  def set_params
    if params
      Current.request_params = params
    end
  end
end
```


## Override policy

By default, the Roles and policy gets enabled for all the models on the application. We can override the policy with the following

```
  ...
    cm_admin do
      actions only: []
      set_icon "fa fa-user"
      override_pundit_policy true
      cm_index do
        page_title 'User'
  ....
```

and create a policy file on the application for the respective model. eg: `app/policies/cm_admin/user_policy.rb`
```
class CmAdmin::UserPolicy < ApplicationPolicy


  def index?
    true
  end
  ...
end
```

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cm-admin-2.1.3 docs/RoleManagement.md
cm-admin-2.1.2 docs/RoleManagement.md
cm-admin-2.1.1 docs/RoleManagement.md
cm-admin-2.1.0 docs/RoleManagement.md
cm-admin-2.0.2 docs/RoleManagement.md
cm-admin-2.0.1 docs/RoleManagement.md
cm-admin-2.0.0 docs/RoleManagement.md
cm-admin-1.5.56 docs/RoleManagement.md
cm-admin-1.5.55 docs/RoleManagement.md
cm-admin-1.5.54 docs/RoleManagement.md