simple_authorize 0.1.0 → 1.0.1
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/.overcommit.yml +55 -0
- data/.simplecov +15 -0
- data/CHANGELOG.md +113 -25
- data/CODE_OF_CONDUCT.md +129 -0
- data/CONTRIBUTING.md +182 -0
- data/LICENSE.txt +1 -1
- data/README.md +210 -15
- data/SECURITY.md +77 -0
- data/lib/generators/simple_authorize/install/install_generator.rb +1 -0
- data/lib/generators/simple_authorize/install/templates/simple_authorize.rb +8 -0
- data/lib/generators/simple_authorize/policy/policy_generator.rb +55 -0
- data/lib/generators/simple_authorize/policy/templates/policy.rb.tt +39 -0
- data/lib/generators/simple_authorize/policy/templates/policy_spec.rb.tt +73 -0
- data/lib/generators/simple_authorize/policy/templates/policy_test.rb.tt +65 -0
- data/lib/simple_authorize/configuration.rb +21 -0
- data/lib/simple_authorize/controller.rb +336 -38
- data/lib/simple_authorize/policy.rb +22 -0
- data/lib/simple_authorize/railtie.rb +20 -0
- data/lib/simple_authorize/rspec.rb +149 -0
- data/lib/simple_authorize/test_helpers.rb +115 -0
- data/lib/simple_authorize/version.rb +1 -1
- data/lib/simple_authorize.rb +6 -17
- data/spec/examples.txt +51 -0
- data/spec/rspec_matchers_spec.rb +235 -0
- data/spec/spec_helper.rb +116 -0
- metadata +53 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0016cdf20b078e1d8e9d67b037742260a3e07d8d73a8056aea027c182ed422dc
|
|
4
|
+
data.tar.gz: 4653aae4a3e588e3ebb94e6afb16518793a2e5b5c167b117f5c8bf6517e2ee7f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fdc1204e73d66f005d3f19893244712013300f12529b59a28e709f21552134e52e8efbb944197403be7832521cf983c15a7c1b8c46c3b2d3808dbbdc5511f2a
|
|
7
|
+
data.tar.gz: 5da4732fc1838f7a495336b4380f3bb90a523a5922fe6130e3e6b6c50cd0d2fd3d37f17f083de74ea8128871aac18f2d3a9ca7ef1e5196b225371c82e6ddd4cd
|
data/.overcommit.yml
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Overcommit configuration
|
|
2
|
+
# See https://github.com/sds/overcommit for full documentation
|
|
3
|
+
|
|
4
|
+
# Verify signatures for overcommit config to prevent tampering
|
|
5
|
+
verify_signatures: true
|
|
6
|
+
|
|
7
|
+
# Run these hooks before commits
|
|
8
|
+
PreCommit:
|
|
9
|
+
RuboCop:
|
|
10
|
+
enabled: true
|
|
11
|
+
description: 'Checking code style with RuboCop'
|
|
12
|
+
required: true
|
|
13
|
+
quiet: false
|
|
14
|
+
command: ['bundle', 'exec', 'rubocop']
|
|
15
|
+
|
|
16
|
+
TrailingWhitespace:
|
|
17
|
+
enabled: true
|
|
18
|
+
description: 'Checking for trailing whitespace'
|
|
19
|
+
|
|
20
|
+
YamlSyntax:
|
|
21
|
+
enabled: true
|
|
22
|
+
description: 'Checking YAML syntax'
|
|
23
|
+
|
|
24
|
+
# Run these hooks before pushes (more extensive checks)
|
|
25
|
+
PrePush:
|
|
26
|
+
RuboCop:
|
|
27
|
+
enabled: true
|
|
28
|
+
description: 'Running RuboCop before push'
|
|
29
|
+
required: true
|
|
30
|
+
|
|
31
|
+
Minitest:
|
|
32
|
+
enabled: true
|
|
33
|
+
description: 'Running Minitest suite'
|
|
34
|
+
required: true
|
|
35
|
+
|
|
36
|
+
RSpec:
|
|
37
|
+
enabled: true
|
|
38
|
+
description: 'Running RSpec suite'
|
|
39
|
+
required: true
|
|
40
|
+
|
|
41
|
+
# TruffleHog - scan for secrets
|
|
42
|
+
# Note: Requires truffleHog to be installed
|
|
43
|
+
# Install: brew install truffleHog (macOS) or pip install truffleHog
|
|
44
|
+
CustomScript:
|
|
45
|
+
enabled: true
|
|
46
|
+
description: 'Scanning for secrets with TruffleHog'
|
|
47
|
+
required: false # Optional since it requires external installation
|
|
48
|
+
command: ['sh', '-c', 'if command -v trufflehog >/dev/null 2>&1; then trufflehog filesystem . --only-verified --fail; else echo "TruffleHog not installed - skipping secret scan"; fi']
|
|
49
|
+
|
|
50
|
+
# Run these hooks after checkout
|
|
51
|
+
PostCheckout:
|
|
52
|
+
BundleInstall:
|
|
53
|
+
enabled: true
|
|
54
|
+
description: 'Running bundle install after checkout'
|
|
55
|
+
required: false
|
data/.simplecov
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
SimpleCov.start do
|
|
4
|
+
add_filter "/test/"
|
|
5
|
+
add_filter "/spec/"
|
|
6
|
+
add_filter "/lib/generators/"
|
|
7
|
+
add_filter "/lib/simple_authorize/railtie.rb"
|
|
8
|
+
|
|
9
|
+
# Merge results from multiple test runs
|
|
10
|
+
use_merging true
|
|
11
|
+
merge_timeout 3600 # 1 hour
|
|
12
|
+
|
|
13
|
+
# Don't enforce minimum yet
|
|
14
|
+
# minimum_coverage line: 95, branch: 90
|
|
15
|
+
end
|
data/CHANGELOG.md
CHANGED
|
@@ -5,34 +5,122 @@ 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
|
-
## [
|
|
8
|
+
## [1.0.0] - 2025-11-03
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
|
|
12
|
+
#### Core Authorization
|
|
13
|
+
- **Policy Generator** - Rails generator for creating policy classes (`rails g simple_authorize:policy ModelName`)
|
|
14
|
+
- **Install Generator** - Setup wizard creating initializer and base policy (`rails g simple_authorize:install`)
|
|
15
|
+
- **Headless Policies** - Authorization for actions without a specific record
|
|
16
|
+
- **Batch Authorization** - Efficiently authorize multiple records with `authorize_all`, `authorized_records`, and `partition_records`
|
|
17
|
+
|
|
18
|
+
#### Performance & Caching
|
|
19
|
+
- **Policy Caching** - Request-level memoization to reduce database queries and improve performance
|
|
20
|
+
- **Configurable Cache** - Enable/disable policy caching via `config.enable_policy_cache`
|
|
21
|
+
|
|
22
|
+
#### Instrumentation & Monitoring
|
|
23
|
+
- **ActiveSupport::Notifications** - Comprehensive instrumentation for authorization events
|
|
24
|
+
- **Audit Logging** - Track authorization attempts, denials, and policy scope usage
|
|
25
|
+
- **Custom Event Subscribers** - Hook into `authorize.simple_authorize` and `policy_scope.simple_authorize` events
|
|
26
|
+
|
|
27
|
+
#### API Support
|
|
28
|
+
- **JSON/XML Error Responses** - Automatic API-friendly error responses with proper HTTP status codes
|
|
29
|
+
- **API Request Detection** - Intelligent detection of API requests (JSON/XML format and headers)
|
|
30
|
+
- **Configurable Error Details** - Control error detail level with `config.api_error_details`
|
|
31
|
+
- **Status Code Handling** - 401 Unauthorized vs 403 Forbidden based on authentication state
|
|
32
|
+
|
|
33
|
+
#### Attribute-Level Authorization
|
|
34
|
+
- **Visible Attributes** - Control which attributes users can view (`visible_attributes`, `visible_attributes_for_action`)
|
|
35
|
+
- **Editable Attributes** - Control which attributes users can modify (`editable_attributes`, `editable_attributes_for_action`)
|
|
36
|
+
- **Filter Helpers** - Automatically filter attribute hashes based on policy rules
|
|
37
|
+
- **Strong Parameters Integration** - `policy_params` method for seamless Rails strong parameters integration
|
|
38
|
+
|
|
39
|
+
#### Testing Support
|
|
40
|
+
- **RSpec Matchers** - `permit_action`, `forbid_action`, `permit_mass_assignment`, `forbid_mass_assignment`
|
|
41
|
+
- **RSpec Helpers** - `permit_editing`, `forbid_editing`, `permit_viewing`, `forbid_viewing`
|
|
42
|
+
- **Minitest Helpers** - `assert_permit_action`, `assert_forbid_action` for Minitest users
|
|
43
|
+
- **Policy Testing** - Comprehensive test helpers for both testing frameworks
|
|
44
|
+
|
|
45
|
+
#### Internationalization
|
|
46
|
+
- **I18n Support** - Configurable error messages with internationalization support
|
|
47
|
+
- **Custom Translations** - Per-policy and per-action error message translations
|
|
48
|
+
- **Configurable Scope** - Customize I18n scope with `config.i18n_scope`
|
|
49
|
+
- **Fallback Messages** - Graceful fallback to default messages when translations are missing
|
|
50
|
+
|
|
51
|
+
#### Security & Best Practices
|
|
52
|
+
- **Authorization Verification** - `verify_authorized` and `verify_policy_scoped` to catch missing authorization
|
|
53
|
+
- **Skip Authorization** - Explicit `skip_authorization` and `skip_policy_scope` methods
|
|
54
|
+
- **Auto-Verify Module** - Optional automatic verification with `include SimpleAuthorize::Controller::AutoVerify`
|
|
55
|
+
- **Safe Redirects** - Security-conscious redirect handling preventing open redirect vulnerabilities
|
|
56
|
+
|
|
57
|
+
#### Developer Experience
|
|
58
|
+
- **Comprehensive Documentation** - Extensive README with examples and best practices
|
|
59
|
+
- **Error Messages** - Clear, actionable error messages for common mistakes
|
|
60
|
+
- **Helper Methods** - View helpers automatically included (`policy`, `policy_scope`, `authorized_user`)
|
|
61
|
+
- **Role Helpers** - Convenient `admin_user?`, `contributor_user?`, `viewer_user?` methods
|
|
62
|
+
|
|
63
|
+
### Changed
|
|
64
|
+
- Improved error handling with detailed exception information
|
|
65
|
+
- Enhanced policy class resolution with namespace support
|
|
66
|
+
- Better cache key generation for policy instances
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
- Policy scope resolution for collection classes
|
|
70
|
+
- Safe referrer path handling for redirects
|
|
71
|
+
- API request detection edge cases
|
|
72
|
+
|
|
73
|
+
### Security
|
|
74
|
+
- Added protection against open redirect vulnerabilities in `safe_referrer_path`
|
|
75
|
+
- Implemented proper HTTP status codes (401 vs 403) for API errors
|
|
76
|
+
- Enhanced authorization verification to prevent bypass attempts
|
|
77
|
+
|
|
78
|
+
## [0.1.0] - Initial Development
|
|
29
79
|
|
|
30
80
|
### Added
|
|
31
|
-
-
|
|
32
|
-
- Core authorization
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
81
|
+
- Basic policy-based authorization
|
|
82
|
+
- Core authorization methods (`authorize`, `policy`, `policy_scope`)
|
|
83
|
+
- Integration with Rails controllers
|
|
84
|
+
- Basic test helpers
|
|
85
|
+
- Initial documentation
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Upgrading
|
|
90
|
+
|
|
91
|
+
### From 0.1.0 to 1.0.0
|
|
92
|
+
|
|
93
|
+
**Breaking Changes:**
|
|
94
|
+
None - v1.0.0 is fully backward compatible with 0.1.0.
|
|
95
|
+
|
|
96
|
+
**New Features:**
|
|
97
|
+
All features listed above are opt-in and won't affect existing implementations.
|
|
98
|
+
|
|
99
|
+
**Recommended Updates:**
|
|
100
|
+
1. Run `rails g simple_authorize:install` to generate the configuration file
|
|
101
|
+
2. Enable policy caching for better performance: `config.enable_policy_cache = true`
|
|
102
|
+
3. Enable instrumentation for monitoring: `config.enable_instrumentation = true`
|
|
103
|
+
4. Add RSpec matchers to your spec_helper: `require 'simple_authorize/rspec'`
|
|
104
|
+
|
|
105
|
+
**Configuration:**
|
|
106
|
+
```ruby
|
|
107
|
+
# config/initializers/simple_authorize.rb
|
|
108
|
+
SimpleAuthorize.configure do |config|
|
|
109
|
+
config.enable_policy_cache = true # Enable request-level policy caching
|
|
110
|
+
config.enable_instrumentation = true # Enable ActiveSupport::Notifications
|
|
111
|
+
config.api_error_details = false # Exclude sensitive details in API errors
|
|
112
|
+
config.i18n_enabled = true # Enable I18n support
|
|
113
|
+
config.i18n_scope = "simple_authorize" # I18n translation scope
|
|
114
|
+
config.default_error_message = "You are not authorized to perform this action."
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Support
|
|
119
|
+
|
|
120
|
+
- **Documentation**: [README.md](README.md)
|
|
121
|
+
- **Issues**: [GitHub Issues](https://github.com/scottlaplant/simple_authorize/issues)
|
|
122
|
+
- **Security**: [SECURITY.md](SECURITY.md)
|
|
123
|
+
- **Contributing**: [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
36
124
|
|
|
37
|
-
[
|
|
125
|
+
[1.0.0]: https://github.com/scottlaplant/simple_authorize/releases/tag/v1.0.0
|
|
38
126
|
[0.1.0]: https://github.com/scottlaplant/simple_authorize/releases/tag/v0.1.0
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
**simpleauthorize@gmail.com**.
|
|
64
|
+
|
|
65
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
66
|
+
|
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
68
|
+
reporter of any incident.
|
|
69
|
+
|
|
70
|
+
## Enforcement Guidelines
|
|
71
|
+
|
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
74
|
+
|
|
75
|
+
### 1. Correction
|
|
76
|
+
|
|
77
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
78
|
+
unprofessional or unwelcome in the community.
|
|
79
|
+
|
|
80
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
|
83
|
+
|
|
84
|
+
### 2. Warning
|
|
85
|
+
|
|
86
|
+
**Community Impact**: A violation through a single incident or series
|
|
87
|
+
of actions.
|
|
88
|
+
|
|
89
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
93
|
+
like social media. Violating these terms may lead to a temporary or
|
|
94
|
+
permanent ban.
|
|
95
|
+
|
|
96
|
+
### 3. Temporary Ban
|
|
97
|
+
|
|
98
|
+
**Community Impact**: A serious violation of community standards, including
|
|
99
|
+
sustained inappropriate behavior.
|
|
100
|
+
|
|
101
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
102
|
+
communication with the community for a specified period of time. No public or
|
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
105
|
+
Violating these terms may lead to a permanent ban.
|
|
106
|
+
|
|
107
|
+
### 4. Permanent Ban
|
|
108
|
+
|
|
109
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
112
|
+
|
|
113
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
114
|
+
the community.
|
|
115
|
+
|
|
116
|
+
## Attribution
|
|
117
|
+
|
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
119
|
+
version 2.0, available at
|
|
120
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
121
|
+
|
|
122
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
123
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
124
|
+
|
|
125
|
+
[homepage]: https://www.contributor-covenant.org
|
|
126
|
+
|
|
127
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
128
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
129
|
+
https://www.contributor-covenant.org/translations.
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Contributing to SimpleAuthorize
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to SimpleAuthorize! We welcome contributions from everyone.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
This project and everyone participating in it is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to simpleauthorize@gmail.com.
|
|
8
|
+
|
|
9
|
+
## How Can I Contribute?
|
|
10
|
+
|
|
11
|
+
### Reporting Bugs
|
|
12
|
+
|
|
13
|
+
Before creating bug reports, please check the existing issues to avoid duplicates. When creating a bug report, include as many details as possible:
|
|
14
|
+
|
|
15
|
+
* **Use a clear and descriptive title**
|
|
16
|
+
* **Describe the exact steps to reproduce the problem**
|
|
17
|
+
* **Provide specific examples** to demonstrate the steps
|
|
18
|
+
* **Describe the behavior you observed** and what you expected
|
|
19
|
+
* **Include Ruby version, Rails version, and gem version**
|
|
20
|
+
* **Include any error messages or stack traces**
|
|
21
|
+
|
|
22
|
+
### Suggesting Enhancements
|
|
23
|
+
|
|
24
|
+
Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion:
|
|
25
|
+
|
|
26
|
+
* **Use a clear and descriptive title**
|
|
27
|
+
* **Provide a step-by-step description** of the suggested enhancement
|
|
28
|
+
* **Explain why this enhancement would be useful**
|
|
29
|
+
* **List any alternative solutions** you've considered
|
|
30
|
+
|
|
31
|
+
### Pull Requests
|
|
32
|
+
|
|
33
|
+
* Fill in the pull request template
|
|
34
|
+
* Follow the Ruby style guide (RuboCop will check this)
|
|
35
|
+
* Include tests for new features or bug fixes
|
|
36
|
+
* Update documentation as needed
|
|
37
|
+
* Ensure all tests pass (`bundle exec rake test` and `bundle exec rspec`)
|
|
38
|
+
* Ensure RuboCop passes (`bundle exec rubocop`)
|
|
39
|
+
|
|
40
|
+
## Development Setup
|
|
41
|
+
|
|
42
|
+
1. **Fork and clone the repository**
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/YOUR_USERNAME/simple_authorize.git
|
|
45
|
+
cd simple_authorize
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. **Install dependencies**
|
|
49
|
+
```bash
|
|
50
|
+
bundle install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. **Set up git hooks with Overcommit**
|
|
54
|
+
```bash
|
|
55
|
+
# Install git hooks
|
|
56
|
+
bundle exec overcommit --install
|
|
57
|
+
|
|
58
|
+
# (Optional) Install TruffleHog for secret scanning
|
|
59
|
+
# macOS: brew install truffleHog
|
|
60
|
+
# Linux: pip install truffleHog
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This sets up automatic checks before commits and pushes:
|
|
64
|
+
* **Pre-commit**: RuboCop, trailing whitespace, YAML syntax
|
|
65
|
+
* **Pre-push**: RuboCop, Minitest, RSpec, TruffleHog (if installed)
|
|
66
|
+
* **Post-checkout**: Automatic bundle install
|
|
67
|
+
|
|
68
|
+
To skip hooks temporarily (not recommended):
|
|
69
|
+
```bash
|
|
70
|
+
git push --no-verify
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
4. **Run tests**
|
|
74
|
+
```bash
|
|
75
|
+
# Run Minitest suite
|
|
76
|
+
bundle exec rake test
|
|
77
|
+
|
|
78
|
+
# Run RSpec suite
|
|
79
|
+
bundle exec rspec
|
|
80
|
+
|
|
81
|
+
# Run RuboCop
|
|
82
|
+
bundle exec rubocop
|
|
83
|
+
|
|
84
|
+
# Run all checks
|
|
85
|
+
bundle exec rake
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
5. **Create a feature branch**
|
|
89
|
+
```bash
|
|
90
|
+
git checkout -b my-new-feature
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Testing
|
|
94
|
+
|
|
95
|
+
We maintain high test coverage (89%+) and use both Minitest and RSpec:
|
|
96
|
+
|
|
97
|
+
* **Minitest**: `test/` directory - for integration and controller tests
|
|
98
|
+
* **RSpec**: `spec/` directory - for unit tests and matchers
|
|
99
|
+
|
|
100
|
+
Please ensure your changes include appropriate tests:
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
# Minitest example
|
|
104
|
+
test "authorize succeeds when policy allows" do
|
|
105
|
+
result = controller.authorize(post, :show?)
|
|
106
|
+
assert_equal post, result
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# RSpec example
|
|
110
|
+
it "permits action when policy allows" do
|
|
111
|
+
expect { policy.show? }.to permit_action
|
|
112
|
+
end
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Code Style
|
|
116
|
+
|
|
117
|
+
We follow the Ruby Style Guide and enforce it with RuboCop:
|
|
118
|
+
|
|
119
|
+
* Use 2 spaces for indentation
|
|
120
|
+
* Use double quotes for strings
|
|
121
|
+
* Keep lines under 120 characters
|
|
122
|
+
* Write descriptive method and variable names
|
|
123
|
+
* Add comments for complex logic
|
|
124
|
+
|
|
125
|
+
Run RuboCop with:
|
|
126
|
+
```bash
|
|
127
|
+
bundle exec rubocop
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Auto-fix issues with:
|
|
131
|
+
```bash
|
|
132
|
+
bundle exec rubocop -a
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Documentation
|
|
136
|
+
|
|
137
|
+
* Update README.md if you add features
|
|
138
|
+
* Add YARD documentation to public methods
|
|
139
|
+
* Update CHANGELOG.md with your changes
|
|
140
|
+
* Keep comments up-to-date with code changes
|
|
141
|
+
|
|
142
|
+
## Commit Messages
|
|
143
|
+
|
|
144
|
+
* Use present tense ("Add feature" not "Added feature")
|
|
145
|
+
* Use imperative mood ("Move cursor to..." not "Moves cursor to...")
|
|
146
|
+
* Limit first line to 72 characters
|
|
147
|
+
* Reference issues and pull requests after the first line
|
|
148
|
+
|
|
149
|
+
Example:
|
|
150
|
+
```
|
|
151
|
+
Add policy caching for improved performance
|
|
152
|
+
|
|
153
|
+
Implements request-level memoization for policy instances
|
|
154
|
+
to reduce database queries and improve response times.
|
|
155
|
+
|
|
156
|
+
Fixes #123
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Release Process
|
|
160
|
+
|
|
161
|
+
Maintainers will handle releases:
|
|
162
|
+
|
|
163
|
+
1. Update version in `lib/simple_authorize/version.rb`
|
|
164
|
+
2. Update CHANGELOG.md with release notes
|
|
165
|
+
3. Commit changes
|
|
166
|
+
4. Run `bundle exec rake release`
|
|
167
|
+
|
|
168
|
+
## Questions?
|
|
169
|
+
|
|
170
|
+
Feel free to:
|
|
171
|
+
* Open an issue for questions
|
|
172
|
+
* Email us at simpleauthorize@gmail.com
|
|
173
|
+
* Check existing documentation in the README
|
|
174
|
+
|
|
175
|
+
## Recognition
|
|
176
|
+
|
|
177
|
+
Contributors will be:
|
|
178
|
+
* Listed in the CHANGELOG for their contributions
|
|
179
|
+
* Credited in release notes
|
|
180
|
+
* Added to a CONTRIBUTORS file (if created)
|
|
181
|
+
|
|
182
|
+
Thank you for contributing to SimpleAuthorize! 🎉
|
data/LICENSE.txt
CHANGED