strong_actions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f93205c2a7b9928cbdfbe0e8b9ab217254cf86f
4
+ data.tar.gz: 02d4f14737a759c25b5e8424bad16e5c9498af90
5
+ SHA512:
6
+ metadata.gz: 92d12e0cb73f7ccea5675c3488354ef2fb14da5f94070959441456d5c48f0f67383c0b038e06b6c5182bdda34ac27c422eb0daaa7241a41fdbbb97eb01898903
7
+ data.tar.gz: e2a6e0f4fd72779022400def4e9d19b52a4a4762ddb607ae2c935fd2778601f3155c254046ebe22fed6ee5e89ac3c7ad4e8d567f0e4031ffcc4b83f2221ae84f
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ # Eclipse
37
+ /.project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in strong_actions.gemspec
4
+ gemspec
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ strong_actions (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.3.2)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.6)
16
+ rake
17
+ strong_actions!
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 hybitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ichy
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.
@@ -0,0 +1,29 @@
1
+ # StrongActions
2
+
3
+ Access control for rails controller/action.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'strong_actions'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install strong_actions
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/strong_actions/fork )
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 a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ require "strong_actions/version"
2
+ require "strong_actions/config"
3
+ require "strong_actions/forbidden_action"
4
+ require 'strong_actions/controller_extentions'
5
+
6
+ module StrongActions
7
+
8
+ def self.config
9
+ StrongActions::Config.instance
10
+ end
11
+
12
+ def self.config_files
13
+ config.config_files
14
+ end
15
+
16
+ def self.config_files=(files)
17
+ config.config_files = files
18
+ end
19
+
20
+ end
21
+
22
+ require 'strong_actions/railtie' if defined?(Rails)
@@ -0,0 +1,45 @@
1
+ require 'singleton'
2
+
3
+ module StrongActions
4
+ class Config
5
+ include Singleton
6
+
7
+ def initialize
8
+ @config_files = ['config/acl.yml']
9
+ load_config_files
10
+ end
11
+
12
+ def config_files
13
+ @config_files
14
+ end
15
+
16
+ def config_files=(files)
17
+ config_files = files
18
+ load_config_files
19
+ end
20
+
21
+ def roles
22
+ load_config_files if Rails.env.development?
23
+ @acl.keys
24
+ end
25
+
26
+ def role_definition(role)
27
+ load_config_files if Rails.env.development?
28
+ @acl[role]
29
+ end
30
+
31
+ private
32
+
33
+ def load_config_files
34
+ @acl = {}
35
+ config_files.each do |config_file|
36
+ yml = YAML.load_file(config_file)
37
+ yml.each do |role, values|
38
+ raise "role #{role} is already defined." if @acl.has_key?(role)
39
+ @acl[role] = values
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,61 @@
1
+ module StrongActions
2
+ module ControllerExtentions
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :authorize_roles!
7
+ helper_method :available?
8
+ end
9
+
10
+ private
11
+
12
+ def authorize_roles!
13
+ StrongActions.config.roles.each do |role|
14
+ unless judge(role, controller_name, action_name, params)
15
+ message = "#{controller_name.capitalize}Controller##{action_name} is not permitted for role #{role}"
16
+ raise StrongActions::ForbiddenAction.new(message)
17
+ end
18
+ end
19
+ end
20
+
21
+ def available?(controller_name, action_name = nil, params = {})
22
+ action_name ||= 'index'
23
+
24
+ StrongActions.config.roles.each do |role|
25
+ return false unless judge(role, controller_name, action_name, params)
26
+ end
27
+
28
+ true
29
+ end
30
+
31
+ def judge(role, controller_name, action_name, params)
32
+ role_definition = StrongActions.config.role_definition(role)
33
+ return true unless role_definition
34
+
35
+ begin
36
+ role_object = eval(role)
37
+ rescue NameError
38
+ raise "role #{role} is not defined in controller"
39
+ end
40
+
41
+ controller_value = role_definition[controller_name]
42
+ return true if controller_value.nil?
43
+
44
+ if controller_value.is_a?(Hash)
45
+ action_value = controller_value[action_name]
46
+ else
47
+ action_value = controller_value
48
+ end
49
+ return true if action_value.nil?
50
+
51
+ action_value = [action_value] unless action_value.is_a?(Array)
52
+ action_value.each do |definition|
53
+ return false unless definition
54
+ return false unless role_object.instance_eval(definition)
55
+ end
56
+
57
+ true
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ module StrongActions
2
+
3
+ class ForbiddenAction < StandardError
4
+ end
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ module StrongActions
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ initializer 'strong_actions' do
5
+ ActiveSupport.on_load :action_controller do
6
+ include StrongActions::ControllerExtentions
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module StrongActions
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'strong_actions/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "strong_actions"
7
+ spec.version = StrongActions::VERSION
8
+ spec.authors = ["ichy"]
9
+ spec.email = ["ichylinux@gmail.com"]
10
+ spec.summary = %q{access control for rails controller/action}
11
+ spec.description = %q{access control for rails controller/action}
12
+ spec.homepage = "https://github.com/hybitz/strong_actions"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strong_actions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ichy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-31 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ description: access control for rails controller/action
42
+ email:
43
+ - ichylinux@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/strong_actions.rb
56
+ - lib/strong_actions/config.rb
57
+ - lib/strong_actions/controller_extentions.rb
58
+ - lib/strong_actions/forbidden_action.rb
59
+ - lib/strong_actions/railtie.rb
60
+ - lib/strong_actions/version.rb
61
+ - strong_actions.gemspec
62
+ homepage: https://github.com/hybitz/strong_actions
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: access control for rails controller/action
86
+ test_files: []