cccux 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -0
- data/README.md +124 -112
- data/Rakefile +57 -4
- data/app/assets/stylesheets/cccux/application.css +96 -72
- data/app/controllers/cccux/ability_permissions_controller.rb +138 -33
- data/app/controllers/cccux/application_controller.rb +7 -0
- data/app/controllers/cccux/cccux_controller.rb +20 -10
- data/app/controllers/cccux/dashboard_controller.rb +203 -32
- data/app/controllers/cccux/role_abilities_controller.rb +70 -0
- data/app/controllers/cccux/roles_controller.rb +70 -81
- data/app/controllers/cccux/users_controller.rb +22 -7
- data/app/controllers/concerns/cccux/application_controller_concern.rb +6 -2
- data/app/helpers/cccux/authorization_helper.rb +29 -21
- data/app/models/cccux/ability.rb +83 -32
- data/app/models/cccux/ability_permission.rb +9 -0
- data/app/models/cccux/post.rb +5 -0
- data/app/models/cccux/role.rb +19 -1
- data/app/models/cccux/role_ability.rb +3 -0
- data/app/models/concerns/cccux/user_concern.rb +5 -2
- data/app/views/cccux/ability_permissions/new.html.erb +2 -2
- data/app/views/cccux/dashboard/model_discovery.html.erb +7 -2
- data/app/views/cccux/roles/_form.html.erb +24 -71
- data/app/views/cccux/roles/edit.html.erb +5 -5
- data/app/views/cccux/roles/index.html.erb +1 -8
- data/app/views/cccux/roles/new.html.erb +1 -3
- data/app/views/cccux/users/edit.html.erb +4 -4
- data/app/views/cccux/users/new.html.erb +30 -15
- data/app/views/layouts/cccux/admin.html.erb +1 -2
- data/app/views/shared/_footer.html.erb +1 -1
- data/config/routes.rb +7 -6
- data/lib/cccux/engine.rb +7 -6
- data/lib/cccux/version.rb +1 -1
- data/lib/cccux.rb +12 -0
- data/lib/tasks/cccux.rake +271 -159
- metadata +10 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: afb1191e0b22997a111737dfd7b40e7f3cfb8803cc5046b2091d711ff915dada
|
|
4
|
+
data.tar.gz: 372d9570edf0194fa3759922a6c1d18e60cd3d8ce2bf4c78fbc4ecdd0be15d61
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d235d116f1ad65bf811c70e486b29da1d40dc354e96252db8e0d6fd8a5cfa7e99d2c30e3093e5d161c0267e115c8031a6af827ec31cba6f2b64c8b4fa1ca855
|
|
7
|
+
data.tar.gz: ba3f46415d6a00afc76907be4523a290abfa43441d6f706e4d35d30ab96a8ca664e6df1a2149a48bfe1190d6b4faf5a47bf6c7c310fbe683b34b60060bdb26e1
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,71 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.1] - 2025-01-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Multi-level Ownership Support**: Enhanced ownership system to support ownership chains (e.g., ProjectManager → Project → Task)
|
|
12
|
+
- **Improved Model Discovery**: Enhanced model discovery to include all application models in role editing interface
|
|
13
|
+
- **Enhanced Authorization Logic**: Improved Ability class to handle complex ownership relationships correctly
|
|
14
|
+
- **Project Management Integration**: Added support for Project, Task, and ProjectManager models with proper authorization
|
|
15
|
+
- **Comprehensive Test Coverage**: Added extensive test coverage for all major components and edge cases
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- **Model Loading Issues**: Fixed Zeitwerk autoloading issues with empty model files
|
|
19
|
+
- **Ownership Chain Logic**: Fixed ownership checking logic to properly traverse ownership relationships
|
|
20
|
+
- **User Registration**: Fixed ActiveModel::UnknownAttributeError during user signup process
|
|
21
|
+
- **Permission Inheritance**: Corrected permission inheritance for project managers and task ownership
|
|
22
|
+
- **Debug Output Removal**: Cleaned up all debug output statements from production code
|
|
23
|
+
- **Test Assertion Warnings**: Fixed auto-generated test methods and missing HTTP requests in tests
|
|
24
|
+
|
|
25
|
+
### Technical Improvements
|
|
26
|
+
- **Enhanced Test Coverage**: Improved test coverage for complex ownership scenarios
|
|
27
|
+
- **Better Error Handling**: Enhanced error handling for missing models and invalid ownership configurations
|
|
28
|
+
- **Performance Optimizations**: Improved model loading and authorization checking performance
|
|
29
|
+
- **Code Quality**: Removed all debug statements and improved code organization
|
|
30
|
+
|
|
31
|
+
## [0.1.2] - 2025-01-27
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
- **Multi-level Ownership Support**: Enhanced ownership system to support ownership chains (e.g., ProjectManager → Project → Task)
|
|
35
|
+
- **Improved Model Discovery**: Enhanced model discovery to include all application models in role editing interface
|
|
36
|
+
- **Enhanced Authorization Logic**: Improved Ability class to handle complex ownership relationships correctly
|
|
37
|
+
- **Project Management Integration**: Added support for Project, Task, and ProjectManager models with proper authorization
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
- **Model Loading Issues**: Fixed Zeitwerk autoloading issues with empty model files
|
|
41
|
+
- **Ownership Chain Logic**: Fixed ownership checking logic to properly traverse ownership relationships
|
|
42
|
+
- **User Registration**: Fixed ActiveModel::UnknownAttributeError during user signup process
|
|
43
|
+
- **Permission Inheritance**: Corrected permission inheritance for project managers and task ownership
|
|
44
|
+
|
|
45
|
+
### Technical Improvements
|
|
46
|
+
- **Enhanced Test Coverage**: Improved test coverage for complex ownership scenarios
|
|
47
|
+
- **Better Error Handling**: Enhanced error handling for missing models and invalid ownership configurations
|
|
48
|
+
- **Performance Optimizations**: Improved model loading and authorization checking performance
|
|
49
|
+
|
|
50
|
+
## [0.1.1] - 2025-07-07
|
|
51
|
+
|
|
52
|
+
### Added
|
|
53
|
+
- **Comprehensive Test Suite**: Added extensive test coverage for all major components
|
|
54
|
+
- Model tests for User, Role, RoleAbility with validations and associations
|
|
55
|
+
- Ability class tests covering all authorization scenarios
|
|
56
|
+
- Controller tests for admin interface functionality
|
|
57
|
+
- View helper tests for authorization-aware UI components
|
|
58
|
+
- Integration tests for complete authorization workflows
|
|
59
|
+
- Rake task tests for setup and configuration automation
|
|
60
|
+
- **Test Fixtures**: Created comprehensive test data fixtures for users and roles
|
|
61
|
+
- **Test Documentation**: Detailed test scenarios covering edge cases and security
|
|
62
|
+
|
|
63
|
+
### Fixed
|
|
64
|
+
- **Rails Version Compatibility**: Fixed schema version compatibility with Rails 7.2
|
|
65
|
+
- **Dependency Constraints**: Removed incompatible RSpec dependency, using built-in Rails testing
|
|
66
|
+
|
|
67
|
+
### Technical Improvements
|
|
68
|
+
- **Security Testing**: Tests verify deny-by-default security model
|
|
69
|
+
- **Ownership Testing**: Comprehensive tests for both direct and contextual ownership
|
|
70
|
+
- **Multi-role Testing**: Tests verify cumulative permissions from multiple roles
|
|
71
|
+
- **Guest User Testing**: Ensures proper handling of unauthenticated users
|
|
72
|
+
|
|
8
73
|
## [0.1.0] - 2025-07-07
|
|
9
74
|
|
|
10
75
|
### Added
|
|
@@ -64,4 +129,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
64
129
|
- Backward compatibility maintained during transition period
|
|
65
130
|
- Clear upgrade path for existing installations
|
|
66
131
|
|
|
132
|
+
[0.1.1]: https://github.com/bagus1/cccux/releases/tag/v0.1.1
|
|
67
133
|
[0.1.0]: https://github.com/bagus1/cccux/releases/tag/v0.1.0
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@ CCCUX is a Rails engine that provides comprehensive role-based authorization wit
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
+
CCCUX eliminates the complexity of traditional authorization solutions by providing:
|
|
8
|
+
|
|
7
9
|
- **One-Line Controller Setup**: Just add `load_and_authorize_resource` to any controller
|
|
8
10
|
- **No Model Code Required**: Models need no special concerns or methods
|
|
9
11
|
- **UI-Driven Configuration**: Set up complex ownership patterns through the web interface
|
|
@@ -13,6 +15,21 @@ CCCUX is a Rails engine that provides comprehensive role-based authorization wit
|
|
|
13
15
|
- **Admin Interface**: Clean, intuitive interface for role and permission management
|
|
14
16
|
- **Rails 8 Compatible**: Works with Rails 8 and modern Rails applications
|
|
15
17
|
|
|
18
|
+
### Why CCCUX is Simple
|
|
19
|
+
|
|
20
|
+
Traditional authorization solutions require:
|
|
21
|
+
- Complex model concerns and methods
|
|
22
|
+
- Manual ability class configuration
|
|
23
|
+
- Custom ownership logic in every model
|
|
24
|
+
- Lots of boilerplate code
|
|
25
|
+
|
|
26
|
+
**CCCUX eliminates all of this:**
|
|
27
|
+
- ✅ One line per controller: `load_and_authorize_resource`
|
|
28
|
+
- ✅ No model code required
|
|
29
|
+
- ✅ UI-driven configuration
|
|
30
|
+
- ✅ Automatic setup and integration
|
|
31
|
+
- ✅ Works with standard Rails patterns
|
|
32
|
+
|
|
16
33
|
## Quick Start
|
|
17
34
|
|
|
18
35
|
### 1. Install the Engine
|
|
@@ -33,6 +50,10 @@ bundle install
|
|
|
33
50
|
rails cccux:setup
|
|
34
51
|
```
|
|
35
52
|
|
|
53
|
+
#### Setup Task Details
|
|
54
|
+
|
|
55
|
+
The `rails cccux:setup` task performs these steps:
|
|
56
|
+
|
|
36
57
|
**What the setup task does:**
|
|
37
58
|
|
|
38
59
|
1. **Checks for Devise**: Verifies Devise is installed, guides you through installation if needed
|
|
@@ -48,11 +69,20 @@ The setup task automatically configures your `ApplicationController` with:
|
|
|
48
69
|
- Error handling for authorization failures
|
|
49
70
|
- View helpers for authorization checks
|
|
50
71
|
|
|
51
|
-
|
|
72
|
+
The setup task is idempotent - you can run it multiple times safely.
|
|
73
|
+
|
|
74
|
+
### 3. Managing Permissions and Roles
|
|
75
|
+
|
|
76
|
+
Start your server, login as the Role Manager user you created and navigate to `http://localhost:3000/cccux`. You should see links in the footer on your homepage.
|
|
77
|
+
|
|
78
|
+
## Controller Configuration
|
|
79
|
+
|
|
80
|
+
Controllers need minimal configuration to work with CCCUX - just add `load_and_authorize_resource` to any controller.
|
|
81
|
+
|
|
82
|
+
### Basic Controller Setup
|
|
52
83
|
|
|
53
84
|
**The only requirement: Add `load_and_authorize_resource` to your controllers**
|
|
54
85
|
|
|
55
|
-
#### Basic Controller
|
|
56
86
|
```ruby
|
|
57
87
|
class ProductsController < ApplicationController
|
|
58
88
|
load_and_authorize_resource
|
|
@@ -67,7 +97,10 @@ class ProductsController < ApplicationController
|
|
|
67
97
|
end
|
|
68
98
|
```
|
|
69
99
|
|
|
70
|
-
|
|
100
|
+
### Nested Resource Setup
|
|
101
|
+
|
|
102
|
+
For controllers handling nested resources, use conditional loading:
|
|
103
|
+
|
|
71
104
|
```ruby
|
|
72
105
|
class OrdersController < ApplicationController
|
|
73
106
|
# Load parent resource when present
|
|
@@ -87,57 +120,14 @@ class OrdersController < ApplicationController
|
|
|
87
120
|
end
|
|
88
121
|
```
|
|
89
122
|
|
|
90
|
-
###
|
|
91
|
-
|
|
92
|
-
Start your server and navigate to `http://localhost:3000/cccux`:
|
|
93
|
-
|
|
94
|
-
1. **Model Discovery**: Click "Model Discovery" to automatically detect your models and create permissions
|
|
95
|
-
2. **Roles Management**: Go to "Roles" to see default roles and create custom ones
|
|
96
|
-
3. **Assign Permissions**: Configure which roles can perform which actions on your models
|
|
97
|
-
|
|
98
|
-
## Permission Configuration
|
|
99
|
-
|
|
100
|
-
CCCUX supports two access types:
|
|
101
|
-
|
|
102
|
-
### Global Access
|
|
103
|
-
- **What it does**: Access to all records everywhere
|
|
104
|
-
- **Use case**: Administrators, managers with broad access
|
|
105
|
-
- **Configuration**: Select "Global" access type
|
|
106
|
-
|
|
107
|
-
### Owned Access
|
|
108
|
-
- **What it does**: Access to records you own or have access to via relationships
|
|
109
|
-
- **Use case**: Users editing their own records, managers accessing records in their scope
|
|
110
|
-
- **Configuration**: Select "Owned" access type and configure ownership settings
|
|
111
|
-
|
|
112
|
-
## Ownership Configuration Examples
|
|
113
|
-
|
|
114
|
-
### Simple User Ownership
|
|
115
|
-
**Scenario**: Users can only edit products they created
|
|
116
|
-
|
|
117
|
-
- **Access Type**: Owned
|
|
118
|
-
- **Ownership Model**: (leave blank)
|
|
119
|
-
- **Foreign Key**: (leave blank - auto-detects `user_id`)
|
|
120
|
-
- **User Key**: (leave blank - defaults to `user_id`)
|
|
121
|
-
|
|
122
|
-
### Manager Ownership
|
|
123
|
-
**Scenario**: Store managers can edit all orders in stores they manage
|
|
124
|
-
|
|
125
|
-
- **Access Type**: Owned
|
|
126
|
-
- **Ownership Model**: `StoreManager`
|
|
127
|
-
- **Foreign Key**: `store_id`
|
|
128
|
-
- **User Key**: `user_id`
|
|
129
|
-
|
|
130
|
-
This configuration tells CCCUX: "Find all StoreManager records where user_id matches the current user, get their store_id values, and allow access to orders with those store_id values."
|
|
131
|
-
|
|
132
|
-
### Complex Hierarchies
|
|
133
|
-
**Scenario**: Regional managers can edit products in all stores in their region
|
|
123
|
+
### Checking Roles in Code
|
|
134
124
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
125
|
+
```ruby
|
|
126
|
+
current_user.has_role?('Role Manager') # => true/false
|
|
127
|
+
current_user.roles # => ['Basic User', 'Store Manager']
|
|
128
|
+
```
|
|
139
129
|
|
|
140
|
-
##
|
|
130
|
+
## Models
|
|
141
131
|
|
|
142
132
|
**Models need NO special code!** CCCUX works with standard Rails models:
|
|
143
133
|
|
|
@@ -160,10 +150,60 @@ class Store < ApplicationRecord
|
|
|
160
150
|
end
|
|
161
151
|
```
|
|
162
152
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
153
|
+
## Admin Interface
|
|
154
|
+
|
|
155
|
+
Navigate to `/cccux` to access the admin interface:
|
|
156
|
+
|
|
157
|
+
- **Dashboard**: Overview of roles, users, and permissions
|
|
158
|
+
- **Roles**: Create and manage roles with drag-and-drop priority ordering
|
|
159
|
+
- **Permissions**: View and create permissions for your models
|
|
160
|
+
- **Users**: Assign roles to users
|
|
161
|
+
- **Model Discovery**: Automatically detect new models and create permissions
|
|
162
|
+
|
|
163
|
+
## Managing Permissions and Roles
|
|
164
|
+
|
|
165
|
+
### Permission Configuration
|
|
166
|
+
|
|
167
|
+
1. **Model Discovery**: Click "Model Discovery" to automatically detect your models and create permissions
|
|
168
|
+
2. **CRUD Actions added by default**: The Model Discovery process will add permissions for Read, Create, Update and Delete.
|
|
169
|
+
3. **Additional Actions**: The Permissions page shows each model and all their permisssions. Click the "Create New xxx Permission" for a model and it will discover any additional actions that your controller and routes support. Add them and they'll be available for any role.
|
|
170
|
+
|
|
171
|
+
### Role Creation
|
|
172
|
+
|
|
173
|
+
Once you've created all the permissions from the Model Discovery page, you can assign them to Roles. By default, CCCUX creates three roles. Guest, Basic User and Role Manager. For additional Roles, click the Create Role button and fill out the simple form. Once it's created, edit it to configure its abilities.
|
|
174
|
+
|
|
175
|
+
Click to edit a role to configure it.
|
|
176
|
+
|
|
177
|
+
### Role Configuration
|
|
178
|
+
|
|
179
|
+
CCCUX supports two access types for each action for each model. Global and Owned.
|
|
180
|
+
|
|
181
|
+
#### Global Access
|
|
182
|
+
- **What it does**: Access to the to all records for a model for the individual action.
|
|
183
|
+
- **Use case**: Allowing Read access to the role for all items in a model.
|
|
184
|
+
- **Use case**: Allowing Create access to create an item in a model.
|
|
185
|
+
- **Configuration**: Select "Global" access type
|
|
186
|
+
|
|
187
|
+
#### Owned Access
|
|
188
|
+
|
|
189
|
+
There are two types of Owned Access. When you click 'owned' for a permission (Update) for a model (Product) for a role ("Basic User"), by default, any user with that role will be able only update records they created. However additional fields will be displayed for 'Owned' role permissions. These allow you to allow access to a manager (Project Manager) if you have an appropriate model (ProjectManager) and relationships set up in your application. This is best used for nested routes (see the setup for nested routes above) so that for instance a Project Manager can manage all the Tasks in a Project.
|
|
190
|
+
|
|
191
|
+
##### Basic Owned Access
|
|
192
|
+
|
|
193
|
+
- **By Default**: Access to records for the user that created them.
|
|
194
|
+
- **Use case**: Users editing their own records
|
|
195
|
+
|
|
196
|
+
##### Advanced Owned Access
|
|
197
|
+
|
|
198
|
+
- **First** select 'Owned' for a permission on a model for a role.
|
|
199
|
+
- **Next** Select an Ownership Model (ProjectManager), and enter a foreign key (project_id) and a User Key (user_id)
|
|
200
|
+
- **Result**: Now if managers (Project Managers) are assigned to the parent item (A Project), they can manage all the items (Tasks) within (their Project).
|
|
201
|
+
|
|
202
|
+
### Role Assignment
|
|
203
|
+
|
|
204
|
+
From the cccux dashboard, click users to see a list of users. Click to edit an individual user to add them to a role. Users can be assgined to multiple roles.
|
|
205
|
+
|
|
206
|
+
|
|
167
207
|
|
|
168
208
|
## View Helpers
|
|
169
209
|
|
|
@@ -202,7 +242,7 @@ You can also use standard CanCanCan patterns:
|
|
|
202
242
|
<% end %>
|
|
203
243
|
```
|
|
204
244
|
|
|
205
|
-
|
|
245
|
+
## Converting Existing Views
|
|
206
246
|
|
|
207
247
|
CCCUX includes a development tool to convert existing Rails views to use authorization helpers:
|
|
208
248
|
|
|
@@ -237,16 +277,6 @@ rails cccux:view_examples
|
|
|
237
277
|
|
|
238
278
|
This conversion tool saves significant time when adding CCCUX to existing applications.
|
|
239
279
|
|
|
240
|
-
## Admin Interface
|
|
241
|
-
|
|
242
|
-
Navigate to `/cccux` to access the admin interface:
|
|
243
|
-
|
|
244
|
-
- **Dashboard**: Overview of roles, users, and permissions
|
|
245
|
-
- **Roles**: Create and manage roles with drag-and-drop priority ordering
|
|
246
|
-
- **Permissions**: View and create permissions for your models
|
|
247
|
-
- **Users**: Assign roles to users
|
|
248
|
-
- **Model Discovery**: Automatically detect new models and create permissions
|
|
249
|
-
|
|
250
280
|
## Error Handling
|
|
251
281
|
|
|
252
282
|
CCCUX automatically handles authorization errors:
|
|
@@ -257,6 +287,8 @@ CCCUX automatically handles authorization errors:
|
|
|
257
287
|
|
|
258
288
|
## Testing
|
|
259
289
|
|
|
290
|
+
### Basic Authorization Testing
|
|
291
|
+
|
|
260
292
|
Test your authorization with standard Rails testing:
|
|
261
293
|
|
|
262
294
|
```ruby
|
|
@@ -280,6 +312,31 @@ class ProductsControllerTest < ActionDispatch::IntegrationTest
|
|
|
280
312
|
end
|
|
281
313
|
```
|
|
282
314
|
|
|
315
|
+
### Comprehensive Test Suite
|
|
316
|
+
|
|
317
|
+
CCCUX includes a comprehensive test suite covering:
|
|
318
|
+
|
|
319
|
+
- **Model Tests**: User, Role, RoleAbility, and Ability model functionality
|
|
320
|
+
- **Controller Tests**: User authorization and admin interface access
|
|
321
|
+
- **Helper Tests**: Authorization helper methods and view helpers
|
|
322
|
+
- **Integration Tests**: Complete authorization flow testing
|
|
323
|
+
- **Task Tests**: Setup task functionality and configuration
|
|
324
|
+
- **Fixture Tests**: Proper test data setup for users and roles
|
|
325
|
+
|
|
326
|
+
Run the tests with:
|
|
327
|
+
```bash
|
|
328
|
+
cd path/to/cccux
|
|
329
|
+
rails test
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
The test suite validates:
|
|
333
|
+
- Role assignment and permission checking
|
|
334
|
+
- Ownership-based access control
|
|
335
|
+
- Admin interface restrictions
|
|
336
|
+
- Database setup and seeding
|
|
337
|
+
- View helper functionality
|
|
338
|
+
- Error handling scenarios
|
|
339
|
+
|
|
283
340
|
## Advanced Usage
|
|
284
341
|
|
|
285
342
|
### Custom Ability Logic
|
|
@@ -301,51 +358,6 @@ class ProductsController < ApplicationController
|
|
|
301
358
|
end
|
|
302
359
|
```
|
|
303
360
|
|
|
304
|
-
### Multiple Role Assignment
|
|
305
|
-
|
|
306
|
-
Users can have multiple roles, and permissions are cumulative:
|
|
307
|
-
|
|
308
|
-
```ruby
|
|
309
|
-
user.add_role('Basic User')
|
|
310
|
-
user.add_role('Store Manager')
|
|
311
|
-
user.roles # => ['Basic User', 'Store Manager']
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### Checking Roles in Code
|
|
315
|
-
|
|
316
|
-
```ruby
|
|
317
|
-
current_user.has_role?('Role Manager') # => true/false
|
|
318
|
-
current_user.roles # => ['Basic User', 'Store Manager']
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
## Setup Task Details
|
|
322
|
-
|
|
323
|
-
The `rails cccux:setup` task performs these steps:
|
|
324
|
-
|
|
325
|
-
1. **Devise Check**: Ensures Devise is installed and configured
|
|
326
|
-
2. **Route Mounting**: Adds CCCUX routes to your application
|
|
327
|
-
3. **ApplicationController Configuration**: Automatically adds the CCCUX concern
|
|
328
|
-
4. **Database Setup**: Creates all necessary tables and indexes
|
|
329
|
-
5. **Default Data**: Seeds roles, permissions, and creates admin user
|
|
330
|
-
6. **Status Verification**: Confirms all components are properly configured
|
|
331
|
-
|
|
332
|
-
The setup task is idempotent - you can run it multiple times safely.
|
|
333
|
-
|
|
334
|
-
## Why CCCUX is Simple
|
|
335
|
-
|
|
336
|
-
Traditional authorization solutions require:
|
|
337
|
-
- Complex model concerns and methods
|
|
338
|
-
- Manual ability class configuration
|
|
339
|
-
- Custom ownership logic in every model
|
|
340
|
-
- Lots of boilerplate code
|
|
341
|
-
|
|
342
|
-
**CCCUX eliminates all of this:**
|
|
343
|
-
- ✅ One line per controller: `load_and_authorize_resource`
|
|
344
|
-
- ✅ No model code required
|
|
345
|
-
- ✅ UI-driven configuration
|
|
346
|
-
- ✅ Automatic setup and integration
|
|
347
|
-
- ✅ Works with standard Rails patterns
|
|
348
|
-
|
|
349
361
|
## Troubleshooting
|
|
350
362
|
|
|
351
363
|
### Common Issues
|
data/Rakefile
CHANGED
|
@@ -1,8 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
2
6
|
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Cccux'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Load the engine's tasks
|
|
3
18
|
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
|
4
|
-
load
|
|
19
|
+
load 'rails/tasks/engine.rake'
|
|
20
|
+
|
|
21
|
+
load 'rails/tasks/statistics.rake'
|
|
22
|
+
|
|
23
|
+
require 'bundler/gem_tasks'
|
|
24
|
+
|
|
25
|
+
# Custom test preparation task
|
|
26
|
+
namespace :test do
|
|
27
|
+
desc "Prepare test database"
|
|
28
|
+
task :prepare do
|
|
29
|
+
puts "🧪 Preparing test database..."
|
|
30
|
+
|
|
31
|
+
# Change to dummy app directory and setup database
|
|
32
|
+
Dir.chdir(File.expand_path("test/dummy", __dir__)) do
|
|
33
|
+
system("RAILS_ENV=test bundle exec rails db:environment:set RAILS_ENV=test")
|
|
34
|
+
system("RAILS_ENV=test bundle exec rails db:schema:load")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
puts "✅ Test database prepared"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Override the default test task to include preparation
|
|
42
|
+
task :test => 'test:prepare'
|
|
5
43
|
|
|
6
|
-
|
|
44
|
+
# Dummy environment task for engine compatibility
|
|
45
|
+
# This prevents "Don't know how to build task 'environment'" errors
|
|
46
|
+
# when engine Rake tasks depend on :environment but it's not defined
|
|
47
|
+
task :environment do
|
|
48
|
+
# No-op: Engine doesn't need full Rails environment loading
|
|
49
|
+
# Host applications will have their own real environment task
|
|
50
|
+
end
|
|
7
51
|
|
|
8
|
-
|
|
52
|
+
# Dummy db:migrate task for engine compatibility
|
|
53
|
+
# This prevents "Don't know how to build task 'db:migrate'" errors
|
|
54
|
+
# when engine Rake tasks depend on :db:migrate but it's not defined
|
|
55
|
+
namespace :db do
|
|
56
|
+
task :migrate do
|
|
57
|
+
# No-op: Engine doesn't need to run migrations in test context
|
|
58
|
+
# Host applications will have their own real db:migrate task
|
|
59
|
+
puts "Dummy db:migrate task called (no-op in engine context)"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -1,102 +1,126 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
-
*
|
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
-
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
-
* It is generally better to create a new file per style scope.
|
|
12
|
-
*
|
|
13
|
-
*= require_tree .
|
|
14
|
-
*= require_self
|
|
2
|
+
* CCCUX Engine Styles
|
|
3
|
+
*
|
|
4
|
+
* This file contains styles for the CCCUX engine components.
|
|
15
5
|
*/
|
|
16
6
|
|
|
17
|
-
/*
|
|
18
|
-
.cccux-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
font-size: 0.875rem;
|
|
23
|
-
border: none;
|
|
24
|
-
cursor: pointer;
|
|
25
|
-
display: inline-block;
|
|
26
|
-
text-align: center;
|
|
7
|
+
/* CCCUX Admin Styles */
|
|
8
|
+
.cccux-admin {
|
|
9
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
10
|
+
line-height: 1.6;
|
|
11
|
+
color: #333;
|
|
27
12
|
}
|
|
28
13
|
|
|
29
|
-
.cccux-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
.cccux-admin h1 {
|
|
15
|
+
color: #2c3e50;
|
|
16
|
+
margin-bottom: 1rem;
|
|
32
17
|
}
|
|
33
18
|
|
|
34
|
-
.cccux-btn
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
.cccux-admin .btn {
|
|
20
|
+
display: inline-block;
|
|
21
|
+
padding: 0.5rem 1rem;
|
|
22
|
+
border: 1px solid #ddd;
|
|
23
|
+
border-radius: 4px;
|
|
24
|
+
text-decoration: none;
|
|
25
|
+
color: #333;
|
|
26
|
+
background: #f8f9fa;
|
|
38
27
|
}
|
|
39
28
|
|
|
40
|
-
.cccux-btn-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
.cccux-admin .btn-primary {
|
|
30
|
+
background: #007bff;
|
|
31
|
+
color: white;
|
|
32
|
+
border-color: #007bff;
|
|
43
33
|
}
|
|
44
34
|
|
|
45
|
-
.cccux-btn-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
.cccux-admin .btn-danger {
|
|
36
|
+
background: #dc3545;
|
|
37
|
+
color: white;
|
|
38
|
+
border-color: #dc3545;
|
|
49
39
|
}
|
|
50
40
|
|
|
51
|
-
.cccux-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
.cccux-admin table {
|
|
42
|
+
width: 100%;
|
|
43
|
+
border-collapse: collapse;
|
|
44
|
+
margin-bottom: 1rem;
|
|
54
45
|
}
|
|
55
46
|
|
|
56
|
-
.cccux-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
.cccux-admin th,
|
|
48
|
+
.cccux-admin td {
|
|
49
|
+
padding: 0.75rem;
|
|
50
|
+
border-bottom: 1px solid #ddd;
|
|
51
|
+
text-align: left;
|
|
59
52
|
}
|
|
60
53
|
|
|
61
|
-
.cccux-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
padding: 0.75rem 1.5rem;
|
|
65
|
-
font-weight: bold;
|
|
66
|
-
border-radius: 6px;
|
|
54
|
+
.cccux-admin th {
|
|
55
|
+
background: #f8f9fa;
|
|
56
|
+
font-weight: 600;
|
|
67
57
|
}
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
/* CCCUX Footer Styles */
|
|
60
|
+
.cccux-footer {
|
|
61
|
+
font-size: 0.9rem;
|
|
62
|
+
color: #6c757d;
|
|
63
|
+
margin-top: 1rem;
|
|
64
|
+
padding: .5rem 0;
|
|
65
|
+
border-top: 1px solid #e5e5e5;
|
|
66
|
+
background-color: #f8f9fa;
|
|
73
67
|
}
|
|
74
68
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
.cccux-footer .footer-link {
|
|
70
|
+
color: #red;
|
|
71
|
+
text-decoration: none;
|
|
72
|
+
margin: 0 0.5rem;
|
|
73
|
+
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
.cccux-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
justify-content: center;
|
|
76
|
+
.cccux-footer .footer-link:hover {
|
|
77
|
+
color: #0056b3;
|
|
78
|
+
text-decoration: underline;
|
|
85
79
|
}
|
|
86
80
|
|
|
87
|
-
.cccux-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
.cccux-footer .footer-separator {
|
|
82
|
+
color: #dee2e6;
|
|
83
|
+
margin: 0 0.25rem;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.cccux-footer .user-info,
|
|
87
|
+
.cccux-footer .auth-links {
|
|
88
|
+
font-size: 0.85rem;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.cccux-footer .container {
|
|
92
|
+
max-width: 1200px;
|
|
93
|
+
margin: 0 auto;
|
|
94
|
+
padding: 0 1rem;
|
|
91
95
|
}
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
.cccux-footer .row {
|
|
98
|
+
display: flex;
|
|
99
|
+
justify-content: space-between;
|
|
100
|
+
align-items: center;
|
|
101
|
+
flex-wrap: wrap;
|
|
97
102
|
}
|
|
98
103
|
|
|
99
|
-
.cccux-
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
.cccux-footer .col-md-6 {
|
|
105
|
+
flex: 1;
|
|
106
|
+
min-width: 300px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.cccux-footer .text-end {
|
|
110
|
+
text-align: right;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@media (max-width: 768px) {
|
|
114
|
+
.cccux-footer .row {
|
|
115
|
+
flex-direction: column;
|
|
116
|
+
gap: 0.5rem;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.cccux-footer .col-md-6 {
|
|
120
|
+
text-align: center;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.cccux-footer .text-end {
|
|
124
|
+
text-align: center;
|
|
125
|
+
}
|
|
102
126
|
}
|