access-granted-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9cec44df04ff324bee663c5703640a1422702618
4
+ data.tar.gz: 3f542efd1c9314ff0a7db646be8a1e6acfac1594
5
+ SHA512:
6
+ metadata.gz: 64c7ec10c7d5e7eeedf60c14026bfa187ede9efdcc64c78e9f29d3db33cf7a524483fb07e9a31b4c268a1b71eb98da850361c626e3c6c950ddb5054bb2ac1cbf
7
+ data.tar.gz: faa6c8038b3d365667cc0e6c5881c4c86a572e35cdbe5cce44def8d45f9255a681747083528d7c0d8a29afc4dc0da12e2688336c79af83188d322d5738a27021
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Piotrek Okoński
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # AccessGranted::Rails
2
+
3
+ This is a Rails-flavoured extension of [AccessGranted](https://github.com/pokonski/access-granted)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'access-granted-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install access-granted-rails
18
+
19
+ ## Usage
20
+
21
+ AccessGranted::Rails offers integration with Rails framework by providing multiple helper methods.
22
+ Similarly to CanCan with this gem you can use `can?`, `cannot?`, `authorize!` and `current_policy` in your controllers and views.
23
+
24
+ For more usage see [AccessGranted README](https://github.com/pokonski/access-granted)
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( http://github.com/pokonski/access-granted-rails/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'access-granted/rails'
5
+ require 'access-granted/rails/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "access-granted-rails"
9
+ spec.version = AccessGranted::Rails::VERSION
10
+ spec.authors = ["Piotrek Okoński"]
11
+ spec.email = ["piotrek@okonski.org"]
12
+ spec.description = %q{Role based authorization gem}
13
+ spec.summary = %q{Elegant whitelist and role based authorization with ability to prioritize roles.}
14
+ spec.homepage = "https://github.com/pokonski/access-granted-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+
25
+ spec.add_dependency "access-granted", "~> 0.1"
26
+ end
@@ -0,0 +1 @@
1
+ require 'access-granted/rails'
@@ -0,0 +1,13 @@
1
+ require 'access-granted/rails/controller_methods'
2
+
3
+ module AccessGranted
4
+ module Rails
5
+
6
+ end
7
+ end
8
+
9
+ if defined? ActionController::Base
10
+ ActionController::Base.class_eval do
11
+ include AccessGranted::Rails::ControllerMethods
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module AccessGranted
2
+ module Rails
3
+ module ControllerMethods
4
+ def current_policy
5
+ @current_policy ||= ::Policy.new(current_user)
6
+ end
7
+
8
+ def self.included(base)
9
+ base.helper_method :can?, :cannot?, :current_policy
10
+ end
11
+
12
+ def can?(*args)
13
+ current_policy.can?(*args)
14
+ end
15
+
16
+ def cannot?(*args)
17
+ current_policy.cannot?(*args)
18
+ end
19
+
20
+ def authorize!(*args)
21
+ current_policy.authorize!(*args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,5 @@
1
+ module AccessGranted
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe AccessGranted::Rails::ControllerMethods do
4
+ before(:each) do
5
+ @current_user = double("User")
6
+ @controller_class = Class.new
7
+ @controller = @controller_class.new
8
+ @controller_class.stub(:helper_method).with(:can?, :cannot?, :current_policy)
9
+ @controller_class.send(:include, AccessGranted::Rails::ControllerMethods)
10
+ @controller.stub(:current_user).and_return(@current_user)
11
+ end
12
+
13
+ it "should have current_policy method returning Policy instance" do
14
+ @controller.current_policy.should be_kind_of(AccessGranted::Policy)
15
+ end
16
+
17
+ it "provides can? and cannot? method delegated to current_policy" do
18
+ @controller.can?(:read, String).should be_false
19
+ @controller.cannot?(:read, String).should be_true
20
+ end
21
+
22
+ describe "#authorize!" do
23
+ it "raises exception when authorization fails" do
24
+ expect { @controller.authorize!(:read, String) }.to raise_error(AccessGranted::AccessDenied)
25
+ end
26
+
27
+ it "returns subject if authorization succeeds" do
28
+ klass = Class.new do
29
+ include AccessGranted::Policy
30
+
31
+ def configure(user)
32
+ role :member, 1 do
33
+ can :read, String
34
+ end
35
+ end
36
+ end
37
+ policy = klass.new(@current_user)
38
+ @controller.stub(:current_policy).and_return(policy)
39
+ @controller.authorize!(:read, String).should == String
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ if ENV["COV"]
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ config.order = 'random'
15
+ end
16
+
17
+ module ActionController
18
+ class Base
19
+ def self.helper_method(*args)
20
+ end
21
+ end
22
+ end
23
+ require 'access-granted'
24
+ require 'access-granted-rails'
25
+
26
+ class Policy
27
+ include AccessGranted::Policy
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: access-granted-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotrek Okoński
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: access-granted
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ description: Role based authorization gem
56
+ email:
57
+ - piotrek@okonski.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - access-granted-rails.gemspec
69
+ - lib/access-granted-rails.rb
70
+ - lib/access-granted/rails.rb
71
+ - lib/access-granted/rails/controller_methods.rb
72
+ - lib/access-granted/rails/version.rb
73
+ - spec/controller_methods_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/pokonski/access-granted-rails
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.0
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Elegant whitelist and role based authorization with ability to prioritize
99
+ roles.
100
+ test_files:
101
+ - spec/controller_methods_spec.rb
102
+ - spec/spec_helper.rb
103
+ has_rdoc: