bp3-core 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +45 -42
- data/README.md +22 -9
- data/bp3-core.gemspec +1 -1
- data/lib/bp3/core/actions.rb +18 -12
- data/lib/bp3/core/cookies.rb +13 -13
- data/lib/bp3/core/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a439b2f50c821e45fba5119a749a2c7b16f103eab54b791d10df8b7b55352393
|
4
|
+
data.tar.gz: '0598a39328efacd1be9f524c89927bc084921a9f083f5ad55a2079e43af7b3b6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 799d9784bb24ffc560fa30b0047d4c510e52395bcbdda02ae77087aba2a947cf6d35e658ebc22194522f39b8b1ed7da0e97342a82eab04dcf5cbbe21beb09dea
|
7
|
+
data.tar.gz: 94823bea2f47fc9af0a4477c6842071ebec9bff750e7e50239c6a061e9e37ceecdf03ae06791a4232e735676154d162d188f531a74eded2e192d8c1391984043
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bp3-core (0.1.
|
4
|
+
bp3-core (0.1.4)
|
5
5
|
actionview (>= 7.1.2, < 8)
|
6
6
|
activesupport (>= 7.1.2, < 8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionview (7.1.3)
|
12
|
-
activesupport (= 7.1.3)
|
11
|
+
actionview (7.1.3.4)
|
12
|
+
activesupport (= 7.1.3.4)
|
13
13
|
builder (~> 3.1)
|
14
14
|
erubi (~> 1.11)
|
15
15
|
rails-dom-testing (~> 2.2)
|
16
16
|
rails-html-sanitizer (~> 1.6)
|
17
|
-
activesupport (7.1.3)
|
17
|
+
activesupport (7.1.3.4)
|
18
18
|
base64
|
19
19
|
bigdecimal
|
20
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
@@ -26,31 +26,30 @@ GEM
|
|
26
26
|
tzinfo (~> 2.0)
|
27
27
|
ast (2.4.2)
|
28
28
|
base64 (0.2.0)
|
29
|
-
bigdecimal (3.1.
|
30
|
-
builder (3.
|
31
|
-
concurrent-ruby (1.
|
29
|
+
bigdecimal (3.1.8)
|
30
|
+
builder (3.3.0)
|
31
|
+
concurrent-ruby (1.3.3)
|
32
32
|
connection_pool (2.4.1)
|
33
33
|
crass (1.0.6)
|
34
|
-
diff-lcs (1.5.
|
35
|
-
drb (2.2.
|
36
|
-
|
37
|
-
|
38
|
-
i18n (1.14.1)
|
34
|
+
diff-lcs (1.5.1)
|
35
|
+
drb (2.2.1)
|
36
|
+
erubi (1.13.0)
|
37
|
+
i18n (1.14.5)
|
39
38
|
concurrent-ruby (~> 1.0)
|
40
|
-
json (2.7.
|
39
|
+
json (2.7.2)
|
41
40
|
language_server-protocol (3.17.0.3)
|
42
41
|
loofah (2.22.0)
|
43
42
|
crass (~> 1.0.2)
|
44
43
|
nokogiri (>= 1.12.0)
|
45
|
-
minitest (5.
|
44
|
+
minitest (5.24.1)
|
46
45
|
mutex_m (0.2.0)
|
47
|
-
nokogiri (1.16.
|
46
|
+
nokogiri (1.16.7-x86_64-darwin)
|
48
47
|
racc (~> 1.4)
|
49
|
-
parallel (1.
|
50
|
-
parser (3.3.0
|
48
|
+
parallel (1.25.1)
|
49
|
+
parser (3.3.4.0)
|
51
50
|
ast (~> 2.4.1)
|
52
51
|
racc
|
53
|
-
racc (1.
|
52
|
+
racc (1.8.1)
|
54
53
|
rails-dom-testing (2.2.0)
|
55
54
|
activesupport (>= 5.0.0)
|
56
55
|
minitest
|
@@ -59,47 +58,51 @@ GEM
|
|
59
58
|
loofah (~> 2.21)
|
60
59
|
nokogiri (~> 1.14)
|
61
60
|
rainbow (3.1.1)
|
62
|
-
rake (13.1
|
63
|
-
regexp_parser (2.9.
|
64
|
-
rexml (3.2
|
65
|
-
|
66
|
-
|
67
|
-
rspec-
|
68
|
-
rspec-
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
rake (13.2.1)
|
62
|
+
regexp_parser (2.9.2)
|
63
|
+
rexml (3.3.2)
|
64
|
+
strscan
|
65
|
+
rspec (3.13.0)
|
66
|
+
rspec-core (~> 3.13.0)
|
67
|
+
rspec-expectations (~> 3.13.0)
|
68
|
+
rspec-mocks (~> 3.13.0)
|
69
|
+
rspec-core (3.13.0)
|
70
|
+
rspec-support (~> 3.13.0)
|
71
|
+
rspec-expectations (3.13.1)
|
72
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
-
rspec-support (~> 3.
|
74
|
-
rspec-mocks (3.
|
73
|
+
rspec-support (~> 3.13.0)
|
74
|
+
rspec-mocks (3.13.1)
|
75
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
-
rspec-support (~> 3.
|
77
|
-
rspec-support (3.
|
78
|
-
rubocop (1.
|
76
|
+
rspec-support (~> 3.13.0)
|
77
|
+
rspec-support (3.13.1)
|
78
|
+
rubocop (1.65.0)
|
79
79
|
json (~> 2.3)
|
80
80
|
language_server-protocol (>= 3.17.0)
|
81
81
|
parallel (~> 1.10)
|
82
82
|
parser (>= 3.3.0.2)
|
83
83
|
rainbow (>= 2.2.2, < 4.0)
|
84
|
-
regexp_parser (>=
|
84
|
+
regexp_parser (>= 2.4, < 3.0)
|
85
85
|
rexml (>= 3.2.5, < 4.0)
|
86
|
-
rubocop-ast (>= 1.
|
86
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
87
87
|
ruby-progressbar (~> 1.7)
|
88
88
|
unicode-display_width (>= 2.4.0, < 3.0)
|
89
|
-
rubocop-ast (1.
|
90
|
-
parser (>= 3.
|
91
|
-
rubocop-capybara (2.
|
92
|
-
rubocop (~> 1.41)
|
93
|
-
rubocop-factory_bot (2.25.1)
|
89
|
+
rubocop-ast (1.31.3)
|
90
|
+
parser (>= 3.3.1.0)
|
91
|
+
rubocop-capybara (2.21.0)
|
94
92
|
rubocop (~> 1.41)
|
93
|
+
rubocop-factory_bot (2.26.1)
|
94
|
+
rubocop (~> 1.61)
|
95
95
|
rubocop-rake (0.6.0)
|
96
96
|
rubocop (~> 1.0)
|
97
|
-
rubocop-rspec (2.
|
97
|
+
rubocop-rspec (2.31.0)
|
98
98
|
rubocop (~> 1.40)
|
99
99
|
rubocop-capybara (~> 2.17)
|
100
100
|
rubocop-factory_bot (~> 2.22)
|
101
|
+
rubocop-rspec_rails (~> 2.28)
|
102
|
+
rubocop-rspec_rails (2.29.1)
|
103
|
+
rubocop (~> 1.61)
|
101
104
|
ruby-progressbar (1.13.0)
|
102
|
-
|
105
|
+
strscan (3.1.0)
|
103
106
|
tzinfo (2.0.6)
|
104
107
|
concurrent-ruby (~> 1.0)
|
105
108
|
unicode-display_width (2.5.0)
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Bp3::Core
|
2
2
|
|
3
|
-
bp3-core provides core concerns for the persuavis/black_phoebe_3 multi-site
|
3
|
+
bp3-core provides core concerns for BP3, the persuavis/black_phoebe_3 multi-site
|
4
|
+
multi-tenant rails application.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -38,10 +39,20 @@ In ActiveRecord models (or their base class) that are filtered/sorted with ransa
|
|
38
39
|
```ruby
|
39
40
|
include Bp3::Core::Ransackable
|
40
41
|
```
|
42
|
+
Then in your application's `config/initializers/bp3-core`, add:
|
43
|
+
```ruby
|
44
|
+
Bp3::Core::Ransackable.attribute_exceptions = %w[config config_id settable settable_id]
|
45
|
+
Bp3::Core::Ransackable.association_exceptions = %w[config settable]
|
46
|
+
```
|
41
47
|
In all ActiveRecord models (or their base class) with a request-id attribute :rqid, add:
|
42
48
|
```ruby
|
43
49
|
include Bp3::Core::Rqid
|
44
50
|
```
|
51
|
+
Then in your application's `config/initializers/bp3-core`, add:
|
52
|
+
```ruby
|
53
|
+
Bp3::Core::Rqid.global_request_state_class_name = 'GlobalRequestState'
|
54
|
+
Bp3::Core::Rqid.global_request_state_method = :request_id
|
55
|
+
```
|
45
56
|
In all ActiveRecord models (or their base class) with a sequence number attribute :sqnr, add:
|
46
57
|
```ruby
|
47
58
|
include Bp3::Core::Sqnr
|
@@ -50,12 +61,13 @@ To use :sqnr for record ordering for a particular model, use the class macro:
|
|
50
61
|
```ruby
|
51
62
|
use_sqnr_for_ordering
|
52
63
|
```
|
53
|
-
In all ActiveRecord models (or their base class) that use site, tenant and/or workspace
|
54
|
-
to be populated from global state, add:
|
64
|
+
In all ActiveRecord models (or their base class) that use site, tenant and/or workspace
|
65
|
+
attributes that need to be populated from global state, add:
|
55
66
|
```ruby
|
56
67
|
include Bp3::Core::Tenantable
|
57
68
|
```
|
58
69
|
The specific columns expected by `Tenantable` are:
|
70
|
+
|
59
71
|
- site: `sites_site_id`
|
60
72
|
- tenant: `tenant_id`
|
61
73
|
- workspace: `workspaces_workspace_id`
|
@@ -63,20 +75,21 @@ Tenantable will use reflection to determine which one(s) exist, and will create
|
|
63
75
|
|
64
76
|
## Development
|
65
77
|
|
66
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You
|
78
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You
|
79
|
+
can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
80
|
|
68
|
-
To install this gem onto your local machine, run `
|
81
|
+
To install this gem onto your local machine, run `rake install`. To release a new version,
|
82
|
+
update the version number in `version.rb`, and then run `rake release`, which will create a git
|
83
|
+
tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
84
|
|
70
85
|
## Testing
|
71
86
|
The `Bp3::Core::Test` class is for testing purposes.
|
72
87
|
|
88
|
+
Run `rake` to run rspec tests and rubocop linting.
|
89
|
+
|
73
90
|
## Documentation
|
74
91
|
A `.yardopts` file is provided to support yard documentation.
|
75
92
|
|
76
|
-
## Contributing
|
77
|
-
|
78
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/persuavis/bp3-core.
|
79
|
-
|
80
93
|
## License
|
81
94
|
|
82
95
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bp3-core.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Wim den Braven']
|
9
9
|
spec.email = ['wimdenbraven@persuavis.com']
|
10
10
|
|
11
|
-
spec.summary = 'bp3-core provides core concerns for black_phoebe_3.'
|
11
|
+
spec.summary = 'bp3-core provides core concerns for BP3 (persuavis/black_phoebe_3).'
|
12
12
|
# spec.description = "TODO: Write a longer description or delete this line."
|
13
13
|
spec.homepage = 'https://www.black-phoebe.com'
|
14
14
|
spec.license = 'MIT'
|
data/lib/bp3/core/actions.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Bp3
|
4
4
|
module Core
|
5
|
+
# rubocop:disable Metrics/ModuleLength
|
5
6
|
module Actions
|
6
7
|
extend ActiveSupport::Concern
|
7
8
|
|
@@ -36,16 +37,16 @@ module Bp3
|
|
36
37
|
private
|
37
38
|
|
38
39
|
def set_global_request_state
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
grsc.inbound_request = @global_request
|
41
|
+
grsc.current_user = current_user
|
42
|
+
grsc.current_admin = current_admin
|
43
|
+
grsc.current_root = current_root
|
44
|
+
grsc.locale = I18n.locale
|
45
|
+
grsc.view_context = view_context
|
45
46
|
end
|
46
47
|
|
47
48
|
def set_rqid
|
48
|
-
|
49
|
+
grsc.request_id = global_rqid
|
49
50
|
end
|
50
51
|
|
51
52
|
def global_rqid
|
@@ -84,7 +85,7 @@ module Bp3
|
|
84
85
|
|
85
86
|
def check_site
|
86
87
|
current_site || create_site
|
87
|
-
|
88
|
+
grsc.current_site = current_site
|
88
89
|
end
|
89
90
|
|
90
91
|
def current_site
|
@@ -100,7 +101,7 @@ module Bp3
|
|
100
101
|
# TODO: cache the workspace/regex list
|
101
102
|
def check_workspace
|
102
103
|
current_workspace || create_workspace
|
103
|
-
|
104
|
+
grsc.current_workspace = current_workspace
|
104
105
|
end
|
105
106
|
|
106
107
|
# TODO: move (some of) this into Workspace
|
@@ -127,7 +128,7 @@ module Bp3
|
|
127
128
|
|
128
129
|
def check_tenant
|
129
130
|
current_tenant || create_tenant
|
130
|
-
|
131
|
+
grsc.current_tenant = current_tenant
|
131
132
|
end
|
132
133
|
|
133
134
|
def current_tenant
|
@@ -161,7 +162,7 @@ module Bp3
|
|
161
162
|
end
|
162
163
|
|
163
164
|
def info_for_paper_trail
|
164
|
-
state =
|
165
|
+
state = grsc.new
|
165
166
|
{
|
166
167
|
rqid: global_rqid,
|
167
168
|
sites_site_id: state.current_site&.id,
|
@@ -187,7 +188,7 @@ module Bp3
|
|
187
188
|
end
|
188
189
|
|
189
190
|
def either_site
|
190
|
-
|
191
|
+
grsc.either_site
|
191
192
|
end
|
192
193
|
|
193
194
|
def check_site_mode
|
@@ -203,6 +204,11 @@ module Bp3
|
|
203
204
|
break
|
204
205
|
end
|
205
206
|
end
|
207
|
+
|
208
|
+
def grsc
|
209
|
+
@grsc ||= Bp3::Core::Rqid.global_request_state_class
|
210
|
+
end
|
206
211
|
end
|
212
|
+
# rubocop:enable Metrics/ModuleLength
|
207
213
|
end
|
208
214
|
end
|
data/lib/bp3/core/cookies.rb
CHANGED
@@ -64,11 +64,11 @@ module Bp3
|
|
64
64
|
return if cookie_value.blank? && do_not_track
|
65
65
|
|
66
66
|
sites_site_id, tenant_id, identification = cookie_value&.split('/')
|
67
|
-
if sites_site_id && sites_site_id !=
|
68
|
-
Rails.logger.warn { "check_visitor_cookie: site mismatch! (#{sites_site_id} and #{
|
67
|
+
if sites_site_id && sites_site_id != grsc.current_site.id
|
68
|
+
Rails.logger.warn { "check_visitor_cookie: site mismatch! (#{sites_site_id} and #{grsc.current_site.id}" }
|
69
69
|
end
|
70
|
-
if tenant_id && tenant_id !=
|
71
|
-
Rails.logger.warn { "check_visitor_cookie: tenant mismatch! (#{tenant_id} and #{
|
70
|
+
if tenant_id && tenant_id != grsc.current_tenant.id
|
71
|
+
Rails.logger.warn { "check_visitor_cookie: tenant mismatch! (#{tenant_id} and #{grsc.current_tenant.id}" }
|
72
72
|
end
|
73
73
|
visitor = Users::Visitor.find_by(sites_site_id:, tenant_id:, identification:)
|
74
74
|
if visitor.nil?
|
@@ -80,7 +80,7 @@ module Bp3
|
|
80
80
|
expires: 365.days.from_now
|
81
81
|
}
|
82
82
|
end
|
83
|
-
@current_visitor =
|
83
|
+
@current_visitor = grsc.current_visitor = visitor
|
84
84
|
Rails.logger.debug do
|
85
85
|
"check_visitor_cookie: cookie[#{visitor_cookie_name}]=#{cookies.signed[visitor_cookie_name]}"
|
86
86
|
end
|
@@ -93,8 +93,8 @@ module Bp3
|
|
93
93
|
return if cookie_value.blank? && do_not_track
|
94
94
|
|
95
95
|
identification = cookie_value
|
96
|
-
sites_site_id =
|
97
|
-
tenant_id =
|
96
|
+
sites_site_id = grsc.current_site_id
|
97
|
+
tenant_id = grsc.current_tenant_id
|
98
98
|
visitor = Users::Visitor.find_by(sites_site_id:, tenant_id:, identification:)
|
99
99
|
if visitor.nil?
|
100
100
|
visitor = create_visitor
|
@@ -105,7 +105,7 @@ module Bp3
|
|
105
105
|
expires: 365.days.from_now
|
106
106
|
}
|
107
107
|
end
|
108
|
-
@current_visitor =
|
108
|
+
@current_visitor = grsc.current_visitor = visitor
|
109
109
|
Rails.logger.debug do
|
110
110
|
"check_visitor_cookie: cookie[#{new_visitor_cookie_name}]=#{cookies.signed[new_visitor_cookie_name]}"
|
111
111
|
end
|
@@ -121,18 +121,18 @@ module Bp3
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def create_visitor
|
124
|
-
Users::Visitor.create!(sites_site:
|
125
|
-
tenant:
|
126
|
-
workspaces_workspace:
|
124
|
+
Users::Visitor.create!(sites_site: grsc.current_site,
|
125
|
+
tenant: grsc.current_tenant,
|
126
|
+
workspaces_workspace: grsc.current_workspace,
|
127
127
|
identification: SecureRandom.uuid)
|
128
128
|
end
|
129
129
|
|
130
130
|
def cookie_site_id
|
131
|
-
|
131
|
+
grsc.current_site.id[0..7]
|
132
132
|
end
|
133
133
|
|
134
134
|
def cookie_tenant_id
|
135
|
-
|
135
|
+
grsc.current_tenant.id[0..7]
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
data/lib/bp3/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bp3-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wim den Braven
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -179,5 +179,5 @@ requirements: []
|
|
179
179
|
rubygems_version: 3.5.11
|
180
180
|
signing_key:
|
181
181
|
specification_version: 4
|
182
|
-
summary: bp3-core provides core concerns for black_phoebe_3.
|
182
|
+
summary: bp3-core provides core concerns for BP3 (persuavis/black_phoebe_3).
|
183
183
|
test_files: []
|