nexus_cqrs 0.4.2 → 0.4.3
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 +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +4 -0
- data/lib/nexus_cqrs/auth/permission_provider.rb +48 -3
- data/lib/nexus_cqrs/version.rb +2 -2
- data/nexus_cqrs.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ad110fb96498636aa174c3d45aa7783177fb7e5a2475e828f6e694adf392b46
|
|
4
|
+
data.tar.gz: 35fd22cd65fd520c91c93629b365f4573fbc0787158212b12dd3fb1241e0da43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: faee92b66ddcd2cdcd70fb315f444c2f226ff194ff528eb5c4e3f0a654c5e274e7715df987883b7a0512cbf0245a84824dd24829aa879277424c675435ea5169
|
|
7
|
+
data.tar.gz: 172b58d34c2da223e41e933fd0df3b379450d0d9ec0ce89095e6581ff894006224614cb62455d7d5223a376988413f3e6d7a98e28d1d502ad58b349c3a075fa8
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -5,6 +5,7 @@ PATH
|
|
|
5
5
|
generator_spec
|
|
6
6
|
ibsciss-middleware
|
|
7
7
|
pundit
|
|
8
|
+
request_store
|
|
8
9
|
strings-case
|
|
9
10
|
thread_safe
|
|
10
11
|
|
|
@@ -74,6 +75,8 @@ GEM
|
|
|
74
75
|
rainbow (3.0.0)
|
|
75
76
|
rake (13.0.6)
|
|
76
77
|
regexp_parser (2.1.1)
|
|
78
|
+
request_store (1.5.0)
|
|
79
|
+
rack (>= 1.4)
|
|
77
80
|
rexml (3.2.5)
|
|
78
81
|
rspec (3.10.0)
|
|
79
82
|
rspec-core (~> 3.10.0)
|
|
@@ -117,6 +120,7 @@ DEPENDENCIES
|
|
|
117
120
|
generator_spec
|
|
118
121
|
ibsciss-middleware
|
|
119
122
|
nexus_cqrs!
|
|
123
|
+
request_store
|
|
120
124
|
rspec
|
|
121
125
|
rubocop
|
|
122
126
|
rubocop-shopify (~> 1.0.4)
|
|
@@ -22,8 +22,15 @@ module NexusCqrs
|
|
|
22
22
|
|
|
23
23
|
# check entity-specific permissions
|
|
24
24
|
unless permission_model.nil?
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
# get all permissions for this entity. NOTE: This will be cached per-request.
|
|
27
|
+
permissions = cached_permissions(permission_model)
|
|
28
|
+
|
|
29
|
+
# if there are no permissions for this entity and user, return false
|
|
30
|
+
return false if permissions[entity_id].nil?
|
|
31
|
+
|
|
32
|
+
# if the permission key is in the user's permissions for this entity, return true
|
|
33
|
+
return true if permissions[entity_id].include?(permission_key)
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
false
|
|
@@ -35,7 +42,7 @@ module NexusCqrs
|
|
|
35
42
|
# @param [Integer] entity_id ID of the entity
|
|
36
43
|
# @return [Array] Returns an array of hashes representing permission keys, along with their global status
|
|
37
44
|
# @example Get a list of permissions
|
|
38
|
-
# permissions.
|
|
45
|
+
# permissions.for_user_on_entity(CollectionPermissions, collection.id) #=>
|
|
39
46
|
# [
|
|
40
47
|
# {:global=>false, :key=>"collection:discard"},
|
|
41
48
|
# {:global=>false, :key=>"collection:publish"},
|
|
@@ -56,6 +63,35 @@ module NexusCqrs
|
|
|
56
63
|
(global_permissions + entity_permissions).uniq { |p| p[:key] }
|
|
57
64
|
end
|
|
58
65
|
|
|
66
|
+
# Retrieves a list of permissions assigned to a user for ANY entity ID
|
|
67
|
+
#
|
|
68
|
+
# @param [ApplicationRecord] permission_model Permission model
|
|
69
|
+
# @return [Hash] Returns a hash representing each entity and the user's permissions
|
|
70
|
+
# @example Get a list of permissions
|
|
71
|
+
# permissions.for_user(CollectionPermissions) #=>
|
|
72
|
+
# {
|
|
73
|
+
# 1 => ["collection:discard"],
|
|
74
|
+
# 2 => ["collection:discard"],
|
|
75
|
+
# 3 => ["collection:discard", "collection:edit"],
|
|
76
|
+
# 4 => ["collection:discard"],
|
|
77
|
+
# }
|
|
78
|
+
def for_user(permission_model)
|
|
79
|
+
return {} if @user_id.nil?
|
|
80
|
+
|
|
81
|
+
permissions = {}
|
|
82
|
+
|
|
83
|
+
# retrieve entity-specific permissions from DB and map to hash
|
|
84
|
+
permission_model.where(user_id: @user_id).each do |p|
|
|
85
|
+
if permissions[p.entity_id].nil?
|
|
86
|
+
permissions[p.entity_id] = [p.permission]
|
|
87
|
+
else
|
|
88
|
+
permissions[p.entity_id] << p.permission
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
permissions
|
|
93
|
+
end
|
|
94
|
+
|
|
59
95
|
private
|
|
60
96
|
|
|
61
97
|
def parse_permissions_array(permissions_array)
|
|
@@ -71,6 +107,15 @@ module NexusCqrs
|
|
|
71
107
|
|
|
72
108
|
permissions
|
|
73
109
|
end
|
|
110
|
+
|
|
111
|
+
# Retrieve all the permissions for this user for a specific model and cache it for this request (as all calls to
|
|
112
|
+
# a PermissionProvider in the same request will all have the same permissions, this saves on many SQL calls)
|
|
113
|
+
#
|
|
114
|
+
# @param [ApplicationRecord] permission_model Permission model
|
|
115
|
+
# @see PermissionProvider#for_user
|
|
116
|
+
def cached_permissions(permission_model)
|
|
117
|
+
::RequestStore.store[:permissions] ||= for_user(permission_model)
|
|
118
|
+
end
|
|
74
119
|
end
|
|
75
120
|
end
|
|
76
121
|
end
|
data/lib/nexus_cqrs/version.rb
CHANGED
data/nexus_cqrs.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nexus_cqrs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dean Lovett
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-11-
|
|
11
|
+
date: 2021-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: generator_spec
|
|
@@ -80,6 +80,20 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: request_store
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
83
97
|
description:
|
|
84
98
|
email:
|
|
85
99
|
- dean.lovett@nexusmods.com
|
|
@@ -140,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
140
154
|
- !ruby/object:Gem::Version
|
|
141
155
|
version: '0'
|
|
142
156
|
requirements: []
|
|
143
|
-
rubygems_version: 3.2.
|
|
157
|
+
rubygems_version: 3.2.32
|
|
144
158
|
signing_key:
|
|
145
159
|
specification_version: 4
|
|
146
160
|
summary: Core package for the nexus cqrs gem
|