monarchy 2.0.8 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a877a7ac740060484a3f64d5d0f9fbb7fcf310b
4
- data.tar.gz: f26a5bd2af7906227bb78e9a35937e9bfd2ebe4a
3
+ metadata.gz: 4c1b86d97c67b9409578191ef62d270fb906dec7
4
+ data.tar.gz: 77e1921b3153f9ebd4ec32a7a025efae77c9ec05
5
5
  SHA512:
6
- metadata.gz: 8727e6be4d706c8117fc1dae73f19bff9cab7e57269c2c85e942f14b4dbf7e9e761a065ecd8d031fe13c39ce1b6961073dd8e4d6e4937e2c558253bc910668e0
7
- data.tar.gz: 2fd0924823fba6765740c972246a1db28cb358be122c290a28957451b85bc886e306ad89d1c6797436f0a74e763de5f0c70255fb10fdcf0b6dce8c84974c1b8f
6
+ metadata.gz: a25851a0766ad737e3707026aae70160d28077de7c545bdfea6e1b0645bad7ecd460c90192162632c80a2d860944e5f462799660dc2af9c59542779dc4b8ebe5
7
+ data.tar.gz: e1ad1bf1ee4f3f6eca2c722a30fb38e1efd1e61dcae631506b54c6554dba33e4ca6a257e72faba47df681a9deeb1d80f4efe6c8816f6dfd9dc3cd41bcc7614cf
@@ -1 +1 @@
1
- future-release=2.0.8
1
+ future-release=2.1.0
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.4
3
3
  Exclude:
4
4
  - 'dummy/db/seeds.rb'
5
5
  - 'dummy/db/migrate/**'
@@ -11,6 +11,8 @@ Metrics/LineLength:
11
11
  Max: 125
12
12
  Metrics/ModuleLength:
13
13
  Max: 150
14
+ Metrics/BlockLength:
15
+ ExcludedMethods: ['describe', 'context']
14
16
  Style/CaseIndentation:
15
17
  Enabled: false
16
18
  Style/StructInheritance:
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ addons:
3
3
  repo_token: 60b8a9fc7e8d659c7dd22ed8912651c35b3ca5eebf1c23d5470308e6a802abbd
4
4
  language: ruby
5
5
  rvm:
6
- - 2.3.1
7
- before_install: gem install bundler -v 1.12
6
+ - 2.4.0
7
+ before_install: gem update --system
8
8
  after_success:
9
9
  - bundle exec codeclimate-test-reporter
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
1
  # Change Log
2
2
 
3
- ## [2.0.8](https://github.com/Exelord/Monarchy/tree/2.0.8) (2017-01-12)
4
- [Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.7...2.0.8)
3
+ ## [2.1.0](https://github.com/Exelord/Monarchy/tree/2.1.0) (2017-03-30)
4
+ [Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.8...2.1.0)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Users/Members with\_access\_to specific resource [\#70](https://github.com/Exelord/Monarchy/pull/70) ([Exelord](https://github.com/Exelord))
9
+ - Update gems [\#69](https://github.com/Exelord/Monarchy/pull/69) ([Exelord](https://github.com/Exelord))
10
+
11
+ ## [v2.0.8](https://github.com/Exelord/Monarchy/tree/v2.0.8) (2017-01-12)
12
+ [Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.7...v2.0.8)
5
13
 
6
14
  **Merged pull requests:**
7
15
 
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  source 'https://rubygems.org'
3
- ruby '2.3.1'
3
+ ruby '2.4.0'
4
4
 
5
5
  # Declare your gem's dependencies in monarchy.gemspec.
6
6
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -22,11 +22,10 @@ group :development, :test do
22
22
  gem 'pry-rails', '0.3.4'
23
23
  gem 'rails', '5.0.1'
24
24
  gem 'rspec-rails', '3.5.2'
25
- gem 'rubocop', '0.46.0'
25
+ gem 'rubocop', '0.47.1'
26
26
  gem 'shoulda-matchers', '3.1.1'
27
27
  gem 'sqlite3', '1.3.13'
28
- gem 'tqdm', '0.3.0'
29
28
  end
30
29
 
31
- gem 'codeclimate-test-reporter', '1.0.4', group: :test
32
- gem 'simplecov', '0.12.0', group: :test
30
+ gem 'codeclimate-test-reporter', '~>1.0.5', group: :test
31
+ gem 'simplecov', '0.13.0', group: :test
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monarchy (2.0.8)
4
+ monarchy (2.1.0)
5
5
  active_record_union (= 1.2.0)
6
6
  activerecord (>= 4.2.7.1)
7
- closure_tree (= 6.2.0)
7
+ closure_tree (= 6.3.0)
8
8
  configurations (= 2.2.2)
9
9
  tqdm (= 0.3.0)
10
10
 
@@ -52,17 +52,17 @@ GEM
52
52
  tzinfo (~> 1.1)
53
53
  arel (7.1.4)
54
54
  ast (2.3.0)
55
- builder (3.2.2)
56
- closure_tree (6.2.0)
55
+ builder (3.2.3)
56
+ closure_tree (6.3.0)
57
57
  activerecord (>= 4.1.0)
58
58
  with_advisory_lock (>= 3.0.0)
59
- codeclimate-test-reporter (1.0.4)
59
+ codeclimate-test-reporter (1.0.5)
60
60
  simplecov
61
61
  coderay (1.1.1)
62
62
  concurrent-ruby (1.0.4)
63
63
  configurations (2.2.2)
64
64
  database_cleaner (1.5.3)
65
- diff-lcs (1.2.5)
65
+ diff-lcs (1.3)
66
66
  docile (1.1.5)
67
67
  erubis (2.7.0)
68
68
  factory_girl (4.8.0)
@@ -73,7 +73,7 @@ GEM
73
73
  ffaker (2.4.0)
74
74
  globalid (0.3.7)
75
75
  activesupport (>= 4.1.0)
76
- i18n (0.7.0)
76
+ i18n (0.8.0)
77
77
  json (2.0.3)
78
78
  loofah (2.0.3)
79
79
  nokogiri (>= 1.5.9)
@@ -88,7 +88,7 @@ GEM
88
88
  nio4r (1.2.1)
89
89
  nokogiri (1.7.0.1)
90
90
  mini_portile2 (~> 2.1.0)
91
- parser (2.3.3.1)
91
+ parser (2.4.0.0)
92
92
  ast (~> 2.2)
93
93
  powerpack (0.1.1)
94
94
  pry (0.10.4)
@@ -146,8 +146,8 @@ GEM
146
146
  rspec-mocks (~> 3.5.0)
147
147
  rspec-support (~> 3.5.0)
148
148
  rspec-support (3.5.0)
149
- rubocop (0.46.0)
150
- parser (>= 2.3.1.1, < 3.0)
149
+ rubocop (0.47.1)
150
+ parser (>= 2.3.3.1, < 3.0)
151
151
  powerpack (~> 0.1)
152
152
  rainbow (>= 1.99.1, < 3.0)
153
153
  ruby-progressbar (~> 1.7)
@@ -155,7 +155,7 @@ GEM
155
155
  ruby-progressbar (1.8.1)
156
156
  shoulda-matchers (3.1.1)
157
157
  activesupport (>= 4.0.0)
158
- simplecov (0.12.0)
158
+ simplecov (0.13.0)
159
159
  docile (~> 1.1.0)
160
160
  json (>= 1.8, < 3)
161
161
  simplecov-html (~> 0.10.0)
@@ -174,8 +174,8 @@ GEM
174
174
  tqdm (0.3.0)
175
175
  tzinfo (1.2.2)
176
176
  thread_safe (~> 0.1)
177
- unicode-display_width (1.1.2)
178
- websocket-driver (0.6.4)
177
+ unicode-display_width (1.1.3)
178
+ websocket-driver (0.6.5)
179
179
  websocket-extensions (>= 0.1.0)
180
180
  websocket-extensions (0.1.2)
181
181
  with_advisory_lock (3.0.0)
@@ -187,7 +187,7 @@ PLATFORMS
187
187
 
188
188
  DEPENDENCIES
189
189
  bundler (~> 1.12)
190
- codeclimate-test-reporter (= 1.0.4)
190
+ codeclimate-test-reporter (~> 1.0.5)
191
191
  database_cleaner (= 1.5.3)
192
192
  factory_girl_rails (= 4.8.0)
193
193
  ffaker (= 2.4.0)
@@ -197,14 +197,13 @@ DEPENDENCIES
197
197
  rake (~> 12.0)
198
198
  rspec (= 3.5.0)
199
199
  rspec-rails (= 3.5.2)
200
- rubocop (= 0.46.0)
200
+ rubocop (= 0.47.1)
201
201
  shoulda-matchers (= 3.1.1)
202
- simplecov (= 0.12.0)
202
+ simplecov (= 0.13.0)
203
203
  sqlite3 (= 1.3.13)
204
- tqdm (= 0.3.0)
205
204
 
206
205
  RUBY VERSION
207
- ruby 2.3.1p112
206
+ ruby 2.4.0p0
208
207
 
209
208
  BUNDLED WITH
210
- 1.13.7
209
+ 1.14.3
@@ -22,6 +22,13 @@ You can select all members accessible for specific user by using a scope: `acces
22
22
  ``` ruby
23
23
  Monarchy::member_class.accessible_for(current_user) # returns [member1, member2, member5]
24
24
  ```
25
+
26
+ ### .with_access_to
27
+ You can select all members with access to the specific resource by using a scope: `with_access_to`, eg:
28
+ ``` ruby
29
+ Monarchy::member_class.with_access_to(resource) # returns [member1, member2, member5]
30
+ ```
31
+
25
32
  ## Public Relations:
26
33
 
27
34
  ### #roles
data/docs/acts_as_user.md CHANGED
@@ -22,6 +22,12 @@ Returns all memberships (`member` model) of the user
22
22
  Returns all users accessible for the specific user
23
23
  It includes all users from all resource which the user has any access.
24
24
 
25
+ ### .with_access_to
26
+ You can select all users with access to the specific resource by using a scope: `with_access_to`, eg:
27
+ ``` ruby
28
+ Monarchy::user_class.with_access_to(resource) # returns [user1, user2, user5]
29
+ ```
30
+
25
31
  ## Methods
26
32
 
27
33
  ### #roles_for(resource, inheritance = true)
@@ -26,6 +26,11 @@ module Monarchy
26
26
  Monarchy::Validators.user(user)
27
27
  where(hierarchy: Monarchy.hierarchy_class.accessible_for(user))
28
28
  end)
29
+
30
+ scope :with_access_to, (lambda do |resource|
31
+ Monarchy::Validators.resource(resource)
32
+ with_ancestors_access(resource).union(with_descendants_access(resource))
33
+ end)
29
34
  end
30
35
 
31
36
  def include_callbacks
@@ -45,6 +50,17 @@ module Monarchy
45
50
  belongs_to :user, class_name: "::#{Monarchy.user_class}"
46
51
  belongs_to :hierarchy, class_name: "::#{Monarchy.hierarchy_class}"
47
52
  end
53
+
54
+ private
55
+
56
+ def with_ancestors_access(resource)
57
+ unscoped.where(hierarchy: resource.hierarchy.self_and_ancestors)
58
+ .joins(:roles).where(monarchy_roles: { inherited: true })
59
+ end
60
+
61
+ def with_descendants_access(resource)
62
+ unscoped.where(hierarchy: resource.hierarchy.descendants)
63
+ end
48
64
  end
49
65
 
50
66
  module InstanceMethods
@@ -5,14 +5,26 @@ module Monarchy
5
5
 
6
6
  module ClassMethods
7
7
  def acts_as_user
8
+ extend Monarchy::ActsAsUser::SupportMethods
9
+
8
10
  has_many :members, class_name: "::#{Monarchy.member_class}", dependent: :destroy
9
11
  has_many :hierarchies, through: :members, class_name: "::#{Monarchy.hierarchy_class}"
10
12
 
13
+ include_scopes
14
+
15
+ include Monarchy::ActsAsUser::InstanceMethods
16
+ end
17
+ end
18
+
19
+ module SupportMethods
20
+ def include_scopes
11
21
  scope :accessible_for, (lambda do |user|
12
22
  where(id: Monarchy.member_class.accessible_for(user).select('user_id AS id')).union(where(id: user.id))
13
23
  end)
14
24
 
15
- include Monarchy::ActsAsUser::InstanceMethods
25
+ scope :with_access_to, (lambda do |resource|
26
+ User.where(id: Member.with_access_to(resource).select(:user_id))
27
+ end)
16
28
  end
17
29
  end
18
30
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Monarchy
3
- VERSION = '2.0.8'
3
+ VERSION = '2.1.0'
4
4
  end
data/monarchy.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.required_ruby_version = '>= 2.3'
28
28
 
29
29
  s.add_dependency 'activerecord', '>=4.2.7.1'
30
- s.add_dependency 'closure_tree', '6.2.0'
30
+ s.add_dependency 'closure_tree', '6.3.0'
31
31
  s.add_dependency 'configurations', '2.2.2'
32
32
  s.add_dependency 'active_record_union', '1.2.0'
33
33
  s.add_dependency 'tqdm', '0.3.0'
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: 2.0.8
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Exelord
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 6.2.0
33
+ version: 6.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 6.2.0
40
+ version: 6.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: configurations
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  version: '0'
260
260
  requirements: []
261
261
  rubyforge_project:
262
- rubygems_version: 2.6.8
262
+ rubygems_version: 2.6.10
263
263
  signing_key:
264
264
  specification_version: 4
265
265
  summary: Hierarchical access management system with roles inheritance.