monarchy 1.0.0 → 1.1.3

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: 7dfc2d0fdc01fa14cb113bb0d1cf87533af6e849
4
- data.tar.gz: 6ca7712af3dfbe53c0f309432415471bb1f70cf8
3
+ metadata.gz: 6ee35ff7681e64755e2287e318540e66ef5fd891
4
+ data.tar.gz: 60d1a4cf7ba3727517250c2a44c40024cc211224
5
5
  SHA512:
6
- metadata.gz: defd04040f7ece731b35b84ee04000f72cb08be7cceef9d63ba043d61b77459e8a11cdee5f15cbdcece69f1898ce3709c3e127816040159997bf49a96be01a16
7
- data.tar.gz: fb7b2313b86d63b912b8741038fe245dbf6847ecccce9d681db5575ba370a7f1661bbc5658c6fdeadbdbc650e23e08c809c89db894f49a5a17e51a8247f9ee94
6
+ metadata.gz: 66f9f19fe4eaffd3e31f4324b55d69f4b5ed8afaf9d1adf6b370ff990b12a1ee9300b2ebdc9f159f81242535fbfc208f35d2417179afc3406ce19f7c37973b07
7
+ data.tar.gz: ecca2c24e3c2eb3f830d52e720ad6dc0ec54e876fe4a4596b768a981ba3004d496a05d8680668af9a2a80d54f642474c1f3eca81e8390e4520bb8714ee47bf79
data/.rubocop.yml CHANGED
@@ -8,7 +8,7 @@ AllCops:
8
8
  Documentation:
9
9
  Enabled: false
10
10
  Metrics/LineLength:
11
- Max: 120
11
+ Max: 125
12
12
  Style/CaseIndentation:
13
13
  Enabled: false
14
14
  Style/StructInheritance:
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.10.6
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.12
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  source 'https://rubygems.org'
3
- ruby '2.3.0'
3
+ ruby '2.3.1'
4
4
 
5
5
  # Declare your gem's dependencies in monarchy.gemspec.
6
6
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -17,14 +17,14 @@ gemspec
17
17
 
18
18
  group :development, :test do
19
19
  gem 'sqlite3', '1.3.11'
20
- gem 'rubocop', '0.40.0'
20
+ gem 'rubocop', '0.42.0'
21
21
  gem 'pry-rails', '0.3.4'
22
22
  gem 'shoulda-matchers', '3.1.1'
23
- gem 'rspec-rails', '3.4.2'
23
+ gem 'rspec-rails', '3.5.1'
24
24
  gem 'factory_girl_rails', '4.7.0'
25
25
  gem 'ffaker', '2.2.0'
26
26
  gem 'database_cleaner', '1.5.3'
27
27
  gem 'tqdm', '0.3.0'
28
28
  end
29
29
 
30
- gem 'simplecov', '0.11.2', require: false, group: :test
30
+ gem 'simplecov', '0.12.0', require: false, group: :test
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monarchy (0.3.1)
5
- active_record_union (= 1.1.1)
6
- closure_tree (= 6.0.0)
4
+ monarchy (1.1.3)
5
+ active_record_union (= 1.2.0)
6
+ closure_tree (= 6.1.0)
7
7
  configurations (= 2.2.0)
8
8
  rails (~> 4.2, >= 4.2.4)
9
9
  tqdm (= 0.3.0)
@@ -30,7 +30,7 @@ GEM
30
30
  erubis (~> 2.7.0)
31
31
  rails-dom-testing (~> 1.0, >= 1.0.5)
32
32
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
- active_record_union (1.1.1)
33
+ active_record_union (1.2.0)
34
34
  activerecord (>= 4.0)
35
35
  activejob (4.2.7)
36
36
  activesupport (= 4.2.7)
@@ -51,7 +51,7 @@ GEM
51
51
  arel (6.0.3)
52
52
  ast (2.3.0)
53
53
  builder (3.2.2)
54
- closure_tree (6.0.0)
54
+ closure_tree (6.1.0)
55
55
  activerecord (>= 4.1.0)
