authoryze 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.watchr +96 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/authoryze.gemspec +27 -0
- data/lib/authoryze.rb +43 -0
- data/lib/authoryze/configuration.rb +30 -0
- data/lib/authoryze/exceptions.rb +17 -0
- data/lib/authoryze/rails.rb +18 -0
- data/lib/authoryze/rails/authoryze_filter.rb +37 -0
- data/lib/authoryze/rails/can_filter.rb +18 -0
- data/lib/authoryze/rails/controller_extensions.rb +38 -0
- data/lib/authoryze/rails/filter.rb +18 -0
- data/lib/authoryze/version.rb +3 -0
- data/spec/authorize/configuration_spec.rb +3 -0
- data/spec/authorize/rails_spec.rb +27 -0
- data/spec/authoryze_spec.rb +59 -0
- data/spec/spec_helper.rb +20 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzBjOTQ1NWVmNmJiYjJmNzMyYTE2M2RlNTljMDNkNmU5OTYxOTg4Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2YyZTBkYmMwNWE1ZTRmZTQxNWUxYmI5Y2M5YjczYmRmNjc2YjZiMg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzdmZThiYTI0ZTNjNThjNTUzNjE1NzM1NTU3MjQzN2Y0NDhlNmI3YWUwNGVl
|
10
|
+
ZTcxYmU5MTM1Mzg1YTNlZTUxNDRmODkzZjFjZWNjYmU4OWE1OTE0ZWRiMmYz
|
11
|
+
N2ZiMmRkOThiZWUyMzU4YTQ2ODQxYjJjNDMyZDUzZjMyYmNlNDM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NTIwYWNmZDFiMGU4ZGNmNzczNmZjOGRjNTc2MjlkMWM1ZWQyZWUwMTgxOTY1
|
14
|
+
NDI5MjdmNzgxZGM2YWU2YWFiOWVhYmRjZWFiZjc2MGRjNDVmMzA0ZmYzZDQ1
|
15
|
+
MWY2OWJlOGFmMTU1OTlmMzIxZDIzODIxZWY5YzAxZTI4NDRmYjc=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p392
|
data/.watchr
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
puts "Run with: watchr #{__FILE__}. \n\nRequired gems: watchr rev"
|
3
|
+
exit 1
|
4
|
+
end
|
5
|
+
|
6
|
+
# --------------------------------------------------
|
7
|
+
# Convenience Methods
|
8
|
+
# --------------------------------------------------
|
9
|
+
def run(cmd)
|
10
|
+
sleep(2)
|
11
|
+
puts("%s %s [%s]" % ["|\n" * 5 , cmd , Time.now.to_s])
|
12
|
+
$last_test = cmd
|
13
|
+
system(cmd)
|
14
|
+
end
|
15
|
+
|
16
|
+
def run_all_specs
|
17
|
+
tags = "--tag #{ARGV[1]}" if ARGV[1]
|
18
|
+
run "bundle exec rake -s spec SPEC_OPTS='--order rand #{tags.to_s}'"
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_last_test
|
22
|
+
run($last_test)
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_single_spec *spec
|
26
|
+
tags = "--tag #{ARGV[1]}" if ARGV[1]
|
27
|
+
spec = spec.join(' ')
|
28
|
+
run "bundle exec rspec #{spec} --order rand #{tags}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_specs_with_shared_examples(shared_example_filename, spec_path = 'spec')
|
32
|
+
|
33
|
+
# Returns the names of the shared examples in filename
|
34
|
+
def shared_examples(filename)
|
35
|
+
lines = File.readlines(filename)
|
36
|
+
lines.grep(/shared_examples_for[\s'"]+(.+)['"]\s*[do|\{]/) do |matching_line|
|
37
|
+
$1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns array with filenames of the specs using shared_example
|
42
|
+
def specs_with_shared_example(shared_example, path)
|
43
|
+
command = "grep -lrE 'it_should_behave_like .(#{shared_example}).' #{path}"
|
44
|
+
`#{command}`.split
|
45
|
+
end
|
46
|
+
|
47
|
+
shared_examples(shared_example_filename).each do |shared_example|
|
48
|
+
specs_to_run = specs_with_shared_example(shared_example, spec_path)
|
49
|
+
run_single_spec(specs_to_run) unless specs_to_run.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_cucumber_scenario scenario_path
|
55
|
+
if scenario_path !~ /.*\.feature$/
|
56
|
+
scenario_path = $last_scenario
|
57
|
+
end
|
58
|
+
$last_scenario = scenario_path
|
59
|
+
run "bundle exec cucumber #{scenario_path} --tags @dev"
|
60
|
+
end
|
61
|
+
|
62
|
+
# --------------------------------------------------
|
63
|
+
# Watchr Rules
|
64
|
+
# --------------------------------------------------
|
65
|
+
watch( '^spec/spec_helper\.rb' ) { run_all_specs }
|
66
|
+
watch( '^spec/shared_behaviors/.*\.rb' ) { |m| run_specs_with_shared_examples(m[0]) }
|
67
|
+
watch( '^spec/.*_spec\.rb' ) { |m| run_single_spec(m[0]) }
|
68
|
+
watch( '^app/lib/.*' ) { |m| run_last_test }
|
69
|
+
watch( '^spec/factories.*' ) { |m| run_last_test }
|
70
|
+
watch( '^test_harness/.*' ) { |m| run_last_test }
|
71
|
+
watch( '^app/(.*)\.rb' ) { |m| run_single_spec("spec/%s_spec.rb" % m[1]) }
|
72
|
+
watch( '^app/views/(.*)\.haml' ) { |m| run_single_spec("spec/views/%s.haml_spec.rb" % m[1]) }
|
73
|
+
watch( '^lib/(.*)\.rb' ) { |m| run_single_spec("spec/other/%s_spec.rb" % m[1] ) }
|
74
|
+
watch( '^features/*/.*' ) { |m| run_cucumber_scenario(m[0]) }
|
75
|
+
watch( '^test-harness/*/.*' ) { |m| run_cucumber_scenario(m[0]) }
|
76
|
+
|
77
|
+
|
78
|
+
# --------------------------------------------------
|
79
|
+
# Signal Handling
|
80
|
+
# --------------------------------------------------
|
81
|
+
# Ctrl-\
|
82
|
+
Signal.trap('QUIT') do
|
83
|
+
puts " --- Running all tests ---\n\n"
|
84
|
+
run_all_specs
|
85
|
+
end
|
86
|
+
|
87
|
+
# Ctrl-T
|
88
|
+
Signal.trap('TSTP') do
|
89
|
+
puts " --- Running last test --\n\n"
|
90
|
+
run_cucumber_scenario nil
|
91
|
+
end
|
92
|
+
|
93
|
+
# Ctrl-C
|
94
|
+
Signal.trap('INT') { abort("\n") }
|
95
|
+
|
96
|
+
puts "Watching.."
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Maher Hawash
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Authoryze
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'authoryze'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install authoryze
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/authoryze.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'authoryze/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "authoryze"
|
8
|
+
spec.version = Authoryze::VERSION
|
9
|
+
spec.authors = ["Maher Hawash"]
|
10
|
+
spec.email = ["gmhawash@gmail.com"]
|
11
|
+
spec.description = %q{Provides matrix based and role level authorization}
|
12
|
+
spec.summary = %q{matrix based and role level authorization}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'watchr'
|
25
|
+
spec.add_development_dependency 'debugger'
|
26
|
+
spec.add_development_dependency 'simplecov'
|
27
|
+
end
|
data/lib/authoryze.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
require 'authoryze/version'
|
3
|
+
require 'authoryze/rails'
|
4
|
+
require 'authoryze/exceptions'
|
5
|
+
require 'authoryze/configuration'
|
6
|
+
|
7
|
+
module Authoryze
|
8
|
+
class << self
|
9
|
+
extend Forwardable
|
10
|
+
Configuration.defined_settings.each do |setting|
|
11
|
+
def_delegators :configuration, setting, "#{setting.to_s}="
|
12
|
+
end
|
13
|
+
|
14
|
+
# @public
|
15
|
+
# Returns the global configuration, or initializes a new configuration
|
16
|
+
# object if it doesn't exist yet.
|
17
|
+
#
|
18
|
+
def configuration
|
19
|
+
@configuration ||= Authoryze::Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# @public
|
23
|
+
# Yields the global configuration to a block.
|
24
|
+
# @yield [configuration] global configuration
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# Authoryze.configure do |c|
|
28
|
+
# c.root = 'path/to/ruote/assets'
|
29
|
+
# end
|
30
|
+
# @see Authoryze::Configuration
|
31
|
+
def configure(&block)
|
32
|
+
unless block_given?
|
33
|
+
raise ArgumentError.new("You tried to .configure without a block!")
|
34
|
+
end
|
35
|
+
yield configuration
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset!
|
39
|
+
@configuration = nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Authoryze
|
2
|
+
# Stores configuration information
|
3
|
+
#
|
4
|
+
# Configuration information is loaded from a configuration block defined within
|
5
|
+
# the client application.
|
6
|
+
#
|
7
|
+
# @example Standard settings
|
8
|
+
# Authroyze.configure do |c|
|
9
|
+
# c.resource_accessor = :current_user # controller.current_user
|
10
|
+
# c.permission_collection = :permissions # controller.current_user.permissions
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
class Configuration
|
14
|
+
class << self
|
15
|
+
def define_setting(name)
|
16
|
+
defined_settings << name
|
17
|
+
attr_accessor name
|
18
|
+
end
|
19
|
+
|
20
|
+
def defined_settings
|
21
|
+
@defined_settings ||= []
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
define_setting :resource_accessor
|
26
|
+
|
27
|
+
define_setting :permissions_collection
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Authoryze
|
2
|
+
class AccessDenied < StandardError
|
3
|
+
attr_reader :action, :subject
|
4
|
+
attr_writer :default_message
|
5
|
+
|
6
|
+
def initialize(message = nil, action = nil, subject = nil)
|
7
|
+
@message = message
|
8
|
+
@action = action
|
9
|
+
@subject = subject
|
10
|
+
@default_message = I18n.t(:"unauthorized.default", :default => "You are not authorized to access this page.")
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
@message || @default_message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Authoryze
|
2
|
+
module Rails
|
3
|
+
def self.setup
|
4
|
+
if defined?(::Rails) && defined?(::ActionController::Base)
|
5
|
+
require 'authoryze/rails/controller_extensions'
|
6
|
+
require 'authoryze/rails/can_filter'
|
7
|
+
require 'authoryze/rails/authoryze_filter'
|
8
|
+
|
9
|
+
ActionController::Base.class_eval do
|
10
|
+
include Authoryze::Rails::ControllerExtensions
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Authoryze::Rails.setup
|
18
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Authoryze
|
2
|
+
module Rails
|
3
|
+
class AuthoryzeFilter
|
4
|
+
def initialize(controller_class)
|
5
|
+
@controller_name = controller_class.controller_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def filter(controller)
|
9
|
+
@controller = controller
|
10
|
+
unless matches_permission?
|
11
|
+
raise Authoryze::AccessDenied, "Permission '#{action}' is not allowed for current user"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def matches_permission?
|
17
|
+
[:manage, action].any? do |permission|
|
18
|
+
permission = "%s_%s?" % [permission, @controller_name]
|
19
|
+
@controller.can.respond_to?(permission) &&
|
20
|
+
@controller.can.send(permission)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def action
|
25
|
+
@action ||= {
|
26
|
+
:index => :read,
|
27
|
+
:show => :read,
|
28
|
+
:new => :create,
|
29
|
+
:create => :create,
|
30
|
+
:edit => :update,
|
31
|
+
:update => :update,
|
32
|
+
}[@controller.request.parameters['action'].to_sym]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Authoryze
|
2
|
+
module Rails
|
3
|
+
class CanFilter
|
4
|
+
def initialize(permissions)
|
5
|
+
@permissions = permissions
|
6
|
+
end
|
7
|
+
|
8
|
+
def filter(controller)
|
9
|
+
@permissions.each do |permission|
|
10
|
+
unless controller.can.send("#{permission}?")
|
11
|
+
raise Authoryze::AccessDenied, "Permission '#{permission}' is not allowed for current user"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Authoryze
|
4
|
+
module Rails
|
5
|
+
module ControllerExtensions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
class_eval do
|
10
|
+
helper_method :can
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def can
|
15
|
+
@__can_authoryze ||= OpenStruct.new begin
|
16
|
+
if resource = send(Authoryze.resource_accessor)
|
17
|
+
Hash[resource.send(Authoryze.permissions_collection).map{|x| ['%s?' % x,true]}]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
def authoryze!(*args)
|
24
|
+
options = args.extract_options!
|
25
|
+
filter = Authoryze::Rails::AuthoryzeFilter.new(self)
|
26
|
+
self.before_filter(filter, options.slice(:only, :except, :if, :unless))
|
27
|
+
end
|
28
|
+
|
29
|
+
def can(*args)
|
30
|
+
options = args.extract_options!
|
31
|
+
filter = Authoryze::Rails::CanFilter.new(args)
|
32
|
+
self.before_filter(filter, options.slice(:only, :except, :if, :unless))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Authoryze
|
2
|
+
module Rails
|
3
|
+
class Filter
|
4
|
+
def initialize(permissions)
|
5
|
+
@permissions = permissions
|
6
|
+
end
|
7
|
+
|
8
|
+
def filter(controller)
|
9
|
+
@permissions.each do |permission|
|
10
|
+
unless controller.can.send("#{permission}?")
|
11
|
+
raise Authoryze::AccessDenied, "Permission '#{permission}' is not allowed for current user"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe Authoryze::Rails do
|
2
|
+
describe '.setup' do
|
3
|
+
it 'injects ControllerExtensions into ActionController::Base' do
|
4
|
+
stub_const("Rails", :rails)
|
5
|
+
stub_const("ActionController::Base", Class.new)
|
6
|
+
stub_const("Authoryze::Rails::ControllerExtensions", Class.new)
|
7
|
+
described_class.should_receive(:require).any_number_of_times
|
8
|
+
ActionController::Base.should_receive(:include).with(Authoryze::Rails::ControllerExtensions)
|
9
|
+
|
10
|
+
described_class.setup
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'skips injection if Rails not defined' do
|
14
|
+
stub_const("ActionController::Base", Class.new)
|
15
|
+
described_class.should_not_receive(:require).any_number_of_times
|
16
|
+
|
17
|
+
described_class.setup
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'skips injection if ActionController::Base is not defined' do
|
21
|
+
stub_const("Rails", Class.new)
|
22
|
+
described_class.should_not_receive(:require).any_number_of_times
|
23
|
+
|
24
|
+
described_class.setup
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
describe Authoryze do
|
2
|
+
|
3
|
+
describe '.configure' do
|
4
|
+
it 'yields configuration if block given' do
|
5
|
+
configuration = double
|
6
|
+
described_class.stub(:configuration => configuration)
|
7
|
+
described_class.should_receive(:configure).and_yield(configuration)
|
8
|
+
described_class.configure {|c| }
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'raises an error if block not given' do
|
12
|
+
expect{
|
13
|
+
described_class.configure
|
14
|
+
}.to raise_error ArgumentError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.configuration' do
|
19
|
+
before :each do
|
20
|
+
Authoryze.reset!
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns a new configuration object' do
|
24
|
+
Authoryze::Configuration.should_receive(:new).and_call_original
|
25
|
+
described_class.configuration.should be_an_instance_of Authoryze::Configuration
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns memoized version' do
|
29
|
+
configuration = described_class.configuration
|
30
|
+
described_class.configuration.should == configuration
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#can', :pending => true do
|
35
|
+
it 'returns true if user has permission' do
|
36
|
+
role = Role.create :name => 'boss', :permissions => {'manage_peons?' => true}
|
37
|
+
user = create :user, :roles => [role]
|
38
|
+
subject.stub(:current_user => user)
|
39
|
+
subject.can.manage_peons?.should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises AccessDenied error if user does not have permission' do
|
43
|
+
role = Role.create :name => 'boss', :permissions => {'manage_peons?' => true}
|
44
|
+
user = create :user, :roles => [role]
|
45
|
+
subject.stub(:current_user => user)
|
46
|
+
subject.can.manage_big_boss?.should be_false
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns true for permissions from any of the roles' do
|
50
|
+
role = Role.create :name => 'boss', :permissions => {'manage_peons?' => true}
|
51
|
+
role2 = Role.create :name => 'boss2', :permissions => {'manage_underlings?' => true}
|
52
|
+
user = create :user, :roles => [role, role2]
|
53
|
+
subject.stub(:current_user => user)
|
54
|
+
subject.can.manage_peons?.should be_true
|
55
|
+
subject.can.manage_underlings?.should be_true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'authoryze'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authoryze
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maher Hawash
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-15 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: watchr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: debugger
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Provides matrix based and role level authorization
|
98
|
+
email:
|
99
|
+
- gmhawash@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .ruby-version
|
107
|
+
- .watchr
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- authoryze.gemspec
|
113
|
+
- lib/authoryze.rb
|
114
|
+
- lib/authoryze/configuration.rb
|
115
|
+
- lib/authoryze/exceptions.rb
|
116
|
+
- lib/authoryze/rails.rb
|
117
|
+
- lib/authoryze/rails/authoryze_filter.rb
|
118
|
+
- lib/authoryze/rails/can_filter.rb
|
119
|
+
- lib/authoryze/rails/controller_extensions.rb
|
120
|
+
- lib/authoryze/rails/filter.rb
|
121
|
+
- lib/authoryze/version.rb
|
122
|
+
- spec/authorize/configuration_spec.rb
|
123
|
+
- spec/authorize/rails_spec.rb
|
124
|
+
- spec/authoryze_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
homepage: ''
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.0.6
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: matrix based and role level authorization
|
150
|
+
test_files:
|
151
|
+
- spec/authorize/configuration_spec.rb
|
152
|
+
- spec/authorize/rails_spec.rb
|
153
|
+
- spec/authoryze_spec.rb
|
154
|
+
- spec/spec_helper.rb
|