Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ def set_default_ethical_approval
self.ethically_approved ||= ethical_approval_required? ? false : nil
end

# rubocop:disable Metrics/ClassLength
class Metadata
delegate :enforce_data_release, to: :study

Expand Down Expand Up @@ -720,37 +719,6 @@ def delay_until_publication?

validate :sanity_check_y_separation, if: :separate_y_chromosome_data?

validates :data_release_timing, inclusion: { in: DATA_RELEASE_TIMINGS }, if: :data_release_strategy_must_be_managed?
validates :data_release_timing,
inclusion: {
in: [DATA_RELEASE_TIMING_NEVER]
},
if: :data_release_timing_must_be_never?

validates :data_release_timing,
inclusion: {
in: DATA_RELEASE_TIMINGS + [DATA_RELEASE_TIMING_PUBLICATION]
},
if: :data_release_timing_must_be_open?

def data_release_timing_must_be_never?
Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
strategy_not_applicable?
end

def data_release_timing_must_not_be_never?
Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
!strategy_not_applicable?
end

def data_release_timing_must_be_open?
Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? && open?
end

def data_release_strategy_must_be_managed?
Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? && managed?
end

def sanity_check_y_separation
if remove_x_and_autosomes?
errors.add(:separate_y_chromosome_data, 'cannot be selected with remove x and autosomes.')
Expand Down Expand Up @@ -817,5 +785,4 @@ def snp_child_studies
self.class.where(snp_parent_study_id: snp_study_id).includes(:study).map(&:study)
end
end
# rubocop:enable Metrics/ClassLength
end
2 changes: 0 additions & 2 deletions config/feature_flags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
# dpl202_enable_angry_cat_feature: When enabled this will add an angry cat to all pages that will try to catch the mouse pointer
# The key should be lower case and snake case, and prefixed with the issue number to allow easy identification
dpl_395_2_enable_advanced_search_tab: Shows the Search tab in the top navigation bar
# Below is flagged off until some existing data that would violate the rule is fixed. Should be re-enabled in Y24-058.
y24_052_enable_data_release_timing_validation: Enables server-side validation that enforces a relationship between the values of two study metadata fields

y25_442_make_api_key_mandatory: Makes API key mandatory for all API requests
136 changes: 0 additions & 136 deletions spec/models/study_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -697,32 +697,6 @@
it 'will have a dac_policy_title' do
expect(study.study_metadata.dac_policy_title).to eq(metadata[:dac_policy_title])
end

context 'when the data_release_timing validation is switched on' do
before { Flipper.enable :y24_052_enable_data_release_timing_validation }

it 'errors if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = 'never'

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).to include(
/Study metadata data release timing is not included in the list/
)
end
end

context 'when the data_release_timing validation is switched off' do
before { Flipper.disable :y24_052_enable_data_release_timing_validation }

it 'does not error if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = 'never'

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).not_to include(/data release timing/)
end
end
end

context 'open study' do
Expand All @@ -734,32 +708,6 @@
)
end

context 'when the data_release_timing validation is switched on' do
before { Flipper.enable :y24_052_enable_data_release_timing_validation }

it 'errors if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).to include(
/Study metadata data release timing is not included in the list/
)
end
end

context 'when the data_release_timing validation is switched off' do
before { Flipper.disable :y24_052_enable_data_release_timing_validation }

it 'does not error if the data_release_timing is invalid' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).not_to include(/data release timing/)
end
end

context 'when delay until publication is selected' do
let(:study) do
create(
Expand Down Expand Up @@ -855,90 +803,6 @@
metadata[:data_release_prevention_other_comment]
)
end

context 'when the data_release_timing validation is switched on' do
before { Flipper.enable :y24_052_enable_data_release_timing_validation }

it 'errors if the data_release_timing is standard' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_STANDARD

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).to include(
/Study metadata data release timing is not included in the list/
)
end

it 'errors if the data_release_timing is immediate' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_IMMEDIATE

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).to include(
/Study metadata data release timing is not included in the list/
)
end

it 'errors if the data_release_timing is delayed' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_DELAYED
study.study_metadata.data_release_delay_reason = Study::DATA_RELEASE_DELAY_REASONS_STANDARD[0]
study.study_metadata.data_release_delay_period = Study::DATA_RELEASE_DELAY_PERIODS[0]
study.study_metadata.data_release_delay_approval = Study::YES

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).to include(
/Study metadata data release timing is not included in the list/
)
end

it 'is valid if the data_release_timing is never' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).not_to include(/data release timing/)
end
end

context 'when the data_release_timing validation is switched off' do
before { Flipper.disable :y24_052_enable_data_release_timing_validation }

it 'does not error if the data_release_timing is standard' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_STANDARD

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).not_to include(/data release timing/)
end

it 'does not error if the data_release_timing is immediate' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_IMMEDIATE

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).not_to include(/data release timing/)
end

it 'does not error if the data_release_timing is delayed' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_DELAYED
study.study_metadata.data_release_delay_reason = Study::DATA_RELEASE_DELAY_REASONS_STANDARD[0]
study.study_metadata.data_release_delay_period = Study::DATA_RELEASE_DELAY_PERIODS[0]
study.study_metadata.data_release_delay_approval = Study::YES

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).not_to include(/data release timing/)
end

it 'is still valid if the data_release_timing is never' do
study.study_metadata.data_release_timing = Study::DATA_RELEASE_TIMING_NEVER

study.save # Don't raise exceptions, we only want to check for validation error messages.

expect(study.errors.full_messages).not_to include(/data release timing/)
end
end
end
end

Expand Down
Loading