flexible_accessibility 0.2.4.pre → 0.2.6.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
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.2.
|
18
|
+
gem.version = "0.2.6.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}
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "flexible_accessibility"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.6.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-
|
12
|
+
s.date = "2012-09-03"
|
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 = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/flexible_accessibility/exceptions.rb",
|
33
33
|
"lib/flexible_accessibility/filters.rb",
|
34
34
|
"lib/flexible_accessibility/permission.rb",
|
35
|
+
"lib/flexible_accessibility/resource.rb",
|
35
36
|
"lib/flexible_accessibility/utils.rb",
|
36
37
|
"test/helper.rb",
|
37
38
|
"test/test_flexible_accessibility.rb"
|
@@ -9,23 +9,26 @@ module FlexibleAccessibility
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class << self
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def all
|
13
|
+
permissions = []
|
14
|
+
Utils.new.get_controllers.each do |scope|
|
15
|
+
namespace = scope.first
|
16
|
+
(scope - namespace.to_a).each do |klass|
|
17
|
+
klass = "#{namespace}::#{klass}" unless namespace == "default"
|
18
|
+
permissions << Permission.new(:controller => klass.gsub(/_controller/, "").to_sym, :actions => ApplicationResource.new(klass).klass.instance_variable_get(:@_checkable_routes))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
permissions
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
+
def is_action_permitted? permission
|
25
|
+
self.is_action_permitted_for_user? permission, current_user
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def is_action_permitted_for_user? permission, user
|
29
|
+
# TODO: Avoid these code, maybe handle a callback included in application
|
30
|
+
!AccessRule.where(["permission = ? and user_id = ?", permission, user.id]).empty?
|
31
|
+
end
|
32
|
+
end
|
30
33
|
end
|
31
34
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FlexibleAccessibility
|
2
|
+
class ApplicationResource
|
3
|
+
attr_reader :class
|
4
|
+
attr_reader :namespace
|
5
|
+
|
6
|
+
def initialize resource_string
|
7
|
+
@class = resource_string.split("::").last
|
8
|
+
@namespace = resource_string.split("::").first
|
9
|
+
end
|
10
|
+
|
11
|
+
def klass
|
12
|
+
(@namespace.camelize + "::" + @class.camelize).constantize
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -9,6 +9,7 @@ module FlexibleAccessibility
|
|
9
9
|
get_controllers_recursive @path
|
10
10
|
end
|
11
11
|
|
12
|
+
# All controller clases placed in :default scope
|
12
13
|
def get_controllers_recursive path
|
13
14
|
(Dir.new(path).entries - ["..", "."]).each do |entry|
|
14
15
|
if File.directory? path + entry
|
@@ -16,6 +17,7 @@ module FlexibleAccessibility
|
|
16
17
|
else
|
17
18
|
parent_directory = File.dirname(path + entry).split(/\//).last
|
18
19
|
container = parent_directory == "controllers" ? "default" : parent_directory
|
20
|
+
@controllers[container.to_sym] = [] unless @controllers.has_key? container.to_sym
|
19
21
|
@controllers[container.to_sym] << File.basename(path + entry, ".*") unless File.basename(path + entry, ".*") == "application_controller"
|
20
22
|
end
|
21
23
|
end
|
@@ -2,4 +2,5 @@ require 'flexible_accessibility/controller_methods.rb'
|
|
2
2
|
require 'flexible_accessibility/exceptions.rb'
|
3
3
|
require 'flexible_accessibility/permission.rb'
|
4
4
|
require 'flexible_accessibility/filters.rb'
|
5
|
+
require 'flexible_accessibility/resource.rb'
|
5
6
|
require 'flexible_accessibility/utils.rb'
|
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: -2053399853
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
9
|
+
- 6
|
10
10
|
- pre
|
11
|
-
version: 0.2.
|
11
|
+
version: 0.2.6.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-
|
19
|
+
date: 2012-09-03 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/flexible_accessibility/exceptions.rb
|
119
119
|
- lib/flexible_accessibility/filters.rb
|
120
120
|
- lib/flexible_accessibility/permission.rb
|
121
|
+
- lib/flexible_accessibility/resource.rb
|
121
122
|
- lib/flexible_accessibility/utils.rb
|
122
123
|
- test/helper.rb
|
123
124
|
- test/test_flexible_accessibility.rb
|