56
56
  with_advisory_lock (>= 3.0.0)
57
57
  coderay (1.1.1)
@@ -123,29 +123,29 @@ GEM
123
123
  thor (>= 0.18.1, < 2.0)
124
124
  rainbow (2.1.0)
125
125
  rake (11.2.2)
126
- rspec (3.4.0)
127
- rspec-core (~> 3.4.0)
128
- rspec-expectations (~> 3.4.0)
129
- rspec-mocks (~> 3.4.0)
130
- rspec-core (3.4.4)
131
- rspec-support (~> 3.4.0)
132
- rspec-expectations (3.4.0)
126
+ rspec (3.5.0)
127
+ rspec-core (~> 3.5.0)
128
+ rspec-expectations (~> 3.5.0)
129
+ rspec-mocks (~> 3.5.0)
130
+ rspec-core (3.5.2)
131
+ rspec-support (~> 3.5.0)
132
+ rspec-expectations (3.5.0)
133
133
  diff-lcs (>= 1.2.0, < 2.0)
134
- rspec-support (~> 3.4.0)
135
- rspec-mocks (3.4.1)
134
+ rspec-support (~> 3.5.0)
135
+ rspec-mocks (3.5.0)
136
136
  diff-lcs (>= 1.2.0, < 2.0)
137
- rspec-support (~> 3.4.0)
138
- rspec-rails (3.4.2)
139
- actionpack (>= 3.0, < 4.3)
140
- activesupport (>= 3.0, < 4.3)
141
- railties (>= 3.0, < 4.3)
142
- rspec-core (~> 3.4.0)
143
- rspec-expectations (~> 3.4.0)
144
- rspec-mocks (~> 3.4.0)
145
- rspec-support (~> 3.4.0)
146
- rspec-support (3.4.1)
147
- rubocop (0.40.0)
148
- parser (>= 2.3.1.0, < 3.0)
137
+ rspec-support (~> 3.5.0)
138
+ rspec-rails (3.5.1)
139
+ actionpack (>= 3.0)
140
+ activesupport (>= 3.0)
141
+ railties (>= 3.0)
142
+ rspec-core (~> 3.5.0)
143
+ rspec-expectations (~> 3.5.0)
144
+ rspec-mocks (~> 3.5.0)
145
+ rspec-support (~> 3.5.0)
146
+ rspec-support (3.5.0)
147
+ rubocop (0.42.0)
148
+ parser (>= 2.3.1.1, < 3.0)
149
149
  powerpack (~> 0.1)
150
150
  rainbow (>= 1.99.1, < 3.0)
151
151
  ruby-progressbar (~> 1.7)
@@ -153,9 +153,9 @@ GEM
153
153
  ruby-progressbar (1.8.1)
154
154
  shoulda-matchers (3.1.1)
155
155
  activesupport (>= 4.0.0)
156
- simplecov (0.11.2)
156
+ simplecov (0.12.0)
157
157
  docile (~> 1.1.0)
158
- json (~> 1.8)
158
+ json (>= 1.8, < 3)
159
159
  simplecov-html (~> 0.10.0)
160
160
  simplecov-html (0.10.0)
161
161
  slop (3.6.0)
@@ -181,18 +181,18 @@ PLATFORMS
181
181
  ruby
182
182
 
183
183
  DEPENDENCIES
184
- bundler (~> 1.10)
184
+ bundler (~> 1.12)
185
185
  database_cleaner (= 1.5.3)
186
186
  factory_girl_rails (= 4.7.0)
187
187
  ffaker (= 2.2.0)
188
188
  monarchy!
189
189
  pry-rails (= 0.3.4)
190
190
  rake (~> 11.1)
191
- rspec (= 3.4.0)
192
- rspec-rails (= 3.4.2)
193
- rubocop (= 0.40.0)
191
+ rspec (= 3.5.0)
192
+ rspec-rails (= 3.5.1)
193
+ rubocop (= 0.42.0)
194
194
  shoulda-matchers (= 3.1.1)
