simon_says 0.0.4 → 0.0.27b6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab4a955ff3bda5ede4c1168208aef92fbb50440b
4
- data.tar.gz: 013ee6a83b935c5b037387c046cca2f0bb3dd529
3
+ metadata.gz: 19de05c0bda5120ccdd27df9f861c3d436982c25
4
+ data.tar.gz: 21ff0c7d067c9edbfeabf8bfb83a6b9be301e183
5
5
  SHA512:
6
- metadata.gz: eaffbaf64cb1e6b01becc5da9908df34deb5e01b49f529c06ff917efe72b22ffc3afb1531dee3cd36f7ce2677f80e700cf198b12b71ba852c851ac51a61d4567
7
- data.tar.gz: c2458015080be3856965b60922abfcc9e30dd6884f16a49fb06e6b9d63eb0bcc2683f8eb2d85cae5bf0846dac3f37dead9f512f8d319bcdfdf6fe03d3a9c5c31
6
+ metadata.gz: 0fdb85e2380e4505ddcc07e0106f83260d41224021a96411b58bdd162a21c94c2cc2c5a2d97dfb144364ddb342c0e0873f5e7b9c1006d4a9cca16889cf22e558
7
+ data.tar.gz: 7ae83204bb804a8e9a0fbbe75582c57644a2e60c9a5fab752014c1ffdf011f292bd738f842152a2c65bdb5ae7c5e6baa214b1c7634397e6eb584d49407e644b6
data/.gitignore CHANGED
@@ -12,8 +12,5 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
- .ruby-version
16
-
17
- *.gem
18
15
 
