Skip inaccessible elements when generating reports [SCI-6109] (#3569)

This commit is contained in:
artoscinote 2021-10-01 14:18:40 +02:00 committed by GitHub
parent 4f4ab05740
commit 63923f0e63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View file

@ -2,8 +2,16 @@
module ReportsHelper module ReportsHelper
include StringUtility include StringUtility
include Canaid::Helpers::PermissionsHelper
def render_report_element(element, provided_locals = nil) def render_report_element(element, provided_locals = nil)
case element.type_of
when 'experiment'
return unless can_read_experiment?(element.report.user, element.experiment)
when 'my_module'
return unless can_read_my_module?(element.report.user, element.my_module)
end
# Determine partial # Determine partial
view = "reports/elements/#{element.type_of}_element.html.erb" view = "reports/elements/#{element.type_of}_element.html.erb"

View file

@ -68,7 +68,7 @@ module ReportActions
def generate_experiment_content(experiment_id, my_module_ids) def generate_experiment_content(experiment_id, my_module_ids)
experiment = Experiment.find_by(id: experiment_id) experiment = Experiment.find_by(id: experiment_id)
return if !experiment && !can_read_experiment?(@user, experiment) return unless experiment && can_read_experiment?(@user, experiment)
experiment_element = save_element!({ 'experiment_id' => experiment.id }, :experiment, nil) experiment_element = save_element!({ 'experiment_id' => experiment.id }, :experiment, nil)
generate_my_modules_content(experiment, experiment_element, my_module_ids) generate_my_modules_content(experiment, experiment_element, my_module_ids)
@ -79,6 +79,8 @@ module ReportActions
.active .active
.where(id: my_module_ids) .where(id: my_module_ids)
my_modules.sort_by { |m| my_module_ids.index m.id }.each do |my_module| my_modules.sort_by { |m| my_module_ids.index m.id }.each do |my_module|
next unless can_read_my_module?(@user, my_module)
my_module_element = save_element!({ 'my_module_id' => my_module.id }, :my_module, experiment_element) my_module_element = save_element!({ 'my_module_id' => my_module.id }, :my_module, experiment_element)
@repositories.each do |repository| @repositories.each do |repository|

View file

@ -7,7 +7,7 @@ module Reports::Docx::DrawMyModule
scinote_url = @scinote_url scinote_url = @scinote_url
my_module = subject.my_module my_module = subject.my_module
tags = my_module.tags tags = my_module.tags
return unless can_read_experiment?(@user, my_module.experiment) return unless can_read_my_module?(@user, my_module)
@docx.h3 my_module.name, italic: false, size: Constants::REPORT_DOCX_MY_MODULE_TITLE_SIZE @docx.h3 my_module.name, italic: false, size: Constants::REPORT_DOCX_MY_MODULE_TITLE_SIZE
@docx.p do @docx.p do