flexible_accessibility 0.1.2.pre → 0.1.3.pre
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.
- data/Rakefile +1 -2
- data/flexible_accessibility.gemspec +3 -5
- data/lib/flexible_accessibility/controller_methods.rb +32 -21
- data/lib/flexible_accessibility/permissions.rb +20 -0
- data/lib/flexible_accessibility.rb +2 -1
- metadata +5 -7
- data/lib/generators/flexible_accessibility/permission/permission_generator.rb +0 -12
- data/lib/generators/flexible_accessibility/permission/templates/create_permissions.rb +0 -15
- data/lib/generators/flexible_accessibility/permission/templates/permission.rb +0 -15
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ require 'jeweler'
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
17
|
gem.name = "flexible_accessibility"
|
18
|
-
gem.version = "0.1.
|
18
|
+
gem.version = "0.1.3.pre"
|
19
19
|
gem.homepage = "http://github.com/mochnatiy/flexible_accessibility"
|
20
20
|
gem.license = "MIT"
|
21
21
|
gem.summary = %Q{Flexible access control system}
|
@@ -46,7 +46,6 @@ task :default => :test
|
|
46
46
|
require 'rdoc/task'
|
47
47
|
Rake::RDocTask.new do |rdoc|
|
48
48
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
-
|
50
49
|
rdoc.rdoc_dir = 'rdoc'
|
51
50
|
rdoc.title = "flexible_accessibility #{version}"
|
52
51
|
rdoc.rdoc_files.include('README*')
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "flexible_accessibility"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3.pre"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sergey Awanesov"]
|
12
|
-
s.date = "2012-07-
|
12
|
+
s.date = "2012-07-16"
|
13
13
|
s.description = "Flexible access control system for your rails application. Based on analysis of controller actions"
|
14
14
|
s.email = "sergey.awanesov@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,9 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/flexible_accessibility.rb",
|
31
31
|
"lib/flexible_accessibility/controller_methods.rb",
|
32
32
|
"lib/flexible_accessibility/exceptions.rb",
|
33
|
-
"lib/
|
34
|
-
"lib/generators/flexible_accessibility/permission/templates/create_permissions.rb",
|
35
|
-
"lib/generators/flexible_accessibility/permission/templates/permission.rb",
|
33
|
+
"lib/flexible_accessibility/permissions.rb",
|
36
34
|
"test/helper.rb",
|
37
35
|
"test/test_flexible_accessibility.rb"
|
38
36
|
]
|
@@ -2,45 +2,56 @@ module FlexibleAccessibility
|
|
2
2
|
module ControllerMethods
|
3
3
|
module ClassMethods
|
4
4
|
|
5
|
-
#
|
6
|
-
def
|
7
|
-
|
5
|
+
# Macro for skip authorization
|
6
|
+
def skip_authorization_here
|
7
|
+
self.instance_variable_set :@route_permitted, true
|
8
|
+
self.send :before_filter, :check_if_route_permitted
|
8
9
|
end
|
9
10
|
|
10
|
-
#
|
11
|
-
def authorize
|
12
|
-
self.send :before_filter, :
|
11
|
+
# Macro for define authorization
|
12
|
+
def authorize args={}
|
13
|
+
self.send :before_filter, :check_permission_to_route
|
14
|
+
self.send :before_filter, :check_if_route_permitted
|
15
|
+
set_actions_to_authorize *args
|
13
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
#
|
20
|
+
def set_actions_to_authorize args={}
|
21
|
+
self.instance_variable_set :@checkable_routes, args[:only] unless args[:only].nil?
|
22
|
+
self.instance_variable_set :@checkable_routes, self.action_methods - args[:except] unless args[:except].nil?
|
23
|
+
end
|
14
24
|
|
15
25
|
#
|
16
|
-
def
|
26
|
+
def current_route
|
17
27
|
path = ActionController::Routing::Routes.recognize_path request.env["PATH_INFO"]
|
18
|
-
|
28
|
+
[path[:controller], path[:action]]
|
19
29
|
end
|
20
30
|
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
31
|
+
# We checks access to route
|
32
|
+
# And we expected the existing of current_user helper
|
33
|
+
def check_permission_to_route
|
34
|
+
if self.instance_variable_get(:@checkable_routes).include? current_route[1].to_sym
|
35
|
+
self.instance_variable_set(:@route_permitted, true) unless Permissions.is_action_permitted_for_user? "#{current_route[0]}##{current_route[1]}", current_user
|
25
36
|
end
|
26
37
|
end
|
27
38
|
|
28
|
-
#
|
29
|
-
def
|
30
|
-
raise FlexibleAccessibility::AccessDeniedException unless
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
def has_access? controller, action
|
35
|
-
Permission.check_access "#{controller}##{action}", current_action
|
39
|
+
# We checks @authorized variable state
|
40
|
+
def check_if_route_permitted
|
41
|
+
raise FlexibleAccessibility::AccessDeniedException unless self.instance_variable_get :@route_permitted
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
39
|
-
#
|
45
|
+
# Callback needs for include methods and define helper method
|
40
46
|
def self.included base
|
41
47
|
base.extend ClassMethods
|
42
48
|
base.helper_method has_access?
|
43
49
|
end
|
50
|
+
|
51
|
+
# We checks url for each link in view to show it
|
52
|
+
def has_access? controller, action
|
53
|
+
Permissions.is_action_permitted_for_user? "#{controller}##{action}", current_user
|
54
|
+
end
|
44
55
|
end
|
45
56
|
end
|
46
57
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FlexibleAccessibility
|
2
|
+
class Permissions
|
3
|
+
class << self
|
4
|
+
def get_permissions
|
5
|
+
permissions = {}
|
6
|
+
ApplicationController.subclasses.each do |klass|
|
7
|
+
permissions[klass.to_s.tableize.singularize.to_sym] = klass.constantize.new.instance_variable_get(:@checkable_routes).collect{ |a| a.to_s }.join(', ')
|
8
|
+
end
|
9
|
+
permissions
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_action_permitted? action
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_action_permitted_for_user? action, user
|
16
|
+
!self.where(["action = ? and user_id = ?", action, user.id]).empty?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexible_accessibility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 961915968
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
9
|
+
- 3
|
10
10
|
- pre
|
11
|
-
version: 0.1.
|
11
|
+
version: 0.1.3.pre
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Sergey Awanesov
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-07-
|
19
|
+
date: 2012-07-16 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
type: :development
|
@@ -116,9 +116,7 @@ files:
|
|
116
116
|
- lib/flexible_accessibility.rb
|
117
117
|
- lib/flexible_accessibility/controller_methods.rb
|
118
118
|
- lib/flexible_accessibility/exceptions.rb
|
119
|
-
- lib/
|
120
|
-
- lib/generators/flexible_accessibility/permission/templates/create_permissions.rb
|
121
|
-
- lib/generators/flexible_accessibility/permission/templates/permission.rb
|
119
|
+
- lib/flexible_accessibility/permissions.rb
|
122
120
|
- test/helper.rb
|
123
121
|
- test/test_flexible_accessibility.rb
|
124
122
|
homepage: http://github.com/mochnatiy/flexible_accessibility
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module FlexibleAccessibilty
|
2
|
-
module Generators
|
3
|
-
class PermissionGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
|
6
|
-
def generate_ability
|
7
|
-
copy_file "permission.rb", "app/models/permission.rb"
|
8
|
-
copy_file "create_permissions.rb", "db/migrate/create_permissions.rb"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class CreatePermissions < ActiveRecord::Migration
|
2
|
-
def up
|
3
|
-
create_table :permissions do |t|
|
4
|
-
t.string :action, :null => false
|
5
|
-
t.integer :user_id, :null => false
|
6
|
-
t.timestamps
|
7
|
-
end
|
8
|
-
|
9
|
-
add_index :permissions, :user_id
|
10
|
-
end
|
11
|
-
|
12
|
-
def down
|
13
|
-
drop_table :permissions
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class Permission < ActiveRecord::Base
|
2
|
-
|
3
|
-
class << self
|
4
|
-
def get_permissions
|
5
|
-
permissions = {}
|
6
|
-
ApplicationController.subclasses.each do |klass|
|
7
|
-
permissions[klass.to_s.tableize.singularize.to_sym] = klass.constantize.action_methods.collect{ |a| a.to_s }.join(', ')
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def check_access action, user
|
12
|
-
!self.where(["action = ? and user_id = ?", action, user.id]).empty?
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|