Skip to content

Commit 043fd86

Browse files
committed
merged master
2 parents 06e3929 + 49655ec commit 043fd86

24 files changed

+233
-17
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ DEVISE_JWT_SECRET_KEY=9dde7c3cebc4c85e91a6f6e520b683396cd4f0d218671f4f2a398f2b6f
1919
# STRIPE_TAX_RATE_ID=
2020
#
2121
# FRONTEND_URL=
22+
# IRIS_EPS_URL=

.env.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
STRIPE_SUBSCRIPTION_PRICE_ID=test_price
2-
HAPPY_PDF_API_KEY=HAPPY_KEY
2+
HAPPY_PDF_API_KEY=HAPPY_KEY
3+
IRIS_EPS_URL=https://localhost:5556/jsonrpc

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ gem 'activestorage-validator'
2222
gem 'image_processing'
2323
gem 'paper_trail'
2424
gem 'protobuf'
25+
gem 'jimson'
2526

2627
# Emails
2728
gem 'mailgun-ruby', '~> 1.2'

Gemfile.lock

+8
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ GEM
9393
aws-sigv4 (1.2.3)
9494
aws-eventstream (~> 1, >= 1.0.2)
9595
bcrypt (3.1.16)
96+
blankslate (3.1.3)
9697
bootsnap (1.7.5)
9798
msgpack (~> 1.0)
9899
builder (3.2.4)
@@ -181,6 +182,11 @@ GEM
181182
interactor-rails (2.2.1)
182183
interactor (~> 3.0)
183184
rails (>= 4.2)
185+
jimson (0.13.0)
186+
blankslate (>= 3.1.3)
187+
multi_json (>= 1.11.2)
188+
rack (>= 1.4.5)
189+
rest-client (>= 1.7.3)
184190
jmespath (1.4.0)
185191
jquery-rails (4.4.0)
186192
rails-dom-testing (>= 1, < 3)
@@ -226,6 +232,7 @@ GEM
226232
mini_portile2 (2.5.1)
227233
minitest (5.14.4)
228234
msgpack (1.4.2)
235+
multi_json (1.15.0)
229236
multi_xml (0.6.0)
230237
multipart-post (2.1.1)
231238
nested_form (0.3.2)
@@ -423,6 +430,7 @@ DEPENDENCIES
423430
image_processing
424431
inky-rb
425432
interactor-rails
433+
jimson
426434
letter_opener
427435
listen (~> 3.5)
428436
mailgun-ruby (~> 1.2)

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,19 @@ Install rcvr-app frontend: https://github.com/railslove/rcvr-app
7070
Create a frontend entry in your postgres database:
7171

