aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-01-16 17:24:12 +0100
committerTeddy Wing2018-01-16 17:24:12 +0100
commit93b60066cc49d699171d6a50798c5939a4644eea (patch)
tree309fe6039fb1881cac5360c80661548eb36e182e
parentb1c55750bb43736c2cb6f9619bddc453cfadb1aa (diff)
downloadchouette-core-93b60066cc49d699171d6a50798c5939a4644eea.tar.bz2
workbenches/show: Filter referentials by workgroup
Previously, all `Referential`s would be listed on this page if they had matching line metadata. Now, we exclude those referentials that are in other workgroups to ensure users don't see referentials they're not supposed to see. Refs #5592
-rw-r--r--app/models/workbench.rb7
-rw-r--r--app/models/workgroup.rb1
-rw-r--r--spec/features/workbenches/workbenches_show_spec.rb42
3 files changed, 49 insertions, 1 deletions
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index f49f4e7cf..b80fa64ac 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -31,7 +31,12 @@ class Workbench < ActiveRecord::Base
if line_ids.empty?
Referential.none
else
- Referential.joins(:metadatas).where(['referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids]).ready.not_in_referential_suite
+ workgroup
+ .referentials
+ .joins(:metadatas)
+ .where(['referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids])
+ .ready
+ .not_in_referential_suite
end
end
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
index 511bbfeb0..3d761e81f 100644
--- a/app/models/workgroup.rb
+++ b/app/models/workgroup.rb
@@ -4,6 +4,7 @@ class Workgroup < ActiveRecord::Base
has_many :workbenches
has_many :organisations, through: :workbenches
+ has_many :referentials, through: :workbenches
validates_uniqueness_of :name
diff --git a/spec/features/workbenches/workbenches_show_spec.rb b/spec/features/workbenches/workbenches_show_spec.rb
index 2b215bb03..7be813b94 100644
--- a/spec/features/workbenches/workbenches_show_spec.rb
+++ b/spec/features/workbenches/workbenches_show_spec.rb
@@ -22,6 +22,48 @@ RSpec.describe 'Workbenches', type: :feature do
end
end
+ it 'lists referentials in the current workgroup' do
+ other_workbench = create(
+ :workbench,
+ line_referential: line_ref,
+ workgroup: workbench.workgroup
+ )
+ other_referential = create(
+ :workbench_referential,
+ workbench: other_workbench,
+ organisation: other_workbench.organisation,
+ metadatas: [
+ create(
+ :referential_metadata,
+ lines: [create(:line, line_referential: line_ref)]
+ )
+ ]
+ )
+
+ hidden_referential = create(
+ :workbench_referential,
+ workbench: create(
+ :workbench,
+ line_referential: line_ref
+ ),
+ metadatas: [
+ create(
+ :referential_metadata,
+ lines: [create(:line, line_referential: line_ref)]
+ )
+ ]
+ )
+
+ visit workbench_path(workbench)
+
+ expect(page).to have_content(referential.name),
+ "Couldn't find `referential`: `#{referential.inspect}`"
+ expect(page).to have_content(other_referential.name),
+ "Couldn't find `other_referential`: `#{other_referential.inspect}`"
+ expect(page).to_not have_content(hidden_referential.name),
+ "Couldn't find `hidden_referential`: `#{hidden_referential.inspect}`"
+ end
+
context 'filtering' do
let!(:another_organisation) { create :organisation }
let(:another_line) { create :line, line_referential: line_ref }