accessly 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +16 -0
- data/.gitignore +54 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +128 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/accessly.gemspec +32 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/accessly.rb +23 -0
- data/lib/accessly/base.rb +33 -0
- data/lib/accessly/models/permitted_action.rb +7 -0
- data/lib/accessly/models/permitted_action_on_object.rb +8 -0
- data/lib/accessly/permission/grant.rb +95 -0
- data/lib/accessly/permission/revoke.rb +87 -0
- data/lib/accessly/permitted_actions/base.rb +40 -0
- data/lib/accessly/permitted_actions/on_object_query.rb +65 -0
- data/lib/accessly/permitted_actions/query.rb +42 -0
- data/lib/accessly/policy/base.rb +269 -0
- data/lib/accessly/query.rb +122 -0
- data/lib/accessly/query_builder.rb +24 -0
- data/lib/accessly/version.rb +3 -0
- data/lib/generators/accessly/install/USAGE +5 -0
- data/lib/generators/accessly/install/install_generator.rb +51 -0
- data/lib/generators/accessly/install/templates/db/migrate/create_permitted_action_on_objects.rb +15 -0
- data/lib/generators/accessly/install/templates/db/migrate/create_permitted_actions.rb +13 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60f014b72282ae3ebb27bac60f28bea7c596b1b9
|
4
|
+
data.tar.gz: 2ef2178dd5a914519839fad848c5aa6526c6a1ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33ea523a967256119180e2b4a49557c5951d31db882d8c46fa823613d8226ad8896c5f44cb6f27cc767145208ada43e740086caadc853d35fdda00e9f23c0e39
|
7
|
+
data.tar.gz: 01f0e9af0c17a8159e0ccbc8d8c34f5ac48e267dde25e819dbfae52eb132832639feedcb2bb92b6c47ba6a107780a4121b15050a67640d6211167c8fd348ae52
|
data/.editorconfig
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
2
|
+
# coding styles between different editors and IDEs
|
3
|
+
# editorconfig.org
|
4
|
+
|
5
|
+
root = true
|
6
|
+
|
7
|
+
[*]
|
8
|
+
charset = utf-8
|
9
|
+
indent_style = space
|
10
|
+
indent_size = 2
|
11
|
+
end_of_line = lf
|
12
|
+
trim_trailing_whitespace = true
|
13
|
+
insert_final_newline = true
|
14
|
+
|
15
|
+
[*.md]
|
16
|
+
trim_trailing_whitespace = false
|
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/log
|
5
|
+
/tmp
|
6
|
+
*.sqlite3
|
7
|
+
logfile
|
8
|
+
*.log
|
9
|
+
/db/*.sqlite3
|
10
|
+
/db/*.sqlite3-journal
|
11
|
+
/public/system
|
12
|
+
/coverage/
|
13
|
+
/spec/tmp
|
14
|
+
*.orig
|
15
|
+
rerun.txt
|
16
|
+
pickle-email-*.html
|
17
|
+
|
18
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
19
|
+
config/initializers/secret_token.rb
|
20
|
+
|
21
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
22
|
+
# config/secrets.yml
|
23
|
+
|
24
|
+
# dotenv
|
25
|
+
# TODO Comment out this rule if environment variables can be committed
|
26
|
+
.env
|
27
|
+
|
28
|
+
## Environment normalization:
|
29
|
+
/.bundle
|
30
|
+
/vendor/bundle
|
31
|
+
|
32
|
+
# these should all be checked in to normalize the environment:
|
33
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
|
38
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
39
|
+
/vendor/assets/bower_components
|
40
|
+
*.bowerrc
|
41
|
+
bower.json
|
42
|
+
|
43
|
+
# Ignore pow environment settings
|
44
|
+
.powenv
|
45
|
+
|
46
|
+
# Ignore Byebug command history file.
|
47
|
+
.byebug_history
|
48
|
+
|
49
|
+
# Ignore gem stuff
|
50
|
+
pkg/
|
51
|
+
|
52
|
+
# Ignore generated yard docs
|
53
|
+
.yardoc/
|
54
|
+
doc/
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.4.2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
accessly (0.0.1)
|
5
|
+
activerecord (~> 5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (5.1.5)
|
11
|
+
actionpack (= 5.1.5)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.1.5)
|
15
|
+
actionpack (= 5.1.5)
|
16
|
+
actionview (= 5.1.5)
|
17
|
+
activejob (= 5.1.5)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.1.5)
|
21
|
+
actionview (= 5.1.5)
|
22
|
+
activesupport (= 5.1.5)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (>= 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.1.5)
|
28
|
+
activesupport (= 5.1.5)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubi (~> 1.4)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (5.1.5)
|
34
|
+
activesupport (= 5.1.5)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.1.5)
|
37
|
+
activesupport (= 5.1.5)
|
38
|
+
activerecord (5.1.5)
|
39
|
+
activemodel (= 5.1.5)
|
40
|
+
activesupport (= 5.1.5)
|
41
|
+
arel (~> 8.0)
|
42
|
+
activesupport (5.1.5)
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
+
i18n (~> 0.7)
|
45
|
+
minitest (~> 5.1)
|
46
|
+
tzinfo (~> 1.1)
|
47
|
+
arel (8.0.0)
|
48
|
+
builder (3.2.3)
|
49
|
+
concurrent-ruby (1.0.5)
|
50
|
+
crass (1.0.3)
|
51
|
+
database_cleaner (1.5.3)
|
52
|
+
erubi (1.7.1)
|
53
|
+
globalid (0.4.1)
|
54
|
+
activesupport (>= 4.2.0)
|
55
|
+
i18n (0.9.5)
|
56
|
+
concurrent-ruby (~> 1.0)
|
57
|
+
loofah (2.2.2)
|
58
|
+
crass (~> 1.0.2)
|
59
|
+
nokogiri (>= 1.5.9)
|
60
|
+
mail (2.7.0)
|
61
|
+
mini_mime (>= 0.1.1)
|
62
|
+
method_source (0.9.0)
|
63
|
+
mini_mime (1.0.0)
|
64
|
+
mini_portile2 (2.3.0)
|
65
|
+
minitest (5.11.3)
|
66
|
+
nio4r (2.3.0)
|
67
|
+
nokogiri (1.8.2)
|
68
|
+
mini_portile2 (~> 2.3.0)
|
69
|
+
rack (2.0.4)
|
70
|
+
rack-test (0.8.3)
|
71
|
+
rack (>= 1.0, < 3)
|
72
|
+
rails (5.1.5)
|
73
|
+
actioncable (= 5.1.5)
|
74
|
+
actionmailer (= 5.1.5)
|
75
|
+
actionpack (= 5.1.5)
|
76
|
+
actionview (= 5.1.5)
|
77
|
+
activejob (= 5.1.5)
|
78
|
+
activemodel (= 5.1.5)
|
79
|
+
activerecord (= 5.1.5)
|
80
|
+
activesupport (= 5.1.5)
|
81
|
+
bundler (>= 1.3.0)
|
82
|
+
railties (= 5.1.5)
|
83
|
+
sprockets-rails (>= 2.0.0)
|
84
|
+
rails-dom-testing (2.0.3)
|
85
|
+
activesupport (>= 4.2.0)
|
86
|
+
nokogiri (>= 1.6)
|
87
|
+
rails-html-sanitizer (1.0.3)
|
88
|
+
loofah (~> 2.0)
|
89
|
+
railties (5.1.5)
|
90
|
+
actionpack (= 5.1.5)
|
91
|
+
activesupport (= 5.1.5)
|
92
|
+
method_source
|
93
|
+
rake (>= 0.8.7)
|
94
|
+
thor (>= 0.18.1, < 2.0)
|
95
|
+
rake (10.5.0)
|
96
|
+
sprockets (3.7.1)
|
97
|
+
concurrent-ruby (~> 1.0)
|
98
|
+
rack (> 1, < 3)
|
99
|
+
sprockets-rails (3.2.1)
|
100
|
+
actionpack (>= 4.0)
|
101
|
+
activesupport (>= 4.0)
|
102
|
+
sprockets (>= 3.0.0)
|
103
|
+
sqlite3 (1.3.13)
|
104
|
+
thor (0.20.0)
|
105
|
+
thread_safe (0.3.6)
|
106
|
+
tzinfo (1.2.5)
|
107
|
+
thread_safe (~> 0.1)
|
108
|
+
websocket-driver (0.6.5)
|
109
|
+
websocket-extensions (>= 0.1.0)
|
110
|
+
websocket-extensions (0.1.3)
|
111
|
+
|
112
|
+
PLATFORMS
|
113
|
+
ruby
|
114
|
+
|
115
|
+
DEPENDENCIES
|
116
|
+
accessly!
|
117
|
+
bundler (~> 1.16)
|
118
|
+
database_cleaner
|
119
|
+
minitest (~> 5.0)
|
120
|
+
rails (~> 5.0)
|
121
|
+
rake (~> 10.0)
|
122
|
+
sqlite3
|
123
|
+
|
124
|
+
RUBY VERSION
|
125
|
+
ruby 2.4.2p198
|
126
|
+
|
127
|
+
BUNDLED WITH
|
128
|
+
1.16.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Lessonly
|
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) 2018 Aaron Milam
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Accessly
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/accessly`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'accessly'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install accessly
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lessonly/accessly.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/accessly.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "accessly/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "accessly"
|
8
|
+
spec.version = Accessly::VERSION
|
9
|
+
spec.authors = ["Aaron Milam", "Eddie Hourigan", "Ross Reinhardt"]
|
10
|
+
spec.email = ["devops@lessonly.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simplified access control in Rails}
|
13
|
+
spec.description = %q{Use the policy pattern to define access control mechanisms in Rails. Store user-level, group-level, or org-level permission on any given record or concept in the database with ultra-fast lookups.}
|
14
|
+
spec.homepage = "https://github.com/lessonly/accessly"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "activerecord", "~> 5.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
spec.add_development_dependency "database_cleaner", "~> 1.5"
|
30
|
+
spec.add_development_dependency "sqlite3", "~> 1.3"
|
31
|
+
spec.add_development_dependency "rails", "~> 5.0"
|
32
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "accessly"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/accessly.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "accessly/version"
|
2
|
+
require "accessly/query"
|
3
|
+
require "accessly/permission/grant"
|
4
|
+
require "accessly/permission/revoke"
|
5
|
+
require "accessly/models/permitted_action"
|
6
|
+
require "accessly/models/permitted_action_on_object"
|
7
|
+
|
8
|
+
module Accessly
|
9
|
+
|
10
|
+
unless defined?(GrantError) == "constant" && GrantError.class == Class
|
11
|
+
GrantError = Class.new(StandardError)
|
12
|
+
end
|
13
|
+
|
14
|
+
unless defined?(RevokeError) == "constant" && RevokeError.class == Class
|
15
|
+
RevokeError = Class.new(StandardError)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Accessly's tables are prefixed with accessly_ to
|
19
|
+
# prevent any naming conflicts with other tables in the database.
|
20
|
+
def self.table_name_prefix
|
21
|
+
"accessly_"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "accessly/permitted_actions/query"
|
2
|
+
require "accessly/permitted_actions/on_object_query"
|
3
|
+
|
4
|
+
|
5
|
+
module Accessly
|
6
|
+
class Base
|
7
|
+
|
8
|
+
# Create an instance of Accessly::Base.
|
9
|
+
# Lookups are cached in inherited object(s) to prevent redundant calls to the database.
|
10
|
+
# Pass in a Hash or ActiveRecord::Base for actors if the actor(s)
|
11
|
+
# inherit some permissions from other actors in the system. This may happen
|
12
|
+
# when you have a user in one or more groups or organizations with their own
|
13
|
+
# access control permissions.
|
14
|
+
#
|
15
|
+
# @param actors [Hash, ActiveRecord::Base] The actor(s) we're checking permission(s)
|
16
|
+
def initialize(actors)
|
17
|
+
@segment_id = -1
|
18
|
+
@actors = case actors
|
19
|
+
when Hash
|
20
|
+
actors
|
21
|
+
else
|
22
|
+
{ actors.class.name => actors.id }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param segment_id [Integer] The segment to further separate permissions requests
|
27
|
+
# @return [Accessly::Base] returns the object caller
|
28
|
+
def on_segment(segment_id)
|
29
|
+
@segment_id = segment_id
|
30
|
+
self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|