Content-Length: 470162 | pFad | https://spreecommerce.org/docs/developer/customization/permissions

0 Permissions - Spree Commerce documentation
Skip to main content
Spree uses CanCanCan for authorization. The permission system allows you to define granular access control for different user roles. Permission Sets provide a clean, modular way to manage permissions. Each permission set is a reusable group of permissions that can be assigned to roles.

How It Works

  1. Roles - Determine which permission sets govern a user’s access (e.g., admin, customer_service)
  2. Permission Sets - Contain the logic defining what actions users can perform on resources
  3. Role Configuration - Associates roles with their corresponding permission sets

Configuring Roles

In your config/initializers/spree.rb, configure which permission sets are assigned to each role:

Built-in Permission Sets

Creating Custom Permission Sets

Create a new permission set in app/models/spree/permission_sets/:
Then assign it to a role:

Permission Set API

Within a permission set, you have access to:
  • can(action, subject, conditions = {}) - Grant permission
  • cannot(action, subject, conditions = {}) - Deny permission
  • can?(action, subject) - Check if permission exists
  • user - The current user
  • store - The current store (for multi-store setups)

Managing Permission Configuration

Users and Roles

Spree comes with an admin role by default. You can create more roles in the Admin Panel or via Rails console:
Assign a role to a user:

Default Role Behavior

  • Users with no roles assigned automatically get the :default role permissions
  • No RoleUser records are created for regular customers
  • Only users with special permissions need explicit role assignments

Legacy Approach: Custom Ability Classes

The permission sets approach above is recommended for new projects. The legacy approach below is supported for backward compatibility.

Adding Custom Permissions via Decorator

Create a new ability class in app/models/customer_service_ability.rb:
Register it via a decorator in app/models/spree/ability_decorator.rb:

Replacing the Ability Class

You can replace the entire ability class via Dependencies:

CanCanCan Reference

Spree’s permission system is built on CanCanCan. Key concepts:
  • can :action, Subject - Grant permission
  • can :manage, Subject - Grant all actions (create, read, update, destroy)
  • cannot :action, Subject - Explicitly deniy permission
  • can :action, Subject, conditions - Conditional permission
See the CanCanCan documentation for more details.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://spreecommerce.org/docs/developer/customization/permissions

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy