Skip to content

Commit

Permalink
Make unauthorized samples hidden.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin De Pelseneer committed Oct 16, 2023
1 parent 9dff887 commit 4bcb006
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
11 changes: 9 additions & 2 deletions app/assets/javascripts/single_page/dynamic_table.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ const handleSelect = (e) => {
if (c.multi_link) {
data = data && Array.isArray(data) ? data : [data];
data = data[0]?.id ? data : [];
const existingOptions = data.map((e) => `<option selected="selected" title="ID: ${e.id}" value="${e.id}">${e.title}</option>`).join("");
const existingOptions = data.map((e) => {
isHiddenInput = (e.title == '#HIDDEN')
if (isHiddenInput) {
return `<option selected="selected" title="ID: hidden" value="hidden">hidden</option>`
} else {
return `<option selected="selected" title="ID: ${e.id}" value="${e.id}">${e.title}</option>`
}
}).join("");
if (options.readonly) {
return data.map((e) => `<span title="ID: ${e.id}" class="badge">${e.title}</span>`).join(" ");
} else {
Expand All @@ -61,7 +68,7 @@ const handleSelect = (e) => {
const linkedSamples = retrieveLinkedSamples(url);
const linkedSampleIds = linkedSamples.map((ls) => ls.id);
const unLinkedSamples = data.reduce(function(filtered, sample) {
if(!linkedSampleIds.includes(parseInt(sample.id))){
if(!linkedSampleIds.includes(parseInt(sample.id)) && sample.title != '#HIDDEN'){
filtered.push(sample);
}
return filtered;
Expand Down
30 changes: 25 additions & 5 deletions app/helpers/dynamic_table_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,34 @@ def link_sequence(sample_type)

def dt_rows(sample_type)
sample_type.samples.map do |s|
if s.can_view?
['', s.id, s.uuid] +
JSON(s.json_metadata).values
else
['', '#HIDDEN', '#HIDDEN'] +
if s.can_view?
sanitized_json_metadata = hide_unauthorized_inputs(JSON(s.json_metadata))
['', s.id, s.uuid] +
sanitized_json_metadata.values
else
['', '#HIDDEN', '#HIDDEN'] +
Array.new(JSON(s.json_metadata).length, '#HIDDEN')
end
end
end

def hide_unauthorized_inputs(json_metadata)
input_key = json_metadata.keys.detect { |jmdk| jmdk.downcase.include? 'input' }

unless input_key.nil?
json_metadata[input_key] = json_metadata[input_key].map do |input|
input_exists = Sample.where(id: input['id']).any?
if !input_exists
input
elsif Sample.find(input['id']).can_view?
input
else
{ 'id' => input['id'], 'type' => input['type'], 'title' => '#HIDDEN' }
end
end
end

json_metadata
end

def dt_cols(sample_type)
Expand Down

0 comments on commit 4bcb006

Please sign in to comment.