diff --git a/app/controllers/isa_assays_controller.rb b/app/controllers/isa_assays_controller.rb
index dbf1ce9807..b343b2b2d4 100644
--- a/app/controllers/isa_assays_controller.rb
+++ b/app/controllers/isa_assays_controller.rb
@@ -212,7 +212,9 @@ def find_requested_item
end
if @isa_assay.errors.any?
- error_messages = @isa_assay.errors.full_messages.map { |msg| "
[#{t('isa_assay')}]: #{msg}" }.join('')
+ error_messages = @isa_assay.errors.map do |error|
+ "[#{error.attribute.to_s}]: #{error.message}"
+ end.join('')
flash[:error] = "".html_safe
redirect_to single_page_path(id: @isa_assay.assay.projects.first, item_type: 'assay',
item_id: @isa_assay.assay)
diff --git a/app/controllers/isa_studies_controller.rb b/app/controllers/isa_studies_controller.rb
index 990169a543..791575e4d2 100644
--- a/app/controllers/isa_studies_controller.rb
+++ b/app/controllers/isa_studies_controller.rb
@@ -36,12 +36,7 @@ def create
end
def edit
- @isa_study.source = nil unless requested_item_authorized?(@isa_study.source)
- @isa_study.sample_collection = nil unless requested_item_authorized?(@isa_study.sample_collection)
-
- respond_to do |format|
- format.html
- end
+ respond_to(&:html)
end
def update
@@ -132,8 +127,20 @@ def set_up_instance_variable
def find_requested_item
@isa_study = IsaStudy.new
@isa_study.populate(params[:id])
- unless requested_item_authorized?(@isa_study.study)
- flash[:error] = "You are not authorized to edit this #{t('isa_study')}"
+
+ @isa_study.errors.add(:study, "The #{t('isa_study')} was not found.") if @isa_study.study.nil?
+ @isa_study.errors.add(:study, "You are not authorized to edit this #{t('isa_study')}.") unless requested_item_authorized?(@isa_study.study)
+
+ @isa_study.errors.add(:sample_type, "'Study source' #{t('sample_type')} not found.") if @isa_study.source.nil?
+ @isa_study.errors.add(:sample_type, "You are not authorized to edit the 'study source' #{t('sample_type')}.") unless requested_item_authorized?(@isa_study.source)
+ @isa_study.errors.add(:sample_type, "'Study sample' #{t('sample_type')} not found.") if @isa_study.sample_collection.nil?
+ @isa_study.errors.add(:sample_type, "You are not authorized to edit the 'study sample' #{t('sample_type')}.") unless requested_item_authorized?(@isa_study.sample_collection)
+
+ if @isa_study.errors.any?
+ error_messages = @isa_study.errors.map do |error|
+ "[#{error.attribute.to_s}]: #{error.message}"
+ end.join('')
+ flash[:error] = "".html_safe
redirect_to single_page_path(id: @isa_study.study.projects.first, item_type: 'study',
item_id: @isa_study.study)
end