19
16
  /test/rails_app/db/*.sqlite3
data/.travis.yml CHANGED
@@ -1,9 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.1.4"
4
- before_script:
5
- - cd test/rails_app/
6
- - RAILS_ENV=test bundle exec rake db:migrate db:fixtures:load
7
- - cd ../..
8
- script:
9
- - bundle exec rake test
3
+ - 2.1.3
data/Gemfile CHANGED
@@ -9,7 +9,5 @@ group :development do
9
9
  gem 'rdoc'
10
10
 
11
11
  gem 'guard'
12
- gem 'guard-minitest', "2.3.2"
12
+ gem 'guard-minitest'
13
13
  end
14
-
15
- gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md CHANGED
@@ -4,10 +4,152 @@
4
4
  Logo](https://raw.githubusercontent.com/SimplyBuilt/SimonSays/master/SimonSays.png)
5
5
 
6
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!
7
+ works great with devise! Take a look at the
8
+ [docs](http://simplybuilt.github.io/SimonSays) for more details!
9
9
 
10
- ![Build Status](https://travis-ci.org/SimplyBuilt/SimonSays.svg)
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'simon_says'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install simon_says
25
+
26
+ ## Usage
27
+
28
+ SimonSays consists of two parts. One is a model concern called
29
+ `Roleable`. The other is a controller concern called `Authorizer`. The
30
+ idea is that you give users some set of roles and find and authorize
31
+ against those roles on a controller (and action) basis.
32
+
33
+ ### Roleable
34
+
35
+ First, we need to define roles. Generally speaking roles will exist on
36
+ either User models or on relationship models (like a through model linking a
37
+ User to another resource).
38
+
39
+ Here's a quick example:
40
+
41
+ class User < ActiveRecord::Base
42
+ include SimonSays::Roleable
43
+
44
+ has_roles :add, :edit, :delete
45
+ end
46
+
47
+ User can now have none or one more roles:
48
+
49
+ User.new.roles
50
+ => []
51
+
52
+ User.new.tap { |u| u.roles = :add, :edit }.roles
53
+ => [:add, :edit]
54
+
55
+ The roles are stored as an integer. When using `Roleable` you need add a
56
+ `roles_mask` column. Note that we do not have any generators for this yet.
57
+ Feel free to fork add them!
58
+
59
+ You can customize this attribute using the `:as` option. For example:
60
+
61
+ class Admin < ActiveRecord::Base
62
+ include SimonSays::Roleable
63
+
64
+ has_roles :design, :support, :moderator, as: :access
65
+ end
66
+
67
+ Admin.new.access
68
+ => []
69
+
70
+ Admin.new(access: :support).access
71
+ => [:support]
72
+
73
+ You can also use `Roleable` on through models. For example:
74
+
75
+ class Membership < ActiveRecord::Base
76
+ include SimonSays::Roleable
77
+
78
+ belongs_to :user
79
+ belongs_to :document
80
+
81
+ has_roles :download, :edit, :delete,
82
+ end
83
+
84
+ There will be several methods as well as a scope generated by
85
+ calling `has_roles`. See below for more details on the methods
86
+ generated by `Roleable`. Be sure to also checkout the
87
+ [docs](http://simplybuilt.github.io/SimonSays/SimonSays/Roleable/ClassMethods.html)
88
+ for more details!
89
+
90
+ ### Authorizer
91
+
92
+ Next up is the `Authorizer`. This concern provides several methods that
93
+ can be used within your controllers to declaratively find resources and
94
+ ensuring certain role-based conditions are met.
95
+
96
+ *Please note*, certain assumptions are made with `Authorizer`. Building
97
+ upon the above `User` and `Admin` models, `Authorizer` would assume
98
+ there is a `current_user` and `current_admin`. If these models
99
+ correspond to devise scopes this would be the case by default.
100
+ Additionally there would need to a be an `authenticate_user!` and
101
+ `authenticate_admin!` method, which devise provides as well.
102
+
103
+ Eventually, we would like to see better customization around the
104
+ authentication aspects. This library is intended to solve the problem of
105
+ authorization and access control. It is not an authentication library.
106
+
107
+ The first step is to include the concern within the
108
+ `ApplicationController` and to configure the default authorization
109
+ method:
110
+
111
+ class ApplicationController < ActionController::Base
112
+ include SimonSays::Authorizer
113
+ end
114
+
115
+ Let's start with an example; here we'll create a reports resource that
116
+ only Admin's with support access to use. The roles are supplied within
117
+ the `authorize_resource` method. Note that, multiple roles can be
118
+ supplied; access is granted if one or more are met.
119
+
120
+ # routes.rb
121
+ # Reports resource for Admins
122
+ resources :reports
123
+
124
+ # app/controllers/reports_controller.rb
125
+ class ReportsController < ApplicationController
126
+ authorize_resource :admin, :support
127
+ find_resource :report, except: [:index, :new, :create]
128
+ end
129
+
130
+ Here's another example using the `Membership` through model.
131
+
132
+ # routes.rb
133
+ resources :documents
134
+
135
+ # app/controllers/documents_controller.rb
136
+ class DocumentsController < ApplicationController
137
+ authenticate :user
138
+
139
+ find_and_authorize :documents, :edit, through: :memberships, only: [:edit, :update]
140
+ find_and_authorize :documents, :delete, through: :memberships, only: :destroy
141
+ end
142
+
143
+ The document model will not be found if the membership relationship does
144
+ not exist and an `ActiveRecord::NotFound` exception will be raised.
145
+
146
+ If the membership record exists, but the role conditions are not met,
147
+ `Authorizer` will raise a `Denied` exception.
148
+
149
+ If the document is found and the user has the access to it. It will be
150
+ set as the `@document` instance variable. Make sure to checkout the
151
+ [docs](http://simplybuilt.github.io/SimonSays/SimonSays/Authorizer/ClassMethods.html)
152
+ for more details!
11
153
 
12
154
  ## Contributing
13
155
 
@@ -2,7 +2,7 @@ module SimonSays
2
2
  module Authorizer
3
3
  extend ActiveSupport::Concern
4
4
 
5
- class Denied < StandardError
5
+ class Denied < Exception
6
6
  def initialize(as, required, actual)
7
7
  # TODO i18n for err message (as should be singluarized with 1 flag)
8
8
  super "Access denied; #{required * ', '} role is required. Current access is #{actual * ', '}"
@@ -138,8 +138,7 @@ module SimonSays
138
138
  scope = send(self.class.default_authorization_scope)
139
139
 
140
140
  elsif options[:from]
141
- scope = instance_variable_get("@#{options[:from]}") || send(options[:from])
142
-
141
+ scope = instance_variable_get("@#{options[:from]}")
143
142
  else
144
143
  klass = (options[:class_name] || resource).to_s
145
144
  # TODO support array of namespaces?
@@ -1,3 +1,3 @@
1
1
  module SimonSays
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.27b6"
3
3
  end
data/simon_says.gemspec CHANGED
@@ -20,9 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "activesupport", "~> 4.0"
22
22
 
23
- spec.add_development_dependency "bundler", "1.7.4"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rails", "~> 4.1"
26
- spec.add_development_dependency "responders", "~> 1.0"
27
26
  spec.add_development_dependency "mocha", "~> 1.1"
28
27
  end
@@ -0,0 +1,40 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
+ gem 'rails', '4.1.6'
6
+ # Use sqlite3 as the database for Active Record
7
+ gem 'sqlite3'
8
+ # Use SCSS for stylesheets
9
+ gem 'sass-rails', '~> 4.0.3'
10
+ # Use Uglifier as compressor for JavaScript assets
11
+ gem 'uglifier', '>= 1.3.0'
12
+ # Use CoffeeScript for .js.coffee assets and views
13
+ gem 'coffee-rails', '~> 4.0.0'
14
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
15
+ # gem 'therubyracer', platforms: :ruby
16
+
17
+ # Use jquery as the JavaScript library
18
+ gem 'jquery-rails'
19
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
20
+ gem 'turbolinks'
21
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
22
+ gem 'jbuilder', '~> 2.0'
23
+ # bundle exec rake doc:rails generates the API under doc/api.
24
+ gem 'sdoc', '~> 0.4.0', group: :doc
25
+
26
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
27
+ gem 'spring', group: :development
28
+
29
+ # Use ActiveModel has_secure_password
30
+ # gem 'bcrypt', '~> 3.1.7'
31
+
32
+ # Use unicorn as the app server
33
+ # gem 'unicorn'
34
+
35
+ # Use Capistrano for deployment
36
+ # gem 'capistrano-rails', group: :development
37
+
38
+ # Use debugger
39
+ # gem 'debugger', group: [:development, :test]
40
+
@@ -0,0 +1,120 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (4.1.6)
5
+ actionpack (= 4.1.6)
6
+ actionview (= 4.1.6)
7
+ mail (~> 2.5, >= 2.5.4)
8
+ actionpack (4.1.6)
9
+ actionview (= 4.1.6)
10
+ activesupport (= 4.1.6)
11
+ rack (~> 1.5.2)
12
+ rack-test (~> 0.6.2)
13
+ actionview (4.1.6)
14
+ activesupport (= 4.1.6)
15
+ builder (~> 3.1)
16
+ erubis (~> 2.7.0)
17
+ activemodel (4.1.6)
18
+ activesupport (= 4.1.6)
19
+ builder (~> 3.1)
20
+ activerecord (4.1.6)
21
+ activemodel (= 4.1.6)
22
+ activesupport (= 4.1.6)
23
+ arel (~> 5.0.0)
24
+ activesupport (4.1.6)
25
+ i18n (~> 0.6, >= 0.6.9)
26
+ json (~> 1.7, >= 1.7.7)
27
+ minitest (~> 5.1)
28
+ thread_safe (~> 0.1)
29
+ tzinfo (~> 1.1)
30
+ arel (5.0.1.20140414130214)
31
+ builder (3.2.2)
32
+ coffee-rails (4.0.1)
33
+ coffee-script (>= 2.2.0)
34
+ railties (>= 4.0.0, < 5.0)
35
+ coffee-script (2.3.0)
36
+ coffee-script-source
37
+ execjs
38
+ coffee-script-source (1.8.0)
39
+ erubis (2.7.0)
40
+ execjs (2.2.2)
41
+ hike (1.2.3)
42
+ i18n (0.6.11)
43
+ jbuilder (2.2.2)
44
+ activesupport (>= 3.0.0, < 5)
45
+ multi_json (~> 1.2)
46
+ jquery-rails (3.1.2)
47
+ railties (>= 3.0, < 5.0)
48
+ thor (>= 0.14, < 2.0)
49
+ json (1.8.1)
50
+ mail (2.6.1)
51
+ mime-types (>= 1.16, < 3)
52
+ mime-types (2.4.2)
53
+ minitest (5.4.2)
54
+ multi_json (1.10.1)
55
+ rack (1.5.2)
56
+ rack-test (0.6.2)
57
+ rack (>= 1.0)
58
+ rails (4.1.6)
59
+ actionmailer (= 4.1.6)
60
+ actionpack (= 4.1.6)
61
+ actionview (= 4.1.6)
62
+ activemodel (= 4.1.6)
63
+ activerecord (= 4.1.6)
64
+ activesupport (= 4.1.6)
65
+ bundler (>= 1.3.0, < 2.0)
66
+ railties (= 4.1.6)
67
+ sprockets-rails (~> 2.0)
68
+ railties (4.1.6)
69
+ actionpack (= 4.1.6)
70
+ activesupport (= 4.1.6)
71
+ rake (>= 0.8.7)
72
+ thor (>= 0.18.1, < 2.0)
73
+ rake (10.3.2)
74
+ rdoc (4.1.2)
75
+ json (~> 1.4)
76
+ sass (3.2.19)
77
+ sass-rails (4.0.3)
78
+ railties (>= 4.0.0, < 5.0)
79
+ sass (~> 3.2.0)
80
+ sprockets (~> 2.8, <= 2.11.0)
81
+ sprockets-rails (~> 2.0)
82
+ sdoc (0.4.1)
83
+ json (~> 1.7, >= 1.7.7)
84
+ rdoc (~> 4.0)
85
+ spring (1.1.3)
86
+ sprockets (2.11.0)
87
+ hike (~> 1.2)
88
+ multi_json (~> 1.0)
89
+ rack (~> 1.0)
90
+ tilt (~> 1.1, != 1.3.0)
91
+ sprockets-rails (2.2.0)
92
+ actionpack (>= 3.0)
93
+ activesupport (>= 3.0)
94
+ sprockets (>= 2.8, < 4.0)
95
+ sqlite3 (1.3.9)
96
+ thor (0.19.1)
97
+ thread_safe (0.3.4)
98
+ tilt (1.4.1)
99
+ turbolinks (2.4.0)
100
+ coffee-rails
101
+ tzinfo (1.2.2)
102
+ thread_safe (~> 0.1)
103
+ uglifier (2.5.3)
104
+ execjs (>= 0.3.0)
105
+ json (>= 1.8.0)
106
+
107
+ PLATFORMS
108
+ ruby
109
+
110
+ DEPENDENCIES
111
+ coffee-rails (~> 4.0.0)
112
+ jbuilder (~> 2.0)
113
+ jquery-rails
114
+ rails (= 4.1.6)
115
+ sass-rails (~> 4.0.3)
116
+ sdoc (~> 0.4.0)
117
+ spring
118
+ sqlite3
119
+ turbolinks
120
+ uglifier (>= 1.3.0)
@@ -1,7 +1,6 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
- require 'responders'
5
4
 
6
5
  # Require the gems listed in Gemfile, including any gems
7
6
  # you've limited to :test, :development, or :production.
@@ -13,11 +13,9 @@ Rails.application.configure do
13
13
  config.eager_load = true
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
16
+ config.serve_static_assets = true
17
17
  config.static_cache_control = 'public, max-age=3600'
18
18
 
19
- config.active_support.test_order = :random
20
-
21
19
  # Show full error reports and disable caching.
22
20
  config.consider_all_requests_local = true
23
21
  config.action_controller.perform_caching = false
@@ -38,8 +36,4 @@ Rails.application.configure do
38
36
 
39
37
  # Raises error for missing translations
40
38
  # config.action_view.raise_on_missing_translations = true
41
-
42
- # Use transactional fixtures
43
- config.use_transactional_fixtures = true
44
-
45
39
  end
@@ -14,7 +14,7 @@
14
14
  ActiveRecord::Schema.define(version: 20141017140833) do
15
15
 
16
16
  create_table "admin_reports", force: true do |t|
17
- t.string "title", limit: nil
17
+ t.string "title"
18
18
  t.datetime "created_at"
19
19
  t.datetime "updated_at"
20
20
  end
@@ -26,7 +26,7 @@ ActiveRecord::Schema.define(version: 20141017140833) do
26
26
  end
27
27
 
28
28
  create_table "documents", force: true do |t|
29
- t.string "title", limit: nil
29
+ t.string "title"
30
30
  t.datetime "created_at"
31
31
  t.datetime "updated_at"
32
32
  end
data/test/test_helper.rb CHANGED
@@ -1,8 +1,3 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
- require 'mocha/mini_test'
5
-
6
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
7
2
  require 'simon_says' # HELLO SIMON
8
3
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simon_says
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.27b6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Coyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.7.4
33
+ version: '1.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.7.4
40
+ version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.1'
69
- - !ruby/object:Gem::Dependency
70
- name: responders
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: mocha
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +90,6 @@ extra_rdoc_files: []
104
90
  files:
105
91
  - ".gitignore"
106
92
  - ".gitpublish"
107
- - ".ruby-version"
108
93
  - ".travis.yml"
109
94
  - Gemfile
110
95
  - Guardfile
@@ -123,6 +108,8 @@ files:
123
108
  - test/models/admin_test.rb
124
109
  - test/models/membership_test.rb
125
110
  - test/rails_app/.gitignore
111
+ - test/rails_app/Gemfile
112
+ - test/rails_app/Gemfile.lock
126
113
  - test/rails_app/README.rdoc
127
114
  - test/rails_app/Rakefile
128
115
  - test/rails_app/app/assets/images/.keep
@@ -217,12 +204,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
204
  version: '0'
218
205
  required_rubygems_version: !ruby/object:Gem::Requirement
219
206
  requirements:
220
- - - ">="
207
+ - - ">"
221
208
  - !ruby/object:Gem::Version
222
- version: '0'
209
+ version: 1.3.1
223
210
  requirements: []
224
211
  rubyforge_project:
225
- rubygems_version: 2.4.6
212
+ rubygems_version: 2.4.2
226
213
  signing_key:
227
214
  specification_version: 4
228
215
  summary: Light-weight, declarative authorization and access control for Rails
@@ -232,6 +219,8 @@ test_files:
232
219
  - test/models/admin_test.rb
233
220
  - test/models/membership_test.rb
234
221
  - test/rails_app/.gitignore
222
+ - test/rails_app/Gemfile
223
+ - test/rails_app/Gemfile.lock
235
224
  - test/rails_app/README.rdoc
236
225
  - test/rails_app/Rakefile
237
226
  - test/rails_app/app/assets/images/.keep
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.4