right_on 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d604e3a0d52e8dd395888dce6b1d201138ea8b6
4
- data.tar.gz: 62d8d15da688d03422d5a31b3641a577f92ec42b
3
+ metadata.gz: 440d9cc6f2bd3abd809e3a57bb7c62e6086ba1c9
4
+ data.tar.gz: ca7322b951d1f21f126c055f4ca9c69540c0075f
5
5
  SHA512:
6
- metadata.gz: 59b6d8bbf60c6328bfc0753b622a05603d53362a762f47f490b1cf39cf8f083f4e0423616fdc28f99e088db2d77d16052e44f4ea8fc8f99daf71e990aab9b3b0
7
- data.tar.gz: 829f2b6d9050d1cd92b38f9e70cda0a41e325b72d35cc77443e2e70a17c382f3718c983ca41799eec0177131876ec0ba45b49d0c9018a9edba488552ad044173
6
+ metadata.gz: 40ac1d0adebc602bb7b7d051a6b679d0f3a28e7edf79a6b873fc9a3bb25c100b3604f83818aa67991b9dde0ac67e0744964080fc4e4fe0b581e6c8ab1644347e
7
+ data.tar.gz: 7c8b1ffba321fc5098f516a76105c7e6454aef06fcf0af0e9bb741b3ec92138ae82ab98af0c19ba45ca5f8cb2cee6956abdeab2c69967ca28ab5adc2881e65a7
@@ -5,6 +5,7 @@ script: "bundle exec rake spec"
5
5
  gemfile:
6
6
  - gemfiles/rails3.gemfile
7
7
  - gemfiles/rails4.gemfile
8
+ - gemfiles/rails5.gemfile
8
9
  notifications:
9
10
  email:
10
11
  - support@travellink.com.au
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
5
+
6
+ ## 0.2.0
7
+
8
+ ### Added
9
+ - Rails 4/5 support
10
+ - Groupless rights
11
+
12
+ ### Added
13
+ - [TT-1392] Changelog file
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => '../'
3
+
4
+ group :development, :test do
5
+ gem 'rails', '~> 5.0'
6
+ end
@@ -23,7 +23,7 @@ module RightOn
23
23
  unless @@restricted_by_right_classes.include?(klass)
24
24
  @@restricted_by_right_classes << klass
25
25
  end
26
- has_one klass.table_name.singularize.to_sym, :dependent => :restrict
26
+ has_one klass.table_name.singularize.to_sym, dependent: :restrict_with_exception
27
27
  end
28
28
 
29
29
  def rights_yaml(file_path)
@@ -31,52 +31,58 @@ module RightOn
31
31
  end
32
32
 
33
33
  def by_groups
34
- rights = []
35
- rights += regular_rights_with_group
36
- rights += restricted_rights_with_group
34
+ rights = regular_rights_with_group + restricted_rights_with_group
35
+ rights += (Right.all - rights)
37
36
  rights.group_by(&:group)
38
37
  end
39
38
 
40
39
  def regular_rights_with_group
41
- yaml = YAML::load_file(@@rights_yaml)
42
- rights = []
43
- rights_by_name = Hash[Right.all.map{|r| [r.name, r]}]
44
- yaml['rights'].each_pair do |group, right_names|
45
- rights_for_group = []
46
- right_names.each do |right_name|
47
- if right_name.is_a?(String) # controller
48
- r = rights_by_name[right_name]
49
- raise right_name if r.nil?
50
- rights_for_group << r
51
- else right_name.is_a?(Hash) # controller + actions
52
- controller, actions = right_name.first
53
- r = rights_by_name[controller]
54
- if r
55
- rights_for_group << r
56
- end
57
- actions.each do |action|
58
- name = "#{controller}##{action}"
59
- r = rights_by_name[name]
60
- raise name.inspect + "****" + right_name.inspect + '---' + action_right.inspect if r.nil?
61
- rights_for_group << r
62
- end
63
- end
64
- end
65
- rights_for_group.each{|r| r.group = group}
66
- rights += rights_for_group
40
+ yaml_rights.each_pair.flat_map do |group, right_names|
41
+ right_names
42
+ .flat_map { |right_name| right_name_to_rights(right_name) }
43
+ .each { |r| r.group = group }
67
44
  end
68
- rights
45
+ end
46
+
47
+ def yaml_rights
48
+ YAML::load_file(@@rights_yaml)['rights']
49
+ end
50
+
51
+ def right_name_to_rights(right_name)
52
+ case right_name
53
+ when String # controller
54
+ [rights_by_name!(right_name)]
55
+ when Hash # controller + actions
56
+ controller, actions = right_name.first
57
+ controller_rights(controller) + action_rights(controller, actions)
58
+ end
59
+ end
60
+
61
+ def controller_rights(controller)
62
+ r = rights_by_name[controller]
63
+ return [] unless r
64
+ [r]
65
+ end
66
+
67
+ def action_rights(controller, actions)
68
+ actions.map { |action| rights_by_name!("#{controller}##{action}") }
69
+ end
70
+
71
+ def rights_by_name
72
+ @rights_by_name ||= Hash[Right.all.map{|r| [r.name, r]}]
73
+ end
74
+
75
+ def rights_by_name!(name)
76
+ rights_by_name[name] or fail name.inspect
69
77
  end
70
78
 
71
79
  def restricted_rights_with_group
72
- rights = []
73
- @@restricted_by_right_classes.each do |klass|
80
+ @@restricted_by_right_classes.flat_map do |klass|
74
81
  group = klass.restricted_by_right_group