7272
```
73-
docker-compose exec postgres psql -U postgres`
74-
postgres=# insert into frontends (name, url) values('App-Local', 'http://localhost:3333');
73+
docker-compose exec postgres psql -U postgres
74+
postgres=# \connect rcvr_api_development
75+
rcvr_api_development=# insert into frontends (name, url) values('App-Local', 'http://localhost:3333');
7576
```
7677

7778
Your port might vary depending on your set up (see rcvr-app README).
7879

80+
You should also update the frontend .env.local to match your backends local url:
81+
82+
NEXT_PUBLIC_API_BASE=http://api.localhost:3000
83+
84+
for local development the http://api. prefix is mandatory
85+
7986
### Deployment
8087

8188
- `origin/master` deploys to production on push

app/controllers/owners/areas_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def area
5454
end
5555

5656
def area_params
57-
params.require(:area).permit(:name)
57+
params.require(:area).permit(:name, :test_exemption)
5858
end
5959
end
6060
end

app/controllers/owners/companies_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def stats
3434
company = @owner.companies.find(params[:company_id])
3535

3636
stats = company.areas.map do |area|
37-
{ area_name: area.name, checkin_count: area.tickets.open.count }
37+
{ area_name: area.name, area_test_exemption: area.test_exemption, checkin_count: area.tickets.open.count }
3838
end
3939

4040
render json: stats

app/jobs/iris_delete_company.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class IrisDeleteCompany < ApplicationJob
2+
queue_as :default
3+
4+
def perform(company_id)
5+
return if ENV["IRIS_EPS_URL"].blank?
6+
Jimson::Client.new(
7+
ENV["IRIS_EPS_URL"], {id_type: :string}, "ls-1.", {verify_ssl: false}
8+
).deleteLocationFromSearchIndex({
9+
locationId: company_id
10+
})
11+
end
12+
end

app/jobs/iris_update_company.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class IrisUpdateCompany < ApplicationJob
2+
queue_as :default
3+
4+
def perform(company_id)
5+
return if ENV["IRIS_EPS_URL"].blank?
6+
7+
company = Company.find(company_id)
8+
return unless company
9+
10+
Jimson::Client.new(
11+
ENV["IRIS_EPS_URL"], {id_type: :string}, "ls-1.", {verify_ssl: false}
12+
).postLocationsToSearchIndex({
13+
locations: [
14+
{
15+
id: company.id,
16+
name: company.name,
17+
contact: {
18+
officalName: company.name,
19+
representative: company.owner.name,
20+
address: {
21+
street: company.street,
22+
city: company.city,
23+
zip: company.zip
24+
},
25+
email: company.owner.email,
26+
phone: company.owner.phone
27+
}
28+
}
29+
]
30+
})
31+
end
32+
end

app/models/affiliate.rb

+4
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ def link
2727
def owner_count
2828
Owner.where(affiliate: self.code).count
2929
end
30+
31+
def company_count
32+
Company.joins(:owner).where(owners: {affiliate: self.code}).count
33+
end
3034
end

app/models/area.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Area < ApplicationRecord
22
include ApiSerializable
33
include RailsAdminConfig::ForArea
44

5-
EXPOSED_ATTRIBUTES = %i[id name menu_link checkin_link company_id company_name company_need_to_show_corona_test company_cwa_link_enabled affiliate_logo owner_is_blocked menu_alias frontend_url public_key privacy_policy_link]
5+
EXPOSED_ATTRIBUTES = %i[id name menu_link checkin_link company_id company_name company_need_to_show_corona_test company_cwa_link_enabled affiliate_logo owner_is_blocked menu_alias frontend_url public_key privacy_policy_link test_exemption].freeze
66

77
belongs_to :company
88
has_many :tickets, dependent: :destroy

app/models/company.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,32 @@ class Company < ApplicationRecord
4848
delegate :menu_alias, :frontend_url, :public_key, to: :owner
4949
delegate :affiliate_logo, to: :owner
5050
delegate :auto_checkout_time, to: :owner
51-
delegate :affiliate, to: :owner
51+
delegate :affiliate, to: :owner, allow_nil: true
5252

5353
attr_accessor :remove_menu_pdf
5454

5555
before_update {
5656
menu_pdf.purge if remove_menu_pdf == '1' and menu_pdf.attached?
5757
}
5858

59+
after_commit(on: [:create, :update]) {
60+
IrisUpdateCompany.perform_later(self.id)
61+
}
62+
63+
after_commit(on: [:destroy]) {
64+
IrisDeleteCompany.perform_later(self.id)
65+
}
66+
5967
def menu_pdf_link
6068
return unless menu_pdf.attached?
6169

6270
url_for(menu_pdf)
6371
end
6472

6573
def stats_url
66-
owners_company_stats_url(self)
74+
if self.id
75+
owners_company_stats_url(self)
76+
end
6777
end
6878

6979
def open_ticket_count

app/models/concerns/rails_admin_config/for_affiliate.rb

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ module ForAffiliate
1515
path = bindings[:view].index_path(model_name: 'Owner')
1616
bindings[:view].link_to(bindings[:object].owner_count, "#{path}?f[affiliate][1][o]=is&f[affiliate][1][v]=#{ERB::Util.url_encode(bindings[:object].code)}")
1717
end
18+
read_only true
19+
end
20+
field :companies_count do
21+
label "Companies"
22+
formatted_value do
23+
bindings[:object].company_count
24+
end
25+
read_only true
1826
end
1927
fields :stripe_price_id_monthly, :custom_trial_phase, :logo_link
2028

config/initializers/rest-client.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require "rest-client"
2+
3+
RestClient.proxy = ENV["QUOTAGUARDSTATIC_URL"] if ENV["QUOTAGUARDSTATIC_URL"].present?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class ChangeCoronatestoptions < ActiveRecord::Migration[6.1]
2+
def up
3+
execute "
4+
ALTER TABLE companies ALTER need_to_show_corona_test SET DEFAULT null;
5+
ALTER TABLE companies
6+
ALTER need_to_show_corona_test TYPE INTEGER
7+
USING
8+
CASE
9+
WHEN true THEN 48 ELSE 0
10+
end;
11+
"
12+
end
13+
14+
def down
15+
execute "
16+
ALTER TABLE companies ALTER COLUMN need_to_show_corona_test TYPE BOOL USING need_to_show_corona_test::boolean;
17+
"
18+
end
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddExceptionAreas < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :areas, :test_exemption, :boolean, default: false
4+
end
5+
end

db/schema.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
t.datetime "updated_at", precision: 6, null: false
5858
t.string "name"
5959
t.uuid "company_id"
60+
t.boolean "test_exemption", default: false
6061
t.index ["company_id"], name: "index_areas_on_company_id"
6162
end
6263

@@ -71,7 +72,7 @@
7172
t.string "street"
7273
t.string "zip"
7374
t.string "city"
74-
t.boolean "need_to_show_corona_test", default: false
75+
t.integer "need_to_show_corona_test"
7576
t.integer "location_type", default: 0
7677
t.boolean "cwa_link_enabled", default: false
7778
t.string "cwa_crypto_seed"

spec/factories/area.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FactoryBot.define do
22
factory :area do
33
name { Faker::FunnyName.name }
4-
4+
test_exemption { true }
55
company
66
end
77
end

spec/jobs/iris_delete_company_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe IrisDeleteCompany, type: :job do
4+
5+
it "should send a delete request via JSON-RPC" do
6+
company = FactoryBot.create(:company)
7+
expect_any_instance_of(Jimson::ClientHelper).to receive(:process_call).with(:deleteLocationFromSearchIndex, {
8+
locationId: company.id
9+
})
10+
IrisDeleteCompany.perform_now(company.id)
11+
end
12+
end

spec/jobs/iris_update_company_spec.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
require 'rails_helper'
3+
4+
RSpec.describe IrisUpdateCompany, type: :job do
5+
6+
it "should send a update request via JSON-RPC" do
7+
company = FactoryBot.create(:company)
8+
expect_any_instance_of(Jimson::ClientHelper).to receive(:process_call).with(:postLocationsToSearchIndex, {
9+
locations: [
10+
{
11+
id: company.id,
12+
name: company.name,
13+
contact: {
14+
officalName: company.name,
15+
representative: company.owner.name,
16+
address: {
17+
street: company.street,
18+
city: company.city,
19+
zip: company.zip
20+
},
21+
email: company.owner.email,
22+
phone: company.owner.phone
23+
}
24+
}
25+
]
26+
})
27+
IrisUpdateCompany.perform_now(company.id)
28+
end
29+
end

spec/models/affiliate_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,31 @@
2121
end
2222
end
2323
end
24+
25+
describe "owner_count" do
26+
let(:affiliate) { FactoryBot.create(:affiliate) }
27+
28+
it "should return the correct owner count" do
29+
FactoryBot.create(:owner, affiliate: affiliate.code)
30+
FactoryBot.create(:owner, affiliate: affiliate.code)
31+
FactoryBot.create(:owner)
32+
33+
expect(affiliate.owner_count).to eql 2
34+
end
35+
end
36+
37+
describe "company_count" do
38+
let(:affiliate) { FactoryBot.create(:affiliate) }
39+
40+
it "should return the correct owner count" do
41+
owner1 = FactoryBot.create(:owner, affiliate: affiliate.code)
42+
owner2 = FactoryBot.create(:owner, affiliate: affiliate.code)
43+
FactoryBot.create(:company, owner: owner1)
44+
FactoryBot.create(:company, owner: owner1)
45+
FactoryBot.create(:company, owner: owner2)
46+
FactoryBot.create(:company)
47+
48+
expect(affiliate.company_count).to eql 3
49+
end
50+
end
2451
end

spec/models/company_spec.rb

+29
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,33 @@
2727
end
2828

2929
end
30+
31+
describe "affiliate=" do
32+
it 'should update the affiliate code in the owner' do
33+
company = FactoryBot.create(:company)
34+
company.affiliate = "awesome-code"
35+
expect(company.owner.affiliate).to eql("awesome-code")
36+
end
37+
end
38+
39+
describe 'updates IRIS on create/update' do
40+
it 'should schedule a job for creates' do
41+
expect(IrisUpdateCompany).to receive(:perform_later)
42+
FactoryBot.create(:company)
43+
end
44+
45+
it 'should schedule a job for updates' do
46+
company = FactoryBot.create(:company)
47+
expect(IrisUpdateCompany).to receive(:perform_later).with(company.id)
48+
company.update(name: "IRIS Update Name")
49+
end
50+
end
51+
52+
describe 'informs IRIS about destroy' do
53+
it 'should schedule a job for destroys' do
54+
company = FactoryBot.create(:company)
55+
expect(IrisDeleteCompany).to receive(:perform_later).with(company.id)
56+
company.destroy
57+
end
58+
end
3059
end

spec/requests/owners/area_request_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@
4444
let!(:area) { FactoryBot.create(:area, company: company) }
4545

4646
subject do
47-
-> { patch(owners_area_path(area), params: { area: { name: 'New Name' } }) }
47+
-> { patch(owners_area_path(area), params: { area: { test_exemption: true, name: 'New Name' } }) }
4848
end
4949

5050
it { is_expected.to change { area.reload.name }.to('New Name') }
5151

52+
it { expect(area.reload.test_exemption).to eq(true) }
53+
5254
it 'renders the area' do
5355
subject.call
5456

0 commit comments

Comments
 (0)