Skip to content

Commit f818db9

Browse files
authored
Merge branch 'main' into feat/sync-status-reporting-569
2 parents d4f5fac + 834291b commit f818db9

10 files changed

Lines changed: 178 additions & 26 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gem "azure_file_shares"
99
gem "bcrypt", "~> 3.1.22"
1010
gem "bootsnap", require: false
1111
gem "csv"
12-
gem "herb", "~> 0.9.7"
12+
gem "herb", "~> 0.10.1"
1313
gem "image_processing", "~> 1.14"
1414
gem "importmap-rails"
1515
gem "inline_svg"

Gemfile.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ GEM
9191
activesupport (>= 6.0.0)
9292
ast (2.4.3)
9393
aws-eventstream (1.4.0)
94-
aws-partitions (1.1236.0)
95-
aws-sdk-core (3.244.0)
94+
aws-partitions (1.1245.0)
95+
aws-sdk-core (3.246.0)
9696
aws-eventstream (~> 1, >= 1.3.0)
9797
aws-partitions (~> 1, >= 1.992.0)
9898
aws-sigv4 (~> 1.9)
9999
base64
100100
bigdecimal
101101
jmespath (~> 1, >= 1.6.1)
102102
logger
103-
aws-sdk-kms (1.123.0)
103+
aws-sdk-kms (1.124.0)
104104
aws-sdk-core (~> 3, >= 3.244.0)
105105
aws-sigv4 (~> 1.5)
106-
aws-sdk-s3 (1.219.0)
106+
aws-sdk-s3 (1.221.0)
107107
aws-sdk-core (~> 3, >= 3.244.0)
108108
aws-sdk-kms (~> 1)
109109
aws-sigv4 (~> 1.5)
@@ -119,12 +119,12 @@ GEM
119119
bcrypt_pbkdf (1.1.2)
120120
bigdecimal (4.1.2)
121121
bindex (0.8.1)
122-
bootsnap (1.22.0)
122+
bootsnap (1.24.3)
123123
msgpack (~> 1.2)
124124
brakeman (8.0.4)
125125
racc
126126
builder (3.3.0)
127-
bullet (8.1.0)
127+
bullet (8.1.1)
128128
activesupport (>= 3.0.0)
129129
uniform_notifier (~> 1.11)
130130
capybara (3.40.0)
@@ -215,14 +215,14 @@ GEM
215215
rake (>= 13)
216216
googleapis-common-protos-types (1.22.0)
217217
google-protobuf (~> 4.26)
218-
herb (0.9.7-aarch64-linux-gnu)
219-
herb (0.9.7-aarch64-linux-musl)
220-
herb (0.9.7-arm-linux-gnu)
221-
herb (0.9.7-arm-linux-musl)
222-
herb (0.9.7-arm64-darwin)
223-
herb (0.9.7-x86_64-darwin)
224-
herb (0.9.7-x86_64-linux-gnu)
225-
herb (0.9.7-x86_64-linux-musl)
218+
herb (0.10.1-aarch64-linux-gnu)
219+
herb (0.10.1-aarch64-linux-musl)
220+
herb (0.10.1-arm-linux-gnu)
221+
herb (0.10.1-arm-linux-musl)
222+
herb (0.10.1-arm64-darwin)
223+
herb (0.10.1-x86_64-darwin)
224+
herb (0.10.1-x86_64-linux-gnu)
225+
herb (0.10.1-x86_64-linux-musl)
226226
hotwire-spark (0.1.13)
227227
listen
228228
rails (>= 7.0.0)
@@ -368,7 +368,7 @@ GEM
368368
opentelemetry-semantic_conventions (1.36.0)
369369
opentelemetry-api (~> 1.0)
370370
ostruct (0.6.3)
371-
ox (2.14.23)
371+
ox (2.14.25)
372372
bigdecimal (>= 3.0)
373373
pagy (43.3.0)
374374
json
@@ -397,7 +397,7 @@ GEM
397397
date
398398
stringio
399399
public_suffix (6.0.2)
400-
puma (7.2.0)
400+
puma (8.0.1)
401401
nio4r (~> 2.0)
402402
raabro (1.4.0)
403403
racc (1.8.1)
@@ -639,7 +639,7 @@ DEPENDENCIES
639639
dotenv-rails
640640
factory_bot_rails
641641
faker
642-
herb (~> 0.9.7)
642+
herb (~> 0.10.1)
643643
hotwire-spark
644644
image_processing (~> 1.14)
645645
importmap-rails

