flexible_accessibility 0.1.1.pre

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.7.3)
11
+ rake (0.9.2.2)
12
+ rcov (1.0.0)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+ shoulda (3.0.1)
16
+ shoulda-context (~> 1.0.0)
17
+ shoulda-matchers (~> 1.0.0)
18
+ shoulda-context (1.0.0)
19
+ shoulda-matchers (1.0.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.8.3)
27
+ rcov
28
+ rdoc (~> 3.12)
29
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Sergey Awanesov
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/README.md ADDED
@@ -0,0 +1,2 @@
1
+ flexible_accessibility
2
+ ======================
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = flexible_accessibility
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to flexible_accessibility
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Sergey Awanesov. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "flexible_accessibility"
18
+ gem.version = "0.1.1.pre"
19
+ gem.homepage = "http://github.com/mochnatiy/flexible_accessibility"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Flexible access control system}
22
+ gem.description = %Q{Flexible access control system for your rails application. Based on analysis of controller actions}
23
+ gem.email = "sergey.awanesov@gmail.com"
24
+ gem.authors = ["Sergey Awanesov"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rdoc/task'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "flexible_accessibility #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "flexible_accessibility"
8
+ s.version = "0.1.1.pre"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sergey Awanesov"]
12
+ s.date = "2012-07-01"
13
+ s.description = "Flexible access control system for your rails application. Based on analysis of controller actions"
14
+ s.email = "sergey.awanesov@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "flexible_accessibility.gemspec",
29
+ "init.rb",
30
+ "lib/flexible_accessibility.rb",
31
+ "lib/flexible_accessibility/controller_methods.rb",
32
+ "lib/flexible_accessibility/exceptions.rb",
33
+ "lib/generators/flexible_accessibility/permission/permission_generator.rb",
34
+ "lib/generators/flexible_accessibility/permission/templates/create_permissions.rb",
35
+ "lib/generators/flexible_accessibility/permission/templates/permission.rb",
36
+ "test/helper.rb",
37
+ "test/test_flexible_accessibility.rb"
38
+ ]
39
+ s.homepage = "http://github.com/mochnatiy/flexible_accessibility"
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = "1.8.24"
43
+ s.summary = "Flexible access control system"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ end
68
+ end
69
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'flexible_accessibility'
@@ -0,0 +1,46 @@
1
+ module FlexibleAccessibility
2
+ module ControllerMethods
3
+ module ClassMethods
4
+ before_filter :check_access_to_resource
5
+ before_filter :check_if_authorized
6
+
7
+ def skip_authorization_on_resource
8
+ @authorized = true
9
+ end
10
+
11
+ def authorize actions=[]
12
+ @actions = actions
13
+ end
14
+
15
+ def current_action
16
+ path = ActionController::Routing::Routes.recognize_path request.env["PATH_INFO"]
17
+ @fa_path = [path[:controller], path[:action]]
18
+ end
19
+
20
+ def check_access_to_resource
21
+ if @actions.include current_action[1].to_sym
22
+ @authorized = true unless Permission.check_access "#{current_action[0]}##{current_action[1]}", current_action
23
+ end
24
+ end
25
+
26
+ def check_if_authorized
27
+ raise FlexibleAccessibility::AccessDeniedException unless @authorized
28
+ end
29
+
30
+ def has_access? controller, action
31
+ Permission.check_access "#{controller}##{action}", current_action
32
+ end
33
+ end
34
+
35
+ def self.included base
36
+ base.extend ClassMethods
37
+ base.helper_method has_access?
38
+ end
39
+ end
40
+ end
41
+
42
+ if defined? ApplicationController
43
+ ApplicationController.class_eval do
44
+ include FlexibleAccessibility::ControllerMethods
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ module FlexibleAccessibilty
2
+ class AccessDeniedException < Error
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('errors.access_denied')
11
+ end
12
+
13
+ def to_s
14
+ @message || @default_message
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ require 'flexible_accessibility/controller_methods.rb'
2
+ require 'flexible_accessibility/exceptions.rb'
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,15 @@
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
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'flexible_accessibility'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFlexibleAccessibility < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flexible_accessibility
3
+ version: !ruby/object:Gem::Version
4
+ hash: 961915976
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ - pre
11
+ version: 0.1.1.pre
12
+ platform: ruby
13
+ authors:
14
+ - Sergey Awanesov
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-07-01 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ version_requirements: *id001
33
+ name: shoulda
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 31
43
+ segments:
44
+ - 3
45
+ - 12
46
+ version: "3.12"
47
+ version_requirements: *id002
48
+ name: rdoc
49
+ prerelease: false
50
+ - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 23
58
+ segments:
59
+ - 1
60
+ - 0
61
+ - 0
62
+ version: 1.0.0
63
+ version_requirements: *id003
64
+ name: bundler
65
+ prerelease: false
66
+ - !ruby/object:Gem::Dependency
67
+ type: :development
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 49
74
+ segments:
75
+ - 1
76
+ - 8
77
+ - 3
78
+ version: 1.8.3
79
+ version_requirements: *id004
80
+ name: jeweler
81
+ prerelease: false
82
+ - !ruby/object:Gem::Dependency
83
+ type: :development
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ version_requirements: *id005
94
+ name: rcov
95
+ prerelease: false
96
+ description: Flexible access control system for your rails application. Based on analysis of controller actions
97
+ email: sergey.awanesov@gmail.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.md
105
+ - README.rdoc
106
+ files:
107
+ - .rvmrc
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - README.rdoc
113
+ - Rakefile
114
+ - flexible_accessibility.gemspec
115
+ - init.rb
116
+ - lib/flexible_accessibility.rb
117
+ - lib/flexible_accessibility/controller_methods.rb
118
+ - lib/flexible_accessibility/exceptions.rb
119
+ - lib/generators/flexible_accessibility/permission/permission_generator.rb
120
+ - lib/generators/flexible_accessibility/permission/templates/create_permissions.rb
121
+ - lib/generators/flexible_accessibility/permission/templates/permission.rb
122
+ - test/helper.rb
123
+ - test/test_flexible_accessibility.rb
124
+ homepage: http://github.com/mochnatiy/flexible_accessibility
125
+ licenses:
126
+ - MIT
127
+ post_install_message:
128
+ rdoc_options: []
129
+
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">"
145
+ - !ruby/object:Gem::Version
146
+ hash: 25
147
+ segments:
148
+ - 1
149
+ - 3
150
+ - 1
151
+ version: 1.3.1
152
+ requirements: []
153
+
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.24
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: Flexible access control system
159
+ test_files: []
160
+