organizations 0.1.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 +7 -0
- data/.rubocop.yml +137 -0
- data/.simplecov +35 -0
- data/AGENTS.md +5 -0
- data/Appraisals +9 -0
- data/CHANGELOG.md +14 -0
- data/CLAUDE.md +5 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +1496 -0
- data/Rakefile +15 -0
- data/app/controllers/organizations/application_controller.rb +251 -0
- data/app/controllers/organizations/invitations_controller.rb +262 -0
- data/app/controllers/organizations/memberships_controller.rb +179 -0
- data/app/controllers/organizations/organizations_controller.rb +179 -0
- data/app/controllers/organizations/switch_controller.rb +38 -0
- data/app/mailers/organizations/invitation_mailer.rb +85 -0
- data/app/views/organizations/invitation_mailer/invitation_email.html.erb +98 -0
- data/app/views/organizations/invitation_mailer/invitation_email.text.erb +18 -0
- data/config/routes.rb +35 -0
- data/examples/demo_insert_race_condition.rb +212 -0
- data/examples/demo_slugifiable_integration.rb +350 -0
- data/lib/generators/organizations/install/install_generator.rb +42 -0
- data/lib/generators/organizations/install/templates/create_organizations_tables.rb.erb +128 -0
- data/lib/generators/organizations/install/templates/initializer.rb +83 -0
- data/lib/organizations/acts_as_tenant_integration.rb +54 -0
- data/lib/organizations/callback_context.rb +51 -0
- data/lib/organizations/callbacks.rb +120 -0
- data/lib/organizations/configuration.rb +286 -0
- data/lib/organizations/controller_helpers.rb +292 -0
- data/lib/organizations/engine.rb +65 -0
- data/lib/organizations/models/concerns/has_organizations.rb +509 -0
- data/lib/organizations/models/invitation.rb +295 -0
- data/lib/organizations/models/membership.rb +260 -0
- data/lib/organizations/models/organization.rb +451 -0
- data/lib/organizations/roles.rb +256 -0
- data/lib/organizations/test_helpers.rb +167 -0
- data/lib/organizations/version.rb +5 -0
- data/lib/organizations/view_helpers.rb +353 -0
- data/lib/organizations.rb +107 -0
- metadata +163 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e1c3b465c2092c9234aed9d1751337abae3bfef4a86bf1bd2fd34bafb5bee7fb
|
|
4
|
+
data.tar.gz: cc0b5a830649d91a464ba72f5603bec472c45d11818974c6d1567db4a65422ef
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 181defb79c40e269ea86b28d3f6d6d262d3834eaf31674ab66b33a807e685bec9ef085b3251490a26b0c02c870b680b803f020341c7555cebee261fd1984a0e9
|
|
7
|
+
data.tar.gz: 34e5d034196756c2bf436341766a1889b9c665e7a42c70a7a7ad5ba52863da56a0a845d4842b171cd4fbf6354a8be44cbfef476716f6e8c78c665e6e403ed563
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require:
|
|
4
|
+
- rubocop-minitest
|
|
5
|
+
- rubocop-performance
|
|
6
|
+
|
|
7
|
+
AllCops:
|
|
8
|
+
TargetRubyVersion: 3.2
|
|
9
|
+
NewCops: enable
|
|
10
|
+
Exclude:
|
|
11
|
+
- 'bin/**/*'
|
|
12
|
+
- 'vendor/**/*'
|
|
13
|
+
- 'test/dummy/**/*'
|
|
14
|
+
- 'db/migrate/**/*' # Generated migrations
|
|
15
|
+
- 'lib/generators/**/templates/**/*' # Generator templates
|
|
16
|
+
|
|
17
|
+
# Layout & Formatting
|
|
18
|
+
Layout/LineLength:
|
|
19
|
+
Max: 120
|
|
20
|
+
AllowedPatterns:
|
|
21
|
+
- '\s*#.*' # Allow long comments
|
|
22
|
+
- '^\s*raise\s' # Allow long raise statements
|
|
23
|
+
|
|
24
|
+
Layout/MultilineMethodCallIndentation:
|
|
25
|
+
EnforcedStyle: indented
|
|
26
|
+
|
|
27
|
+
Layout/ArgumentAlignment:
|
|
28
|
+
EnforcedStyle: with_first_argument
|
|
29
|
+
|
|
30
|
+
Layout/FirstArgumentIndentation:
|
|
31
|
+
EnforcedStyle: consistent
|
|
32
|
+
|
|
33
|
+
# Style
|
|
34
|
+
Style/Documentation:
|
|
35
|
+
Enabled: false # Don't require class documentation for now
|
|
36
|
+
|
|
37
|
+
Style/StringLiterals:
|
|
38
|
+
EnforcedStyle: double_quotes
|
|
39
|
+
|
|
40
|
+
Style/FrozenStringLiteralComment:
|
|
41
|
+
Enabled: true
|
|
42
|
+
EnforcedStyle: always
|
|
43
|
+
|
|
44
|
+
Style/ClassAndModuleChildren:
|
|
45
|
+
EnforcedStyle: compact
|
|
46
|
+
|
|
47
|
+
Style/GuardClause:
|
|
48
|
+
MinBodyLength: 3
|
|
49
|
+
|
|
50
|
+
# Metrics
|
|
51
|
+
Metrics/ClassLength:
|
|
52
|
+
Max: 150
|
|
53
|
+
|
|
54
|
+
Metrics/ModuleLength:
|
|
55
|
+
Max: 150
|
|
56
|
+
|
|
57
|
+
Metrics/MethodLength:
|
|
58
|
+
Max: 25
|
|
59
|
+
AllowedMethods:
|
|
60
|
+
- 'configure' # Configuration blocks can be longer
|
|
61
|
+
|
|
62
|
+
Metrics/BlockLength:
|
|
63
|
+
Max: 25
|
|
64
|
+
AllowedMethods:
|
|
65
|
+
- 'configure'
|
|
66
|
+
- 'describe'
|
|
67
|
+
- 'context'
|
|
68
|
+
- 'it'
|
|
69
|
+
- 'test'
|
|
70
|
+
Exclude:
|
|
71
|
+
- 'test/**/*' # Allow long test blocks
|
|
72
|
+
|
|
73
|
+
Metrics/AbcSize:
|
|
74
|
+
Max: 20
|
|
75
|
+
AllowedMethods:
|
|
76
|
+
- 'configure'
|
|
77
|
+
|
|
78
|
+
Metrics/CyclomaticComplexity:
|
|
79
|
+
Max: 8
|
|
80
|
+
|
|
81
|
+
Metrics/PerceivedComplexity:
|
|
82
|
+
Max: 10
|
|
83
|
+
|
|
84
|
+
# Naming
|
|
85
|
+
Naming/PredicateName:
|
|
86
|
+
ForbiddenPrefixes:
|
|
87
|
+
- 'is_'
|
|
88
|
+
AllowedMethods:
|
|
89
|
+
- 'is_a?'
|
|
90
|
+
|
|
91
|
+
# Performance
|
|
92
|
+
Performance/StringReplacement:
|
|
93
|
+
Enabled: true
|
|
94
|
+
|
|
95
|
+
Performance/RedundantMerge:
|
|
96
|
+
Enabled: true
|
|
97
|
+
|
|
98
|
+
# Minitest
|
|
99
|
+
Minitest/MultipleAssertions:
|
|
100
|
+
Enabled: false # Allow multiple assertions in integration tests
|
|
101
|
+
|
|
102
|
+
Minitest/AssertTruthy:
|
|
103
|
+
Enabled: false # Allow assert instead of assert_equal true
|
|
104
|
+
|
|
105
|
+
# Rails-specific (even though we don't have full Rails)
|
|
106
|
+
Style/Rails/HttpStatus:
|
|
107
|
+
Enabled: false
|
|
108
|
+
|
|
109
|
+
# Custom overrides for this gem
|
|
110
|
+
Style/AccessorGrouping:
|
|
111
|
+
Enabled: false # Allow separate attr_reader/attr_writer
|
|
112
|
+
|
|
113
|
+
Style/MutableConstant:
|
|
114
|
+
Enabled: false # We have some intentionally mutable constants
|
|
115
|
+
|
|
116
|
+
# Allow class variables for registry pattern
|
|
117
|
+
Style/ClassVars:
|
|
118
|
+
Enabled: false
|
|
119
|
+
|
|
120
|
+
# Allow metaprogramming patterns common in Rails engines
|
|
121
|
+
Style/EvalWithLocation:
|
|
122
|
+
Enabled: false
|
|
123
|
+
|
|
124
|
+
Lint/MissingSuper:
|
|
125
|
+
Enabled: false # Allow classes that don't call super
|
|
126
|
+
|
|
127
|
+
# Disable some cops that don't work well with our DSL
|
|
128
|
+
Style/MethodCallWithoutArgsParentheses:
|
|
129
|
+
Enabled: false # Our DSL looks better without parens
|
|
130
|
+
|
|
131
|
+
# Thread safety
|
|
132
|
+
Style/GlobalVars:
|
|
133
|
+
AllowedVariables: ['$0'] # Only allow program name
|
|
134
|
+
|
|
135
|
+
# Database-related
|
|
136
|
+
Style/NumericLiterals:
|
|
137
|
+
Enabled: false # Allow raw numbers in database IDs/amounts
|
data/.simplecov
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SimpleCov configuration file (auto-loaded before test suite)
|
|
4
|
+
# This keeps test_helper.rb clean and follows best practices
|
|
5
|
+
|
|
6
|
+
SimpleCov.start do
|
|
7
|
+
# Use SimpleFormatter for terminal-only output (no HTML generation)
|
|
8
|
+
formatter SimpleCov::Formatter::SimpleFormatter
|
|
9
|
+
|
|
10
|
+
# Track coverage for the lib directory (gem source code)
|
|
11
|
+
add_filter "/test/"
|
|
12
|
+
|
|
13
|
+
# Track the lib and app directories
|
|
14
|
+
track_files "{lib,app}/**/*.rb"
|
|
15
|
+
|
|
16
|
+
# Enable branch coverage for more detailed metrics
|
|
17
|
+
enable_coverage :branch
|
|
18
|
+
|
|
19
|
+
# Set minimum coverage threshold to prevent coverage regression
|
|
20
|
+
minimum_coverage line: 80, branch: 65
|
|
21
|
+
|
|
22
|
+
# Disambiguate parallel test runs
|
|
23
|
+
command_name "Job #{ENV['TEST_ENV_NUMBER']}" if ENV['TEST_ENV_NUMBER']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Print coverage summary to terminal after tests complete
|
|
27
|
+
SimpleCov.at_exit do
|
|
28
|
+
SimpleCov.result.format!
|
|
29
|
+
puts "\n" + "=" * 60
|
|
30
|
+
puts "COVERAGE SUMMARY"
|
|
31
|
+
puts "=" * 60
|
|
32
|
+
puts "Line Coverage: #{SimpleCov.result.covered_percent.round(2)}%"
|
|
33
|
+
puts "Branch Coverage: #{SimpleCov.result.coverage_statistics[:branch]&.percent&.round(2) || 'N/A'}%"
|
|
34
|
+
puts "=" * 60
|
|
35
|
+
end
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to AI Agents (like OpenAI's Codex, Cursor Agent, Claude Code, etc) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
Please go ahead and read the full context for this project at `.cursor/rules/0-overview.mdc` and `.cursor/rules/1-quality.mdc` now. Also read the README for a good overview of the project.
|
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
## [0.1.0] - 2026-02-19
|
|
2
|
+
|
|
3
|
+
Initial release.
|
|
4
|
+
|
|
5
|
+
- User → Membership → Organization pattern with `has_organizations` macro
|
|
6
|
+
- Hierarchical roles (owner > admin > member > viewer) with customizable permissions
|
|
7
|
+
- Token-based invitation system with email delivery
|
|
8
|
+
- Organization switching for multi-org users
|
|
9
|
+
- Ownership transfer with role demotion for previous owner
|
|
10
|
+
- Controller helpers and authorization (`require_organization!`, `require_organization_admin!`)
|
|
11
|
+
- Lifecycle callbacks for integrations (`on_member_joined`, `on_role_changed`, etc.)
|
|
12
|
+
- Row-level locking for race conditions (concurrent invitations, ownership transfers)
|
|
13
|
+
- Works with any auth system (Devise, Rodauth, Sorcery)
|
|
14
|
+
- Edge case handling (last owner can't leave, stale session cleanup, concurrent invitation acceptance)
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
Please go ahead and read the full context for this project at `.cursor/rules/0-overview.mdc` and `.cursor/rules/1-quality.mdc` now. Also read the README for a good overview of the project.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Javi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Javi R
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|