flexible_accessibility 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flexible_accessibility (0.3.1)
4
+ flexible_accessibility (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -8,7 +8,7 @@ Installation:
8
8
 
9
9
  or add to your Gemfile
10
10
 
11
- gem "flexible_accessibility", "~> 0.3.0"
11
+ gem 'flexible_accessibility', '0.3.2'
12
12
 
13
13
  Do
14
14
 
@@ -19,6 +19,6 @@ Installation:
19
19
  ======================
20
20
 
21
21
  ## Copyright
22
- Copyright (c) 2012-2013 Sergey Awanesov and 7 Pikes, Inc.
22
+ Copyright (c) 2012-2013 Sergey Avanesov and 7 Pikes, Inc.
23
23
 
24
24
  ![7pikes logo](https://github.com/7Pikes/flexible_accessibility/wiki/Logo.png)
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  Bundler.setup(:default, :development)
8
8
  rescue Bundler::BundlerError => e
9
9
  $stderr.puts e.message
10
- $stderr.puts "Run `bundle install` to install missing gems"
10
+ $stderr.puts 'Run `bundle install` to install missing gems'
11
11
  exit e.status_code
12
12
  end
13
13
 
@@ -21,7 +21,7 @@ end
21
21
 
22
22
  require 'rdoc/task'
23
23
  Rake::RDocTask.new do |rdoc|
24
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
24
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
25
25
  rdoc.rdoc_dir = 'rdoc'
26
26
  rdoc.title = "flexible_accessibility #{version}"
27
27
  rdoc.rdoc_files.include('README*')
@@ -1,22 +1,22 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = "flexible_accessibility"
5
- s.version = "0.3.1"
6
- s.authors = ["Sergey Awanesov"]
7
- s.date = "2013-09-30"
8
- s.summary = "Flexible access control system"
9
- s.description = "Flexible access control system for your rails application. Based on analysis of controller actions"
10
- s.email = "sergey.awanesov@gmail.com"
11
- s.homepage = "http://github.com/mochnatiy/flexible_accessibility"
12
- s.licenses = ["MIT"]
13
- s.require_paths = ["lib"]
4
+ s.name = 'flexible_accessibility'
5
+ s.version = '0.3.2'
6
+ s.authors = ['Sergey Avanesov']
7
+ s.date = '2013-09-30'
8
+ s.summary = 'Flexible access control system'
9
+ s.description = 'Flexible access control system for your rails application. Based on analysis of controller actions'
10
+ s.email = 'sergey.awanesov@gmail.com'
11
+ s.homepage = 'http://github.com/mochnatiy/flexible_accessibility'
12
+ s.licenses = ['MIT']
13
+ s.require_paths = ['lib']
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
 
18
18
  s.rubygems_version = "1.8.24"
19
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
19
+ s.required_rubygems_version = Gem::Requirement.new('> 1.3.1') if s.respond_to? :required_rubygems_version=
20
20
 
21
21
  s.add_development_dependency 'i18n'
22
22
  s.add_development_dependency 'rdoc'
@@ -3,7 +3,7 @@ module FlexibleAccessibility
3
3
  class << self
4
4
  def preload_permissions(user)
5
5
  if user.instance_variable_get(:@_available_permissions).nil?
6
- user.instance_variable_set(:@_available_permissions, AccessRule.where(:owner => user.id).map(&:permission))
6
+ user.instance_variable_set(:@_available_permissions, AccessRule.where(:owner_id => user.id).map(&:permission))
7
7
  end
8
8
  end
9
9
 
@@ -2,11 +2,16 @@ module FlexibleAccessibility
2
2
  module ControllerMethods
3
3
  module ClassMethods
4
4
 
5
+ # Compatibility with previous versions
6
+ def skip_authorization_here
7
+ not_authorize :all
8
+ end
9
+
5
10
  # Macro for define actions without authorization
6
- def skip_authorization(args={})
11
+ def not_authorize(args={})
7
12
  valid_arguments = parse_and_validate_arguments(args)
8
13
  self.instance_variable_set(:@_non_verifiable_routes, self.action_methods) if valid_arguments[:all]
9
- self.instance_variable_set(:@_non_verifiable_routes, valid_arguments[:on]) unless valid_arguments[:on].nil?
14
+ self.instance_variable_set(:@_non_verifiable_routes, valid_arguments[:only]) unless valid_arguments[:only].nil?
10
15
  self.instance_variable_set(:@_verifiable_routes, []) if self.instance_variable_get(:@_non_verifiable_routes).nil?
11
16
  end
12
17
 
@@ -17,15 +22,14 @@ module FlexibleAccessibility
17
22
  self.instance_variable_set(:@_verifiable_routes, self.action_methods - valid_arguments[:except]) unless valid_arguments[:except].nil?
18
23
  self.instance_variable_set(:@_verifiable_routes, self.action_methods) if valid_arguments[:all]
19
24
  self.instance_variable_set(:@_non_verifiable_routes, []) if self.instance_variable_get(:@_non_verifiable_routes).nil?
20
- # TODO: get info from routes
21
25
  end
22
26
 
23
27
  private
24
28
  # Parse arguments from macro calls
25
29
  def parse_and_validate_arguments(args={})
26
30
  result = {}
27
- (result[:all] = true) and return result if args.to_s == "all" || args.to_s == "everywhere"
28
- [:on, :only, :except].each do |key|
31
+ (result[:all] = true) and return result if args.to_s == 'all'
32
+ [:only, :except].each do |key|
29
33
  unless args[key].nil?
30
34
  raise ActionsValueException unless args[key].instance_of?(Array)
31
35
  result[key] = args[key].map!{ |v| v.to_s }.to_set
@@ -17,7 +17,7 @@ module FlexibleAccessibility
17
17
  end
18
18
 
19
19
  def default_message
20
- "An exception is occured"
20
+ 'An exception is occurred'
21
21
  end
22
22
  end
23
23
 
@@ -28,7 +28,7 @@ module FlexibleAccessibility
28
28
  end
29
29
 
30
30
  def default_message
31
- "The acess for resoure #{@action} is denied"
31
+ "The access for resource #{@action} is denied"
32
32
  end
33
33
  end
34
34
 
@@ -39,7 +39,7 @@ module FlexibleAccessibility
39
39
  end
40
40
 
41
41
  def default_message
42
- "Current user is not logged in"
42
+ 'Current user is not logged in'
43
43
  end
44
44
  end
45
45
 
@@ -50,7 +50,7 @@ module FlexibleAccessibility
50
50
  end
51
51
 
52
52
  def default_message
53
- "No way to detect a logged user - may you have forgot to define a current_user helper"
53
+ 'No way to detect a logged user - may you have forgot to define a current_user helper'
54
54
  end
55
55
  end
56
56
 
@@ -61,7 +61,7 @@ module FlexibleAccessibility
61
61
  end
62
62
 
63
63
  def default_message
64
- "Probably you have forgot to send a user in has_access?"
64
+ 'Probably you have forgot to send a user in has_access?'
65
65
  end
66
66
  end
67
67
 
@@ -72,7 +72,7 @@ module FlexibleAccessibility
72
72
  end
73
73
 
74
74
  def default_message
75
- "The value of any 'authorize' macro argument should be declared as Array"
75
+ 'The value of any \'authorize\' macro argument should be declared as Array'
76
76
  end
77
77
  end
78
78
  end
@@ -31,7 +31,7 @@ module FlexibleAccessibility
31
31
 
32
32
  # Check access to route and we expected the existing of current_user helper
33
33
  def check_permission_to_route
34
- if self.class.instance_variable_get(:@_verifiable_routes).include? current_action
34
+ if self.class.instance_variable_get(:@_verifiable_routes).include?(current_action)
35
35
  raise UserNotLoggedInException.new(current_route, nil) if logged_user.nil?
36
36
  self.class.instance_variable_set(:@_route_permitted, AccessProvider.is_action_permitted_for_user?(current_route, logged_user))
37
37
  elsif self.class.instance_variable_get(:@_non_verifiable_routes).include? current_action
@@ -39,7 +39,15 @@ module FlexibleAccessibility
39
39
  else
40
40
  self.class.instance_variable_set(:@_route_permitted, false)
41
41
  end
42
- end
42
+ end
43
+
44
+ def allow_route
45
+ self.class.instance_variable_set(:@_route_permitted, true)
46
+ end
47
+
48
+ def deny_route
49
+ self.class.instance_variable_set(:@_route_permitted, false)
50
+ end
43
51
 
44
52
  # Check the @authorized variable state
45
53
  def check_if_route_is_permitted
@@ -4,20 +4,20 @@ module FlexibleAccessibility
4
4
  attr_reader :namespace
5
5
 
6
6
  def initialize(resource_string)
7
- @controller = resource_string.split("/").last
8
- @namespace = resource_string.split("/").first == @controller ? "default" : resource_string.split("/").first
7
+ @controller = resource_string.split('/').last
8
+ @namespace = resource_string.split('/').first == @controller ? 'default' : resource_string.split('/').first
9
9
  end
10
10
 
11
11
  def klass
12
12
  if self.is_standard_resource?
13
13
  @controller.camelize.constantize
14
14
  else
15
- (@namespace.camelize + "::" + @controller.camelize).constantize
15
+ (@namespace.camelize + '::' + @controller.camelize).constantize
16
16
  end
17
17
  end
18
18
 
19
19
  def is_standard_resource?
20
- @namespace == "default"
20
+ @namespace == 'default'
21
21
  end
22
22
  end
23
23
  end
@@ -9,16 +9,16 @@ module FlexibleAccessibility
9
9
  get_controllers_recursive(@path)
10
10
  end
11
11
 
12
- # All controller clases placed in :default scope
12
+ # All controller classes placed in :default scope
13
13
  def get_controllers_recursive(path)
14
- (Dir.new(path).entries - ["..", "."]).each do |entry|
14
+ (Dir.new(path).entries - ['..', '.']).each do |entry|
15
15
  if File.directory?(path + entry)
16
16
  get_controllers_recursive(path + entry + '/')
17
17
  else
18
18
  parent_directory = File.dirname(path + entry).split(/\//).last
19
- container = parent_directory == "controllers" ? "default" : parent_directory
19
+ container = parent_directory == 'controllers' ? 'default' : parent_directory
20
20
  @controllers[container.to_sym] = [] unless @controllers.has_key? container.to_sym
21
- @controllers[container.to_sym] << File.basename(path + entry, ".*") unless File.basename(path + entry, ".*") == "application_controller"
21
+ @controllers[container.to_sym] << File.basename(path + entry, '.*') unless File.basename(path + entry, '.*') == 'application_controller'
22
22
  end
23
23
  end
24
24
  @controllers
@@ -5,19 +5,19 @@ module FlexibleAccessibility
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
6
  include Rails::Generators::Migration
7
7
  source_root File.expand_path('../templates', __FILE__)
8
- desc "Add the migrations"
8
+ desc 'Add the migrations'
9
9
 
10
10
  def self.next_migration_number(path)
11
- unless @prev_migration_nr
12
- @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
13
- else
11
+ if @prev_migration_nr
14
12
  @prev_migration_nr += 1
13
+ else
14
+ @prev_migration_nr = Time.now.utc.strftime('%Y%m%d%H%M%S').to_i
15
15
  end
16
16
  @prev_migration_nr.to_s
17
17
  end
18
18
 
19
19
  def copy_migrations
20
- migration_template "create_access_rules.rb", "db/migrate/create_access_rules.rb"
20
+ migration_template 'create_access_rules.rb', 'db/migrate/create_access_rules.rb'
21
21
  end
22
22
  end
23
23
  end
@@ -2,10 +2,10 @@ class CreateAccessRules < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :access_rules do |t|
4
4
  t.string :permission
5
- t.integer :owner
5
+ t.integer :owner_id
6
6
  t.timestamps
7
7
 
8
- t.index [:owner], :name => "access_rules_index_on_owner"
8
+ t.index [:owner_id], :name => 'access_rules_index_on_owner_id'
9
9
  end
10
10
  end
11
11
 
metadata CHANGED
@@ -2,10 +2,10 @@
2
2
  name: flexible_accessibility
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.1
5
+ version: 0.3.2
6
6
  platform: ruby
7
7
  authors:
8
- - Sergey Awanesov
8
+ - Sergey Avanesov
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []