snfoil-policy 0.0.1 → 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/README.md +5 -6
- data/lib/snfoil/policy/version.rb +1 -1
- data/lib/snfoil/policy.rb +16 -8
- data/snfoil-policy.gemspec +12 -10
- metadata +47 -23
- data/.github/workflows/main.yml +0 -46
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.rubocop.yml +0 -39
- data/Rakefile +0 -12
- data/bin/console +0 -15
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6dab1a607349ecc86d023e26ad1d9ba97e96e57318cd129bafef7589b125e1e
|
4
|
+
data.tar.gz: 66fabe2a19f859d6cd50b707987ee34f51e0e85a19abe8fb2e16e880a570f16b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f4dca9af08516db9b3abfd4075eb568adf576c27da6d2e1a372b93e33a72d9fd0753d07a4700d65f8ef5dc683c1d894e1f48127a46dbcb88ed92e62465f50dd
|
7
|
+
data.tar.gz: 64e48295ab0086b1291ea394e44d93a5859c22a1f9e0c1652621cce81f788734897fd8b254c4c5afbaaaf3dad69003737b8387a01a1c663971aba4fbf87be04b
|
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
 [](https://codeclimate.com/github/limited-effort/snfoil-policy/maintainability)
|
4
4
|
|
5
|
-
SnFoil Policies are an easy and intuitive way to
|
6
|
-
|
5
|
+
SnFoil Policies are an easy and intuitive way to build [Pundit](https://github.com/varvet/pundit) style authorization files with a little extra base functionality added in.
|
7
6
|
|
8
7
|
While it isn't required you use [Pundit](https://github.com/varvet/pundit) with it, we highly recommend it.
|
9
8
|
|
@@ -21,7 +20,7 @@ gem 'snfoil-policy'
|
|
21
20
|
|
22
21
|
SnFoil Policies are meant to be used just like Pundit policies except you can build the actions using a helper and some of the setup work has been done for you.
|
23
22
|
|
24
|
-
The entity being
|
23
|
+
The entity being authorized (usually a User) is accessible via the `entity` instance variable.
|
25
24
|
And the record the entity is trying to work with is accessible as the `record` instance variable.
|
26
25
|
|
27
26
|
Use `permission` to start setting up some checks.
|
@@ -88,7 +87,7 @@ end
|
|
88
87
|
permission :update?, with: :create?
|
89
88
|
```
|
90
89
|
|
91
|
-
For more complex authorization mechanisms where more than one type of entity can operate against a record you can supply the type of
|
90
|
+
For more complex authorization mechanisms where more than one type of entity can operate against a record, you can supply the type of entity to check against.
|
92
91
|
|
93
92
|
```ruby
|
94
93
|
permission :create?, User do
|
@@ -115,7 +114,7 @@ end
|
|
115
114
|
|
116
115
|
### Scope
|
117
116
|
|
118
|
-
There is nothing special about SnFoil Policy Scopes. They are just defined to make life a little easier.
|
117
|
+
There is nothing special about SnFoil Policy Scopes. They are just defined to make life a little easier. Check out how to use Scopes in [Pundit](https://github.com/varvet/pundit#scopes), we highly recommend them.
|
119
118
|
|
120
119
|
|
121
120
|
## Development
|
@@ -134,4 +133,4 @@ The gem is available as open source under the terms of the [Apache 2 License](ht
|
|
134
133
|
|
135
134
|
## Code of Conduct
|
136
135
|
|
137
|
-
Everyone interacting in the Snfoil::Policy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/limited-effort/snfoil-policy/blob/main/CODE_OF_CONDUCT.md).
|
136
|
+
Everyone interacting in the Snfoil::Policy project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/limited-effort/snfoil-policy/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/snfoil/policy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2021 Matthew Howes
|
3
|
+
# Copyright 2021 Matthew Howes, Cliff Campbell
|
4
4
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
@@ -28,21 +28,29 @@ module SnFoil
|
|
28
28
|
extend ActiveSupport::Concern
|
29
29
|
|
30
30
|
class_methods do
|
31
|
-
def
|
32
|
-
@
|
31
|
+
def snfoil_permissions
|
32
|
+
@snfoil_permissions ||= {}
|
33
33
|
end
|
34
34
|
|
35
35
|
def permission(authorization_type, entity_class = nil, with: nil, &block)
|
36
|
-
@
|
37
|
-
@
|
38
|
-
if @
|
36
|
+
@snfoil_permissions ||= {}
|
37
|
+
@snfoil_permissions[authorization_type] ||= {}
|
38
|
+
if @snfoil_permissions[authorization_type][entity_class]
|
39
39
|
raise SnFoil::Policy::Error,
|
40
40
|
"permission #{entity_class} #{authorization_type} already defined for #{name}"
|
41
41
|
end
|
42
42
|
|
43
|
-
@
|
43
|
+
@snfoil_permissions[authorization_type][entity_class] = build_permission_exec(with, block)
|
44
44
|
define_permission_method(authorization_type)
|
45
45
|
end
|
46
|
+
|
47
|
+
def inherited(subclass)
|
48
|
+
super
|
49
|
+
|
50
|
+
instance_variables.grep(/@snfoil_.+/).each do |i|
|
51
|
+
subclass.instance_variable_set(i, instance_variable_get(i).dup)
|
52
|
+
end
|
53
|
+
end
|
46
54
|
end
|
47
55
|
|
48
56
|
attr_reader :record, :entity
|
@@ -83,7 +91,7 @@ module SnFoil
|
|
83
91
|
|
84
92
|
def define_permission_method(authorization_type)
|
85
93
|
define_method authorization_type do
|
86
|
-
self.class.
|
94
|
+
self.class.snfoil_permissions[authorization_type].each do |klass, exec|
|
87
95
|
return instance_eval(&exec) if klass.nil? || entity.is_a?(klass)
|
88
96
|
end
|
89
97
|
|
data/snfoil-policy.gemspec
CHANGED
@@ -5,24 +5,24 @@ require_relative 'lib/snfoil/policy/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'snfoil-policy'
|
7
7
|
spec.version = SnFoil::Policy::VERSION
|
8
|
-
spec.authors = ['Matthew Howes']
|
9
|
-
spec.email = ['howeszy@gmail.com']
|
8
|
+
spec.authors = ['Matthew Howes', 'Cliff Campbell']
|
9
|
+
spec.email = ['howeszy@gmail.com', 'cliffcampbell@hey.com']
|
10
10
|
|
11
11
|
spec.summary = 'Pundit Style Permissions Builder'
|
12
12
|
spec.description = 'A set of helper functions to build permission files inspired by Pundit.'
|
13
13
|
spec.homepage = 'https://github.com/limited-effort/snfoil-policy'
|
14
|
-
spec.license = '
|
15
|
-
spec.required_ruby_version = '>= 2.
|
14
|
+
spec.license = 'Apache-2.0'
|
15
|
+
spec.required_ruby_version = '>= 2.6'
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
18
|
spec.metadata['source_code_uri'] = spec.homepage
|
19
19
|
spec.metadata['changelog_uri'] = 'https://github.com/limited-effort/snfoil-policy/blob/main/CHANGELOG.md'
|
20
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
20
21
|
|
21
22
|
# Specify which files should be added to the gem when it is released.
|
22
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
|
24
|
-
|
25
|
-
end
|
24
|
+
ignore_list = %r{\A(?:test/|spec/|bin/|features/|Rakefile|\.\w)}
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) { `git ls-files -z`.split("\x0").reject { |f| f.match(ignore_list) } }
|
26
26
|
|
27
27
|
spec.bindir = 'exe'
|
28
28
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
@@ -30,10 +30,12 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_dependency 'activesupport', '>= 5.2.6'
|
32
32
|
|
33
|
+
spec.add_development_dependency 'bundle-audit', '~> 0.1.0'
|
34
|
+
spec.add_development_dependency 'fasterer', '~> 0.10.0'
|
33
35
|
spec.add_development_dependency 'pry-byebug', '~> 3.9'
|
34
36
|
spec.add_development_dependency 'rake', '~> 13.0'
|
35
37
|
spec.add_development_dependency 'rspec', '~> 3.10'
|
36
|
-
spec.add_development_dependency 'rubocop', '
|
37
|
-
spec.add_development_dependency 'rubocop-performance', '
|
38
|
-
spec.add_development_dependency 'rubocop-rspec', '
|
38
|
+
spec.add_development_dependency 'rubocop', '1.33'
|
39
|
+
spec.add_development_dependency 'rubocop-performance', '1.14.3'
|
40
|
+
spec.add_development_dependency 'rubocop-rspec', '2.12.1'
|
39
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snfoil-policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Howes
|
8
|
+
- Cliff Campbell
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2022-08-08 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
@@ -24,6 +25,34 @@ dependencies:
|
|
24
25
|
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: 5.2.6
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundle-audit
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.1.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.1.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: fasterer
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.10.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.10.0
|
27
56
|
- !ruby/object:Gem::Dependency
|
28
57
|
name: pry-byebug
|
29
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,73 +99,68 @@ dependencies:
|
|
70
99
|
name: rubocop
|
71
100
|
requirement: !ruby/object:Gem::Requirement
|
72
101
|
requirements:
|
73
|
-
- -
|
102
|
+
- - '='
|
74
103
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
104
|
+
version: '1.33'
|
76
105
|
type: :development
|
77
106
|
prerelease: false
|
78
107
|
version_requirements: !ruby/object:Gem::Requirement
|
79
108
|
requirements:
|
80
|
-
- -
|
109
|
+
- - '='
|
81
110
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
111
|
+
version: '1.33'
|
83
112
|
- !ruby/object:Gem::Dependency
|
84
113
|
name: rubocop-performance
|
85
114
|
requirement: !ruby/object:Gem::Requirement
|
86
115
|
requirements:
|
87
|
-
- -
|
116
|
+
- - '='
|
88
117
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
118
|
+
version: 1.14.3
|
90
119
|
type: :development
|
91
120
|
prerelease: false
|
92
121
|
version_requirements: !ruby/object:Gem::Requirement
|
93
122
|
requirements:
|
94
|
-
- -
|
123
|
+
- - '='
|
95
124
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
125
|
+
version: 1.14.3
|
97
126
|
- !ruby/object:Gem::Dependency
|
98
127
|
name: rubocop-rspec
|
99
128
|
requirement: !ruby/object:Gem::Requirement
|
100
129
|
requirements:
|
101
|
-
- -
|
130
|
+
- - '='
|
102
131
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
132
|
+
version: 2.12.1
|
104
133
|
type: :development
|
105
134
|
prerelease: false
|
106
135
|
version_requirements: !ruby/object:Gem::Requirement
|
107
136
|
requirements:
|
108
|
-
- -
|
137
|
+
- - '='
|
109
138
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
139
|
+
version: 2.12.1
|
111
140
|
description: A set of helper functions to build permission files inspired by Pundit.
|
112
141
|
email:
|
113
142
|
- howeszy@gmail.com
|
143
|
+
- cliffcampbell@hey.com
|
114
144
|
executables: []
|
115
145
|
extensions: []
|
116
146
|
extra_rdoc_files: []
|
117
147
|
files:
|
118
|
-
- ".github/workflows/main.yml"
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".rubocop.yml"
|
122
148
|
- CHANGELOG.md
|
123
149
|
- CODE_OF_CONDUCT.md
|
124
150
|
- Gemfile
|
125
151
|
- LICENSE.txt
|
126
152
|
- README.md
|
127
|
-
- Rakefile
|
128
|
-
- bin/console
|
129
|
-
- bin/setup
|
130
153
|
- lib/snfoil/policy.rb
|
131
154
|
- lib/snfoil/policy/version.rb
|
132
155
|
- snfoil-policy.gemspec
|
133
156
|
homepage: https://github.com/limited-effort/snfoil-policy
|
134
157
|
licenses:
|
135
|
-
-
|
158
|
+
- Apache-2.0
|
136
159
|
metadata:
|
137
160
|
homepage_uri: https://github.com/limited-effort/snfoil-policy
|
138
161
|
source_code_uri: https://github.com/limited-effort/snfoil-policy
|
139
162
|
changelog_uri: https://github.com/limited-effort/snfoil-policy/blob/main/CHANGELOG.md
|
163
|
+
rubygems_mfa_required: 'true'
|
140
164
|
post_install_message:
|
141
165
|
rdoc_options: []
|
142
166
|
require_paths:
|
@@ -145,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
169
|
requirements:
|
146
170
|
- - ">="
|
147
171
|
- !ruby/object:Gem::Version
|
148
|
-
version: 2.
|
172
|
+
version: '2.6'
|
149
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
174
|
requirements:
|
151
175
|
- - ">="
|
data/.github/workflows/main.yml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
name: build
|
2
|
-
on:
|
3
|
-
push:
|
4
|
-
branches: [ main ]
|
5
|
-
pull_request:
|
6
|
-
|
7
|
-
jobs:
|
8
|
-
test:
|
9
|
-
|
10
|
-
runs-on: ubuntu-latest
|
11
|
-
|
12
|
-
strategy:
|
13
|
-
matrix:
|
14
|
-
ruby-version: [2.7, 2.6, 2.5]
|
15
|
-
|
16
|
-
steps:
|
17
|
-
- uses: actions/checkout@v2
|
18
|
-
- name: Set up Ruby ${{ matrix.ruby-version }}
|
19
|
-
uses: ruby/setup-ruby@v1.81.0
|
20
|
-
with:
|
21
|
-
ruby-version: ${{ matrix.ruby-version }}
|
22
|
-
bundler-cache: true
|
23
|
-
- name: Install dependencies
|
24
|
-
run: bundle install
|
25
|
-
- name: Run tests
|
26
|
-
run: bundle exec rspec
|
27
|
-
lint:
|
28
|
-
|
29
|
-
runs-on: ubuntu-latest
|
30
|
-
|
31
|
-
strategy:
|
32
|
-
matrix:
|
33
|
-
ruby-version: [2.7, 2.6, 2.5, '3.0']
|
34
|
-
|
35
|
-
steps:
|
36
|
-
- uses: actions/checkout@v2
|
37
|
-
- name: Set up Ruby ${{ matrix.ruby-version }}
|
38
|
-
uses: ruby/setup-ruby@v1.81.0
|
39
|
-
with:
|
40
|
-
ruby-version: ${{ matrix.ruby-version }}
|
41
|
-
bundler-cache: true
|
42
|
-
- name: Install dependencies
|
43
|
-
run: bundle install
|
44
|
-
- name: Run rubocop
|
45
|
-
run: bundle exec rubocop
|
46
|
-
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-performance
|
3
|
-
- rubocop-rspec
|
4
|
-
|
5
|
-
AllCops:
|
6
|
-
NewCops: enable
|
7
|
-
SuggestExtensions: false
|
8
|
-
TargetRubyVersion: 2.5.0
|
9
|
-
|
10
|
-
# ================ LAYOUT ==============
|
11
|
-
Layout/LineLength:
|
12
|
-
Max: 150
|
13
|
-
|
14
|
-
# ================ LINT ================
|
15
|
-
Lint/AmbiguousBlockAssociation:
|
16
|
-
Exclude:
|
17
|
-
- spec/**/*_spec.rb
|
18
|
-
|
19
|
-
Lint/EmptyClass:
|
20
|
-
Exclude:
|
21
|
-
- spec/**/*_spec.rb
|
22
|
-
|
23
|
-
# ================ Metics ================
|
24
|
-
Metrics/BlockLength:
|
25
|
-
Exclude:
|
26
|
-
- spec/**/*_spec.rb
|
27
|
-
|
28
|
-
# ================ RSPEC ================
|
29
|
-
RSpec/FilePath:
|
30
|
-
Enabled: false
|
31
|
-
|
32
|
-
RSpec/MultipleExpectations:
|
33
|
-
Max: 5
|
34
|
-
|
35
|
-
RSpec/MultipleMemoizedHelpers:
|
36
|
-
Enabled: false
|
37
|
-
|
38
|
-
RSpec/NestedGroups:
|
39
|
-
Max: 5
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'snfoil/policy'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start(__FILE__)
|