195
- simplecov (= 0.11.2)
195
+ simplecov (= 0.12.0)
196
196
  sqlite3 (= 1.3.11)
197
197
  tqdm (= 0.3.0)
198
198
 
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  [![Build Status](https://travis-ci.org/Exelord/Monarchy.svg?branch=master)](https://travis-ci.org/Exelord/Monarchy)
2
2
  [![Dependency Status](https://gemnasium.com/badges/github.com/Exelord/Monarchy.svg)](https://gemnasium.com/github.com/Exelord/Monarchy)
3
3
  [![Gitter](https://badges.gitter.im/Exelord/Monarchy.svg)](https://gitter.im/Exelord/Monarchy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
4
- ![Monarchy Logo](monarchy.png?raw=true)
4
+
5
+ <p align="center">
6
+ <img align="center" src="monarchy.png?raw=true" alt="Sublime's custom image"/>
7
+ </p>
5
8
 
6
9
  ## Documentation
7
10
  There is existing fully documentation for that project in our Wiki. Take a look at [Monarchy Documentation] (https://github.com/Exelord/Monarchy/wiki)
@@ -10,11 +13,6 @@ There is existing fully documentation for that project in our Wiki. Take a look
10
13
 
11
14
  Bug reports and pull requests are welcome on GitHub at https://github.com/exelord/Monarchy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
12
15
 
13
- ## Development
14
- Gem dependencies:
15
- - https://github.com/mceachen/closure_tree
16
- - https://github.com/beatrichartz/configurations
17
-
18
16
  ## License
19
17
 
20
18
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -8,5 +8,4 @@ Monarchy.configure do |config|
8
8
  # config.user_class_name = 'User'
9
9
 
10
10
  # config.member_force_revoke = true
11
- # config.restricted_role_names = ['member']
12
11
  end
@@ -9,8 +9,7 @@ module Monarchy
9
9
  has_closure_tree dependent: :destroy
10
10
 
11
11
  has_many :members, class_name: "::#{Monarchy.member_class}", dependent: :destroy
12
- belongs_to :resource, polymorphic: true, dependent: :destroy
13
-
12
+ belongs_to :resource, polymorphic: true
14
13
  include_scopes
15
14
 
16
15
  validates :resource_type, presence: true
@@ -41,18 +40,14 @@ module Monarchy
41
40
 
42
41
  def accessible_leaves(user)
43
42
  descendant_leaves.where('monarchy_hierarchy_hierarchies.descendant_id': descendant_leaves_for_user(user)
44
- .where('monarchy_roles.name': restricted_role_names)
43
+ .where('monarchy_roles.inherited': false)
45
44
  .select('monarchy_hierarchy_hierarchies.ancestor_id')).union(
46
45
  descendant_leaves
47
46
  .where('monarchy_hierarchy_hierarchies.ancestor_id': descendant_leaves_for_user(user)
48
- .where.not('monarchy_roles.name': restricted_role_names))
47
+ .where.not('monarchy_roles.inherited': false))
49
48
  )
50
49
  end
51
50
 
52
- def restricted_role_names
53
- Array(Monarchy.configuration.restricted_role_names) + [default_role_name]
54
- end
55
-
56
51
  def default_role_name
57
52
  Monarchy.configuration.default_role.name
58
53
  end
@@ -82,7 +82,11 @@ module Monarchy
82
82
 
83
83
  def assign_parent(force = false)
84
84
  parent = self.class.parentize
85
- self.parent = send(parent) if parent && (send("#{parent}_id_changed?") || force)
85
+
86
+ if parent
87
+ was_changed = changes["#{parent}_id"] || changes["#{parent}_type"]
88
+ self.parent = send(parent) if was_changed || force
89
+ end
86
90
  end
87
91
 
88
92
  def children_resources
@@ -81,8 +81,8 @@ module Monarchy
81
81
  end
82
82
 
83
83
  def revoking_role(role_name, resource, force = false)
84
- member = member_for(resource)
85
- member_roles = member.members_roles
84
+ member_roles = member_for(resource).try(:members_roles)
85
+ return 0 if member_roles.nil?
86
86
 
87
87
  return revoke_access(resource) if last_role?(member_roles, role_name) && force
88
88
  member_roles.joins(:role).where(monarchy_roles: { name: role_name }).delete_all
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Monarchy
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.3'
4
4
  end
data/lib/monarchy.rb CHANGED
@@ -23,7 +23,6 @@ module Monarchy
23
23
  config.member_class_name = 'Monarchy::Member'
24
24
  config.role_class_name = 'Monarchy::Role'
25
25
  config.member_force_revoke = false
26
- config.restricted_role_names = []
27
26
  end
28
27
 
29
28
  not_configured do |prop|
@@ -2,17 +2,33 @@
2
2
  require 'tqdm'
3
3
 
4
4
  task 'monarchy:reparentize' do
5
+ p 'Monarchy reparentize...'
6
+
5
7
  Monarchy.resource_classes.with_progress.each do |klass|
6
8
  klass.all.each do |model|
7
9
  model.send(:assign_parent, true)
8
10
  end
9
11
  end
12
+
13
+ Monarchy::Hierarchy.rebuild!
14
+ p 'Monarchy reparentize ended!'
10
15
  end
11
16
 
12
17
  task 'monarchy:hierarchization' do
18
+ p 'Monarchy hierarchization...'
13
19
  Monarchy.resource_classes.with_progress.each do |klass|
14
20
  klass.all.each do |model|
15
21
  model.send(:ensure_hierarchy)
16
22
  end
17
23
  end
24
+ p 'Monarchy hierarchization ended!'
25
+ end
26
+
27
+ task 'monarchy:rebuild' do
28
+ p 'Rebuilding Monarchy...'
29
+
30
+ Rake::Task['monarchy:hierarchization'].invoke
31
+ Rake::Task['monarchy:reparentize'].invoke
32
+
33
+ p 'Rebuilding Monarchy ended!'
18
34
  end
data/monarchy.gemspec CHANGED
@@ -26,12 +26,12 @@ Gem::Specification.new do |s|
26
26
  s.require_paths = ['lib']
27
27
 
28
28
  s.add_runtime_dependency 'rails', '~> 4.2', '>= 4.2.4'
29
- s.add_dependency 'closure_tree', '6.0.0'
29
+ s.add_dependency 'closure_tree', '6.1.0'
30
30
  s.add_dependency 'configurations', '2.2.0'
31
- s.add_dependency 'active_record_union', '1.1.1'
31
+ s.add_dependency 'active_record_union', '1.2.0'
32
32
  s.add_dependency 'tqdm', '0.3.0'
33
33
 
34
- s.add_development_dependency 'bundler', '~> 1.10'
34
+ s.add_development_dependency 'bundler', '~> 1.12'
35
35
  s.add_development_dependency 'rake', '~> 11.1'
36
- s.add_development_dependency 'rspec', '3.4.0'
36
+ s.add_development_dependency 'rspec', '3.5.0'
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monarchy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Exelord
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-05 00:00:00.000000000 Z
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 6.0.0
39
+ version: 6.1.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 6.0.0
46
+ version: 6.1.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: configurations
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - '='
66
66
  - !ruby/object:Gem::Version
67
- version: 1.1.1
67
+ version: 1.2.0
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - '='
73
73
  - !ruby/object:Gem::Version
74
- version: 1.1.1
74
+ version: 1.2.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: tqdm
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.10'
95
+ version: '1.12'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.10'
102
+ version: '1.12'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - '='
122
122
  - !ruby/object:Gem::Version
123
- version: 3.4.0
123
+ version: 3.5.0
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - '='
129
129
  - !ruby/object:Gem::Version
130
- version: 3.4.0
130
+ version: 3.5.0
131
131
  description: Hierarchical access management system with roles inheritance.
132
132
  email:
133
133
  - ''