permitted 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +13 -0
- data/lib/permitted.rb +7 -0
- data/lib/permitted/ability.rb +17 -0
- data/lib/permitted/access_denied.rb +4 -0
- data/lib/permitted/action_controller.rb +11 -0
- data/lib/permitted/railtie.rb +9 -0
- data/lib/permitted/version.rb +3 -0
- data/permitted.gemspec +21 -0
- data/test/ability_test.rb +24 -0
- data/test/action_controller_test.rb +19 -0
- data/test/support/application.rb +7 -0
- data/test/support/controllers.rb +4 -0
- data/test/support/models.rb +7 -0
- data/test/test_helper.rb +8 -0
- metadata +88 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Gabriel Sobrinho
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
desc 'Default: run unit tests.'
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
desc 'Test the permitted plugin.'
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
end
|
data/lib/permitted.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Permitted
|
2
|
+
class Ability
|
3
|
+
def initialize(user)
|
4
|
+
@user = user
|
5
|
+
end
|
6
|
+
|
7
|
+
def permit!(action, subject)
|
8
|
+
raise AccessDenied unless permitted_to?(action, subject)
|
9
|
+
end
|
10
|
+
|
11
|
+
def permitted_to?(action, subject)
|
12
|
+
@user.roles.any? do |role|
|
13
|
+
role.subject.to_s == subject.to_s && role.action.to_s == action.to_s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/permitted.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "permitted/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "permitted"
|
7
|
+
s.version = Permitted::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Gabriel Sobrinho"]
|
10
|
+
s.email = ["gabriel.sobrinho@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/sobrinho/permitted"
|
12
|
+
s.summary = %q{Authorization for ruby apps using roles concept}
|
13
|
+
s.description = %q{Authorization for ruby apps using roles concept}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency %q{railties}, [">= 3.0.0"]
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AbilityTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@role = Role.new(:action => 'read', :subject => 'users')
|
6
|
+
@user = User.new(:name => 'sobrinho', :roles => [@role])
|
7
|
+
@ability = Permitted::Ability.new(@user)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_permitted_to
|
11
|
+
assert @ability.permitted_to?(:read, :users)
|
12
|
+
assert !@ability.permitted_to?(:read, :profiles)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_permit
|
16
|
+
assert_nothing_raised do
|
17
|
+
@ability.permit!(:read, :users)
|
18
|
+
end
|
19
|
+
|
20
|
+
assert_raise Permitted::AccessDenied do
|
21
|
+
@ability.permit!(:read, :profiles)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActionControllerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@controller = UsersController.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_current_ability
|
9
|
+
assert @controller.respond_to?(:current_ability)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_permitted_to
|
13
|
+
assert @controller.respond_to?(:permitted_to?)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_permit
|
17
|
+
assert @controller.respond_to?(:permit!)
|
18
|
+
end
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: permitted
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabriel Sobrinho
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-05 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: railties
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.0.0
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Authorization for ruby apps using roles concept
|
28
|
+
email:
|
29
|
+
- gabriel.sobrinho@gmail.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- MIT-LICENSE
|
40
|
+
- Rakefile
|
41
|
+
- lib/permitted.rb
|
42
|
+
- lib/permitted/ability.rb
|
43
|
+
- lib/permitted/access_denied.rb
|
44
|
+
- lib/permitted/action_controller.rb
|
45
|
+
- lib/permitted/railtie.rb
|
46
|
+
- lib/permitted/version.rb
|
47
|
+
- permitted.gemspec
|
48
|
+
- test/ability_test.rb
|
49
|
+
- test/action_controller_test.rb
|
50
|
+
- test/support/application.rb
|
51
|
+
- test/support/controllers.rb
|
52
|
+
- test/support/models.rb
|
53
|
+
- test/test_helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: https://github.com/sobrinho/permitted
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.5.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Authorization for ruby apps using roles concept
|
82
|
+
test_files:
|
83
|
+
- test/ability_test.rb
|
84
|
+
- test/action_controller_test.rb
|
85
|
+
- test/support/application.rb
|
86
|
+
- test/support/controllers.rb
|
87
|
+
- test/support/models.rb
|
88
|
+
- test/test_helper.rb
|