75
- rights += all_rights(klass).map(&:right).each do |right|
82
+ all_rights(klass).map(&:right).sort_by(&:name).each do |right|
76
83
  right.group = group
77
84
  end
78
85
  end
79
- rights
80
86
  end
81
87
 
82
88
  def all_rights(klass)
@@ -1,3 +1,3 @@
1
1
  module RightOn
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency('activerecord', [">= 3.2.0", "< 5.0.0"])
22
- spec.add_dependency('activesupport', [">= 3.2.0", "< 5.0.0"])
23
- spec.add_dependency('dependent_restrict', [">= 0.2.1"])
24
- spec.add_dependency('input_reader', ["~> 0.0"])
25
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_dependency 'activerecord', '>= 3.2.0'
22
+ spec.add_dependency 'activesupport', '>= 3.2.0'
23
+ spec.add_dependency 'dependent_restrict', '>= 0.2.3'
24
+ spec.add_dependency 'input_reader', '~> 0.0'
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
26
  spec.add_development_dependency 'rake'
27
27
  spec.add_development_dependency 'rspec'
28
- spec.add_development_dependency 'simplecov'
28
+ spec.add_development_dependency 'coverage-kit'
29
29
  spec.add_development_dependency 'simplecov-rcov'
30
30
  spec.add_development_dependency 'coveralls'
31
31
  spec.add_development_dependency 'sqlite3'
@@ -1,26 +1,4 @@
1
- MINIMUM_COVERAGE = 70
2
-
3
- unless ENV['COVERAGE'] == 'off'
4
- require 'simplecov'
5
- require 'simplecov-rcov'
6
- require 'coveralls'
7
- Coveralls.wear!
8
-
9
- SimpleCov.formatters = [
10
- SimpleCov::Formatter::RcovFormatter,
11
- Coveralls::SimpleCov::Formatter
12
- ]
13
- SimpleCov.start do
14
- add_filter '/vendor/'
15
- add_filter '/spec/'
16
- add_group 'lib', 'lib'
17
- end
18
- SimpleCov.at_exit do
19
- SimpleCov.result.format!
20
- percent = SimpleCov.result.covered_percent
21
- unless percent >= MINIMUM_COVERAGE
22
- puts "Coverage must be above #{MINIMUM_COVERAGE}%. It is #{"%.2f" % percent}%"
23
- Kernel.exit(1)
24
- end
25
- end
26
- end
1
+ require 'simplecov-rcov'
2
+ require 'coveralls'
3
+ require 'coverage/kit'
4
+ Coverage::Kit.setup(minimum_coverage: 84.7)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Noack
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-17 00:00:00.000000000 Z
12
+ date: 2017-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -18,9 +18,6 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.2.0
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: 5.0.0
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,9 +25,6 @@ dependencies:
28
25
  - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: 3.2.0
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: 5.0.0
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: activesupport
36
30
  requirement: !ruby/object:Gem::Requirement
@@ -38,9 +32,6 @@ dependencies:
38
32
  - - ">="
39
33
  - !ruby/object:Gem::Version
40
34
  version: 3.2.0
41
- - - "<"
42
- - !ruby/object:Gem::Version
43
- version: 5.0.0
44
35
  type: :runtime
45
36
  prerelease: false
46
37
  version_requirements: !ruby/object:Gem::Requirement
@@ -48,23 +39,20 @@ dependencies:
48
39
  - - ">="
49
40
  - !ruby/object:Gem::Version
50
41
  version: 3.2.0
51
- - - "<"
52
- - !ruby/object:Gem::Version
53
- version: 5.0.0
54
42
  - !ruby/object:Gem::Dependency
55
43
  name: dependent_restrict
56
44
  requirement: !ruby/object:Gem::Requirement
57
45
  requirements:
58
46
  - - ">="
59
47
  - !ruby/object:Gem::Version
60
- version: 0.2.1
48
+ version: 0.2.3
61
49
  type: :runtime
62
50
  prerelease: false
63
51
  version_requirements: !ruby/object:Gem::Requirement
64
52
  requirements:
65
53
  - - ">="
66
54
  - !ruby/object:Gem::Version
67
- version: 0.2.1
55
+ version: 0.2.3
68
56
  - !ruby/object:Gem::Dependency
69
57
  name: input_reader
70
58
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +110,7 @@ dependencies:
122
110
  - !ruby/object:Gem::Version
123
111
  version: '0'
124
112
  - !ruby/object:Gem::Dependency
125
- name: simplecov
113
+ name: coverage-kit
126
114
  requirement: !ruby/object:Gem::Requirement
127
115
  requirements:
128
116
  - - ">="
@@ -200,6 +188,7 @@ files:
200
188
  - ".gitignore"
201
189
  - ".rspec"
202
190
  - ".travis.yml"
191
+ - CHANGELOG.md
203
192
  - Gemfile
204
193
  - LICENSE
205
194
  - README.md
@@ -208,6 +197,7 @@ files:
208
197
  - db/rights_roles.yml
209
198
  - gemfiles/rails3.gemfile
210
199
  - gemfiles/rails4.gemfile
200
+ - gemfiles/rails5.gemfile
211
201
  - lib/right_on.rb
212
202
  - lib/right_on/action_controller_extensions.rb
213
203
  - lib/right_on/generators/USAGE
@@ -254,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
244
  version: '0'
255
245
  requirements: []
256
246
  rubyforge_project:
257
- rubygems_version: 2.4.8
247
+ rubygems_version: 2.5.2
258
248
  signing_key:
259
249
  specification_version: 4
260
250
  summary: Set of extensions to core rails to give rights and roles.