simon_says 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: def24394416cde084dfc11e6bf8c8490c16f64ad
4
- data.tar.gz: b41bf2b8ba3dec59f38232e1fd95d837f6a9dd59
3
+ metadata.gz: eb74ffaa3fbf69fbab2c3534393df41d91f8fccd
4
+ data.tar.gz: 8c96349d0aa76b9617b095cb17a4e91d05bd3829
5
5
  SHA512:
6
- metadata.gz: c92b127087300e5d13aa60808ff5477d3f7d8c525c6fd39ffd3c2627fe7d3b8d939cbbc786d9a1fc74607c01b480f62293a55428ff9cf26346a83c7a43db3b79
7
- data.tar.gz: d93d82ad00d4e97caf4ba5e52c3ac7e073cfce70395590f775b8438bd6b48a097e8ab333cc3d9f63279f8f23e0ef849ef3506b9c91b9fe2cfbd73e4c4c553384
6
+ metadata.gz: 71da79481390650b93d0045f379206ed05a1882de58afdb603a88f7996ce717e9fd46941ece13ac926d5901411e9435731760d0d3511194f90df0bf32efe6920
7
+ data.tar.gz: 0c8e4ff2fcc7a0932d0a794e48fb3382c3d083d65b0cf53a326adcbaf2e2e1d23a919354b3c81682b24ce5ca229580da29460dc25f51e26b09534059dd27d6c8
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  cache: bundler
3
3
  install: bundle install --jobs=3 --retry=3
4
4
  rvm:
5
- - "2.3.1"
5
+ - "2.3.3"
6
+ - "2.4.0"
6
7
  script:
7
8
  - bundle exec rake test
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mikeycgto@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source 'https://rubygems.org'
2
- ruby '2.3.1'
3
2
 
4
- # Specify your gem's dependencies in auth_lib.gemspec
5
3
  gemspec
6
4
 
7
5
  group :development do
@@ -12,7 +10,3 @@ group :development do
12
10
  gem 'guard'
13
11
  gem 'guard-minitest', "2.3.2"
14
12
  end
15
-
16
- group :test do
17
- gem "codeclimate-test-reporter", require: false
18
- end
data/README.md CHANGED
@@ -3,11 +3,195 @@
3
3
  ![SimonSays
4
4
  Logo](https://raw.githubusercontent.com/SimplyBuilt/SimonSays/master/SimonSays.png)
5
5
 
6
- This gem is a simple, declarative, role-based access control system for Rails that
7
- works great with devise! Take a look at the [website](http://simonsays.onsimplybuilt.com) or
8
- [docs](http://www.rubydoc.info/github/SimplyBuilt/SimonSays/) for more details!
6
+ This gem is a simple, declarative, role-based access control system for
7
+ Rails that works great with devise! Take a look at the
8
+ [docs](http://www.rubydoc.info/github/SimplyBuilt/SimonSays/) for more
9
+ details.
9
10
 
10
- ![Build Status](https://travis-ci.org/SimplyBuilt/SimonSays.svg)
11
+ [![Travis Build Status](https://travis-ci.org/SimplyBuilt/SimonSays.svg)](https://travis-ci.org/SimplyBuilt/SimonSays)
12
+ [![Gem Version](https://badge.fury.io/rb/simon_says.svg)](https://badge.fury.io/rb/simon_says)
13
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
14
+
15
+ ## About
16
+
17
+ A ruby gem for simple, declarative, role-based access control system for
18
+ [Rails](https://github.com/rails/rails) that works great with
19
+ [Devise](https://github.com/plataformatec/devise)! Take a look at the
20
+ [docs](http://www.rubydoc.info/github/SimplyBuilt/SimonSays/) for more
21
+ details!
22
+
23
+ ### Installation
24
+
25
+ SimonSays can be installed via your Gemfile or using Ruby gems directly.
26
+
27
+ ```ruby
28
+ gem 'simon_says'
29
+ ```
30
+
31
+ ### Usage
32
+
33
+ SimonSays consists of two parts:
34
+
35
+ 1. A [Roleable](#roleable) concern provides a way to define access roles
36
+ on a given resource, such as User or on join through model.
37
+ 2. An [Authorizer](#authorizer) concern which provides a lightweight,
38
+ declarative API to controllers for finding and authorizing these
39
+ resources in relation to an already authenticated resource, like a
40
+ User or Admin.
41
+
42
+ #### Roleable
43
+
44
+ First, we need to define some roles. Generally speaking roles will exist
45
+ on either "User" models or on relationship models (such as a through
46
+ model linking a User to another resource). Roles are stored as an
47
+ integer and [bitmasking](https://en.wikipedia.org/wiki/Mask_(computing))
48
+ is used to determine authorization logic. When using `Roleable` you need
49
+ to add a `roles_mask` column to the model.
50
+
51
+ For example:
52
+
53
+ ```ruby
54
+ class User < ActiveRecord::Base
55
+ include SimonSays::Roleable
56
+
57
+ has_roles :add, :edit, :delete
58
+ end
59
+
60
+ # > User.new.roles
61
+ # => []
62
+
63
+ # > u = User.new(roles: %i[add edit])
64
+ #
65
+ # > u.roles
66
+ # => [:add, :edit]
67
+ # > u.has_add?
68
+ # => true
69
+ # > u.has_delete?
70
+ # => false
71
+ ```
72
+
73
+ The attribute name can be customized by using the `:as` option as seen
74
+ here in the Admin model:
75
+
76
+ ```ruby
77
+ class Admin < ActiveRecord::Base
78
+ include SimonSays::Roleable
79
+
80
+ has_roles :design, :support, :moderator, as: :access
81
+ end
82
+
83
+ # > Admin.new.access
84
+ # => []
85
+
86
+ # > Admin.new(access: :support).access
87
+ # => [:support]
88
+ ```
89
+
90
+ We can also use `has_roles` to define roles on a join through model
91
+ which is used to associate a User with a resource.
92
+
93
+ ```ruby
94
+
95
+ class Membership < ActiveRecord::Base
96
+ include SimonSays::Roleable
97
+
98
+ belongs_to :user
99
+ belongs_to :document
100
+
101
+ has_roles :download, :edit, :delete,
102
+ end
103
+
104
+ # > Membership.new(roles: Membership::ROLES).roles
105
+ # => [:download, :edit, :delete]
106
+ ```
107
+
108
+ It is useful to note the dynamically generated `has_` methods as shown
109
+ in the User model as well the `ROLES` constant which is used in the
110
+ Membership example. Take a look at the [roleable source
111
+ code](https://github.com/SimplyBuilt/SimonSays/blob/master/lib/simon_says/roleable.rb)
112
+ to see how features are dynamically generated when using `has_roles`.
113
+
114
+ #### Authorizer
115
+
116
+ The `Authorizer` concern provides several methods that can be used within
117
+ your controllers in declarative manner.
118
+
119
+ Please note, certain assumptions are made with `Authorizer`. Building
120
+ upon the above User and Admin model examples, `Authorizer` would assume
121
+ there is a `current_user` and `current_admin` method. If these models
122
+ correspond to devise scopes this would be the case by default.
123
+ Additionally there would need to be an `authenticate_user!` and
124
+ `authenticate_admin!` methods, which devise provides as well.
125
+
126
+ Eventually, we would like to see better customization around the
127
+ authentication aspects. This library is intended to solve the problem of
128
+ authorization and access control. It is not an authentication library.
129
+
130
+ In general, the `Authorizer` concern provides four core declarative methods
131
+ to be used in controllers. All of these methods accept the `:only` and
132
+ `:except` options which end up being used in a `before_action` callback.
133
+
134
+ - `authenticate(scope, opts): Declarative convenience method to setup
135
+ authenticate `before_action`
136
+ - `find_resource(resource, opts)`: Declarative method to find a resource
137
+ and assign it to an instance variable
138
+ - `authorize_resource(resource, *roles)`: Authorize resource for given
139
+ roles
140
+ - `find_and_authorize(resource, *roles)`: Find a resource and then try
141
+ authorize it for the given roles
142
+
143
+ When find resources, the `default_authorization_scope` is used. It can
144
+ be customized on a per-controller basis. For example:
145
+
146
+ ```ruby
147
+ class ApplicationController < ActionController::Base
148
+ include SimonSays::Authorizer
149
+
150
+ self.default_authorization_scope = :current_user
151
+ end
152
+ ```
153
+
154
+ To authorize resources against a given role, we use either `authorize`
155
+ or `find_and_authorize`. For example, consider this
156
+ `DocumentsController` which uses an authenticated `User` resource and a
157
+ `Membership` through model:
158
+
159
+ ```ruby
160
+ class DocumentsController < ApplicationController
161
+ authenticate :user
162
+
163
+ find_and_authorize :documents, :edit, through: :memberships, only: [:edit, :update]
164
+ find_and_authorize :documents, :delete, through: :memberships, only: :destroy
165
+ end
166
+ ```
167
+
168
+ This controller will find Document resources and assign them to the
169
+ `@document` instance variable. For the `:edit` and `:update` actions,
170
+ it'll require membership with an `:edit` role. For the `:destroy` method, a
171
+ memberships with the `:delete` role is required. It is possible for a
172
+ given User to have both, one, or neither of those roles.
173
+
174
+ The `find_resource` method may raise an `ActiveRecord::RecordNotFound`
175
+ exception. The `authorize` method may raise a
176
+ `SimonSays::Authorizer::Denied` exception if there is insufficient role
177
+ access. As a result, the `find_and_authorize` method may raise either
178
+ exception.
179
+
180
+ We can also use a different authorization scope by via the `:from`
181
+ option for `find_resource` and `find_and_authorize`. For example:
182
+
183
+ ```ruby
184
+ class ReportsController < ApplicationController
185
+ authorize_resource :admin, :support
186
+
187
+ find_resource :report, from: :current_admin, except: [:index, :new, :create]
188
+ end
189
+ ```
190
+
191
+ Please refer to the
192
+ [docs](http://www.rubydoc.info/github/SimplyBuilt/SimonSays/SimonSays/Authorizer/ClassMethods)
193
+ for more information on the various declarative methods provided by the
194
+ `Authorizer`.
11
195
 
12
196
  ## Contributing
13
197
 
@@ -1,3 +1,3 @@
1
1
  module SimonSays
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
data/simon_says.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activesupport", ">= 4.0", "< 5.1"
21
+ spec.add_dependency "activesupport", ">= 4.0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.9"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
data/test/test_helper.rb CHANGED
@@ -1,6 +1,3 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
1
  require 'mocha/mini_test'
5
2
 
6
3
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simon_says
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Coyne
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-24 00:00:00.000000000 Z
13
+ date: 2017-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -19,9 +19,6 @@ dependencies:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: '4.0'
22
- - - "<"
23
- - !ruby/object:Gem::Version
24
- version: '5.1'
25
22
  type: :runtime
26
23
  prerelease: false
27
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,9 +26,6 @@ dependencies:
29
26
  - - ">="
30
27
  - !ruby/object:Gem::Version
31
28
  version: '4.0'
32
- - - "<"
33
- - !ruby/object:Gem::Version
34
- version: '5.1'
35
29
  - !ruby/object:Gem::Dependency
36
30
  name: bundler
37
31
  requirement: !ruby/object:Gem::Requirement
@@ -119,11 +113,11 @@ files:
119
113
  - ".gitignore"
120
114
  - ".gitpublish"
121
115
  - ".travis.yml"
116
+ - CODE_OF_CONDUCT.md
122
117
  - Gemfile
123
118
  - Guardfile
124
119
  - LICENSE.txt
125
120
  - README.md
126
- - ROADMAP.md
127
121
  - Rakefile
128
122
  - SimonSays.png
129
123
  - lib/simon_says.rb
@@ -240,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
234
  version: '0'
241
235
  requirements: []
242
236
  rubyforge_project:
243
- rubygems_version: 2.5.1
237
+ rubygems_version: 2.6.12
244
238
  signing_key:
245
239
  specification_version: 4
246
240
  summary: Light-weight, declarative authorization and access control for Rails
data/ROADMAP.md DELETED
@@ -1,9 +0,0 @@
1
- # SimonSays Road Map
2
-
3
- ## v2
4
-
5
- - Customization of authentication methods
6
- - Currently we sort of assume you're using devise
7
- - More expressive `find_and_authorize` syntax
8
- - Add a way of authorizing against ALL roles not just any role
9
- - `grep -r TODO .`