app/assets/tailwind/application.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,14 @@
6666
box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
6767
}
6868

69-
.input-field:hover:not(:focus) {
69+
.input-field:hover:not(:focus):not(:disabled) {
7070
@apply border-gray-400;
7171
}
7272

73+
.input-field:disabled {
74+
@apply bg-gray-100 text-gray-500;
75+
}
76+
7377
.select-field {
7478
@apply w-full border border-gray-300 rounded-lg text-sm bg-white transition-all duration-200 cursor-pointer;
7579
padding: 0.625rem 2.5rem 0.625rem 0.875rem;

app/models/provider.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,21 @@ class Provider < ApplicationRecord
2626

2727
validates :name, :provider_type, presence: true
2828
validates :name, uniqueness: true
29+
30+
validate :file_name_prefix_may_be_changed, on: :update, if: :file_name_prefix_changed?
31+
32+
def topics?
33+
topics.any?
34+
end
35+
36+
private
37+
38+
def file_name_prefix_may_be_changed
39+
if topics?
40+
errors.add(
41+
:file_name_prefix,
42+
"can't be changed as provider has associated topics and so file names are established"
43+
)
44+
end
45+
end
2946
end

app/views/providers/_form.html.erb

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
<div class="space-y-6">
33
<%= render "shared/errors", errors: provider.errors.full_messages, resource_name: provider.class.name %>
44

5+
<!-- File name prefix uneditable notice -->
6+
<% if @provider.topics? %>
7+
<div id="file-name-prefix-uneditable-notice" class="bg-blue-50 border border-blue-200 rounded-lg p-4">
8+
<div class="flex">
9+
<div class="flex-shrink-0">
10+
<svg class="h-5 w-5 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
11+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
12+
</svg>
13+
</div>
14+
<div class="ml-3">
15+
<p class="text-sm text-blue-700 m-0">
16+
There are topics associated with this provider, so the file names are established and the file name prefix can't be edited.
17+
</p>
18+
</div>
19+
</div>
20+
</div>
21+
<% end %>
22+
23+
524
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
625

726
<!-- Provider Name -->
@@ -11,7 +30,7 @@
1130
<span class="text-red-500">*</span>
1231
<% end %>
1332
<%= form.text_field :name,
14-
placeholder: "Enter provider name (e.g., Johns Hopkins, Mayo Clinic)",
33+
placeholder: "e.g., Johns Hopkins, Mayo Clinic",
1534
autofocus: true,
1635
class: "input-field bg-gray-50" %>
1736
<p class="help-text">The official name of the healthcare provider or organization.</p>
@@ -29,6 +48,31 @@
2948
<p class="help-text">The type or category of healthcare provider.</p>
3049
</div>
3150

51+
<!-- File name prefix -->
52+
<% if @provider.topics? %>
53+
<div>
54+
<%= form.label :file_name_prefix, class: "input-label" do %>
55+
File name prefix
56+
<% end %>
57+
<%= form.text_field :file_name_prefix,
58+
disabled: true,
59+
value: @provider.file_name_prefix,
60+
class: "input-field bg-gray-50"
61+
%>
62+
<p class="help-text">The prefix to use for this provider's uploads.</p>
63+
</div>
64+
<% else %>
65+
<div>
66+
<%= form.label :file_name_prefix, class: "input-label" do %>
67+
File name prefix
68+
<% end %>
69+
<%= form.text_field :file_name_prefix,
70+
placeholder: "e.g., 123_who_guidelines",
71+
class: "input-field bg-gray-50" %>
72+
<p class="help-text">The prefix to use for this provider's uploads.</p>
73+
</div>
74+
<% end %>
75+
3276
<!-- Regions -->
3377
<div>
3478
<%= form.label :region, class: "input-label" do %>

app/views/providers/show.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
</div>
8282

8383
<div class="card-body">
84-
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
84+
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
8585

8686
<div>
8787
<label class="input-label">Provider Name</label>
@@ -97,7 +97,7 @@
9797
</div>
9898
</div>
9999

100-
<div>
100+
<div class="col-span-full">
101101
<label class="input-label">File Name Prefix</label>
102102
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
103103
<% if @provider.file_name_prefix.present? %>

spec/jobs/documents_sync_job_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
require "rails_helper"
22

33
RSpec.describe DocumentsSyncJob, type: :job do
4-
let(:topic) { create(:topic, :with_documents) }
5-
let(:provider) { topic.provider }
4+
let(:provider) { create(:provider, file_name_prefix: "MyPrefix") }
5+
let(:topic) { create(:topic, :with_documents, provider:) }
66
let(:document) { topic.documents.first }
77
let(:file_name) { document.filename }
88

9-
before { provider.update(file_name_prefix: "MyPrefix") }
10-
119
describe "#perform" do
1210
let(:file_worker) { instance_double(FileWorker) }
1311

spec/models/provider_spec.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# == Schema Information
2+
#
3+
# Table name: providers
4+
# Database name: primary
5+
#
6+
# id :bigint not null, primary key
7+
# file_name_prefix :string
8+
# name :string
9+
# provider_type :string
10+
# created_at :datetime not null
11+
# updated_at :datetime not null
12+
# old_id :integer
13+
#
14+
# Indexes
15+
#
16+
# index_providers_on_old_id (old_id) UNIQUE
17+
#
18+
require "rails_helper"
19+
20+
RSpec.describe Provider, type: :model do
21+
let(:provider) { create(:provider) }
22+
subject { provider }
23+
24+
describe "validations" do
25+
it { should validate_presence_of(:provider_type) }
26+
it { should validate_presence_of(:name) }
27+
it { should validate_uniqueness_of(:name) }
28+
29+
describe "#file_name_prefix_may_be_changed" do
30+
context "when a provider has topics" do
31+
let!(:topic) { create(:topic, provider: provider) }
32+
33+
it "returns an error" do
34+
provider.file_name_prefix = "updated_prefix"
35+
expect(provider).not_to be_valid
36+
expect(provider.errors[:file_name_prefix]).to match_array(
37+
"can't be changed as provider has associated topics and so file names are established"
38+
)
39+
end
40+
end
41+
42+
context "when a provider has no topics" do
43+
it "does not return an error" do
44+
provider.file_name_prefix = "updated_prefix"
45+
expect(provider).to be_valid
46+
end
47+
end
48+
end
49+
end
50+
51+
describe "#topics?" do
52+
subject { provider.topics? }
53+
54+
context "when a provider has topics" do
55+
let!(:topic) { create(:topic, provider: provider) }
56+
57+
it { is_expected.to be(true) }
58+
end
59+
60+
context "when a provider has no topics" do
61+
it { is_expected.to be(false) }
62+
end
63+
end
64+
end

spec/views/providers/edit.html.erb_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,28 @@
1616
assert_select "input[type='submit'][value='Update Provider']"
1717
end
1818
end
19+
20+
context "when the provider has associated topics" do
21+
before { create(:topic, provider: provider) }
22+
23+
it "tells the user that the File name prefix can't be changed" do
24+
render
25+
26+
assert_select "form[action=?][method=?]", provider_path(provider), "post" do
27+
assert_select "input[name=?][disabled]", "provider[file_name_prefix]"
28+
end
29+
30+
assert_select "div#file-name-prefix-uneditable-notice"
31+
end
32+
end
33+
34+
context "when the provider that has no associated topics" do
35+
it "has the File name prefix field" do
36+
render
37+
38+
assert_select "form[action=?][method=?]", provider_path(provider), "post" do
39+
assert_select "input[name=?]", "provider[file_name_prefix]"
40+
end
41+
end
42+
end
1943
end

spec/views/providers/new.html.erb_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
assert_select "form[action=?][method=?]", providers_path, "post" do
1515
assert_select "input[name=?]", "provider[name]"
1616
assert_select "input[name=?]", "provider[provider_type]"
17+
assert_select "input[name=?]", "provider[file_name_prefix]"
1718
assert_select "input[type='submit'][value='Create Provider']"
1819
end
1920
end

0 commit comments

Comments
 (0)