simple_authorize 0.1.0 → 1.0.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/.simplecov +15 -0
- data/CHANGELOG.md +15 -0
- data/LICENSE.txt +1 -1
- data/README.md +210 -15
- data/SECURITY.md +73 -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 +120 -0
- metadata +62 -4
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Start SimpleCov before anything else
|
|
4
|
+
require "simplecov"
|
|
5
|
+
SimpleCov.command_name "RSpec"
|
|
6
|
+
|
|
7
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
|
8
|
+
require "simple_authorize"
|
|
9
|
+
require "simple_authorize/rspec"
|
|
10
|
+
require "active_model"
|
|
11
|
+
|
|
12
|
+
# Mock objects for testing
|
|
13
|
+
class User
|
|
14
|
+
attr_accessor :id, :role
|
|
15
|
+
|
|
16
|
+
def initialize(id: 1, role: :viewer)
|
|
17
|
+
@id = id
|
|
18
|
+
@role = role
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def admin?
|
|
22
|
+
role == :admin
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def contributor?
|
|
26
|
+
role == :contributor
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def viewer?
|
|
30
|
+
role == :viewer
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def can_create_content?
|
|
34
|
+
admin? || contributor?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def can_manage_content?
|
|
38
|
+
admin?
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Post
|
|
43
|
+
attr_accessor :id, :user_id, :published
|
|
44
|
+
|
|
45
|
+
def initialize(id: 1, user_id: 1, published: true)
|
|
46
|
+
@id = id
|
|
47
|
+
@user_id = user_id
|
|
48
|
+
@published = published
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.model_name
|
|
52
|
+
ActiveModel::Name.new(self, nil, "Post")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Sample policy used across specs
|
|
57
|
+
class PostPolicy < SimpleAuthorize::Policy
|
|
58
|
+
def index?
|
|
59
|
+
true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def show?
|
|
63
|
+
true
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def create?
|
|
67
|
+
user.present? && user.can_create_content?
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def update?
|
|
71
|
+
user.present? && (owner? || user.admin?)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def destroy?
|
|
75
|
+
user.present? && (owner? || user.admin?)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def publish?
|
|
79
|
+
user&.admin? || (user&.contributor? && owner?)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def visible_attributes
|
|
83
|
+
if user&.admin?
|
|
84
|
+
%i[id title body published user_id]
|
|
85
|
+
elsif user.present?
|
|
86
|
+
%i[id title body published]
|
|
87
|
+
else
|
|
88
|
+
[]
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def editable_attributes
|
|
93
|
+
if user&.admin?
|
|
94
|
+
%i[title body published]
|
|
95
|
+
elsif user&.contributor?
|
|
96
|
+
%i[title body]
|
|
97
|
+
else
|
|
98
|
+
[]
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
RSpec.configure do |config|
|
|
104
|
+
config.expect_with :rspec do |expectations|
|
|
105
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
config.mock_with :rspec do |mocks|
|
|
109
|
+
mocks.verify_partial_doubles = true
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
113
|
+
config.filter_run_when_matching :focus
|
|
114
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
|
115
|
+
config.disable_monkey_patching!
|
|
116
|
+
config.warnings = true
|
|
117
|
+
config.default_formatter = "doc" if config.files_to_run.one?
|
|
118
|
+
config.order = :random
|
|
119
|
+
Kernel.srand config.seed
|
|
120
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_authorize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Scott
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2025-11-03 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: activesupport
|
|
@@ -23,6 +24,20 @@ dependencies:
|
|
|
23
24
|
- - ">="
|
|
24
25
|
- !ruby/object:Gem::Version
|
|
25
26
|
version: '6.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: i18n
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.0'
|
|
26
41
|
- !ruby/object:Gem::Dependency
|
|
27
42
|
name: railties
|
|
28
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -51,6 +66,34 @@ dependencies:
|
|
|
51
66
|
- - ">="
|
|
52
67
|
- !ruby/object:Gem::Version
|
|
53
68
|
version: '6.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: simplecov
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.22'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.22'
|
|
54
97
|
description: SimpleAuthorize is a lightweight authorization framework for Rails that
|
|
55
98
|
provides policy-based access control, role management, and scope filtering without
|
|
56
99
|
requiring external gems. Inspired by Pundit but completely standalone.
|
|
@@ -60,20 +103,32 @@ executables: []
|
|
|
60
103
|
extensions: []
|
|
61
104
|
extra_rdoc_files: []
|
|
62
105
|
files:
|
|
106
|
+
- ".simplecov"
|
|
63
107
|
- CHANGELOG.md
|
|
64
108
|
- LICENSE.txt
|
|
65
109
|
- README.md
|
|
66
110
|
- Rakefile
|
|
111
|
+
- SECURITY.md
|
|
67
112
|
- lib/generators/simple_authorize/install/install_generator.rb
|
|
68
113
|
- lib/generators/simple_authorize/install/templates/README
|
|
69
114
|
- lib/generators/simple_authorize/install/templates/application_policy.rb
|
|
70
115
|
- lib/generators/simple_authorize/install/templates/simple_authorize.rb
|
|
116
|
+
- lib/generators/simple_authorize/policy/policy_generator.rb
|
|
117
|
+
- lib/generators/simple_authorize/policy/templates/policy.rb.tt
|
|
118
|
+
- lib/generators/simple_authorize/policy/templates/policy_spec.rb.tt
|
|
119
|
+
- lib/generators/simple_authorize/policy/templates/policy_test.rb.tt
|
|
71
120
|
- lib/simple_authorize.rb
|
|
72
121
|
- lib/simple_authorize/configuration.rb
|
|
73
122
|
- lib/simple_authorize/controller.rb
|
|
74
123
|
- lib/simple_authorize/policy.rb
|
|
124
|
+
- lib/simple_authorize/railtie.rb
|
|
125
|
+
- lib/simple_authorize/rspec.rb
|
|
126
|
+
- lib/simple_authorize/test_helpers.rb
|
|
75
127
|
- lib/simple_authorize/version.rb
|
|
76
128
|
- sig/simple_authorize.rbs
|
|
129
|
+
- spec/examples.txt
|
|
130
|
+
- spec/rspec_matchers_spec.rb
|
|
131
|
+
- spec/spec_helper.rb
|
|
77
132
|
homepage: https://github.com/scottlaplant/simple_authorize
|
|
78
133
|
licenses:
|
|
79
134
|
- MIT
|
|
@@ -82,6 +137,8 @@ metadata:
|
|
|
82
137
|
source_code_uri: https://github.com/scottlaplant/simple_authorize
|
|
83
138
|
changelog_uri: https://github.com/scottlaplant/simple_authorize/blob/main/CHANGELOG.md
|
|
84
139
|
bug_tracker_uri: https://github.com/scottlaplant/simple_authorize/issues
|
|
140
|
+
rubygems_mfa_required: 'true'
|
|
141
|
+
post_install_message:
|
|
85
142
|
rdoc_options: []
|
|
86
143
|
require_paths:
|
|
87
144
|
- lib
|
|
@@ -89,14 +146,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
89
146
|
requirements:
|
|
90
147
|
- - ">="
|
|
91
148
|
- !ruby/object:Gem::Version
|
|
92
|
-
version: 3.
|
|
149
|
+
version: 3.2.0
|
|
93
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
151
|
requirements:
|
|
95
152
|
- - ">="
|
|
96
153
|
- !ruby/object:Gem::Version
|
|
97
154
|
version: '0'
|
|
98
155
|
requirements: []
|
|
99
|
-
rubygems_version: 3.
|
|
156
|
+
rubygems_version: 3.5.22
|
|
157
|
+
signing_key:
|
|
100
158
|
specification_version: 4
|
|
101
159
|
summary: Simple, powerful authorization for Rails without external dependencies
|
|
102
160
|
test_files: []
|