Skip to content

Commit

Permalink
Merge branch 'main' into digital-research-hub
Browse files Browse the repository at this point in the history
  • Loading branch information
somathias committed Feb 13, 2024
2 parents abd7ca4 + f3647e4 commit 2294395
Show file tree
Hide file tree
Showing 68 changed files with 1,482 additions and 238 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gem 'will_paginate', '~> 3.1'
gem 'yaml_db'
gem 'rails_autolink'
gem 'rfc-822'
gem 'nokogiri', '~> 1.14.3'
gem 'nokogiri', '~> 1.16.2'
#necessary for newer hashie dependency, original api_smith is no longer active
gem 'api_smith', git: 'https://github.com/youroute/api_smith.git', ref: '1fb428cebc17b9afab25ac9f809bde87b0ec315b'
gem 'rdf-virtuoso', '>= 0.2.0'
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ GEM
nokogiri (~> 1)
rake
mini_mime (1.1.5)
mini_portile2 (2.8.4)
mini_portile2 (2.8.5)
minitest (5.20.0)
minitest-reporters (1.5.0)
ansi
Expand Down Expand Up @@ -492,8 +492,8 @@ GEM
net-protocol
netrc (0.11.0)
nio4r (2.7.0)
nokogiri (1.14.5)
mini_portile2 (~> 2.8.0)
nokogiri (1.16.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nori (1.1.5)
oauth2 (2.0.9)
Expand Down Expand Up @@ -566,7 +566,7 @@ GEM
puma (5.6.8)
nio4r (~> 2.0)
pyu-ruby-sasl (0.0.3.3)
racc (1.7.1)
racc (1.7.3)
rack (2.2.8)
rack-attack (6.6.0)
rack (>= 1.0, < 3)
Expand Down Expand Up @@ -1029,7 +1029,7 @@ DEPENDENCIES
my_responds_to_parent!
mysql2
net-ftp
nokogiri (~> 1.14.3)
nokogiri (~> 1.16.2)
omniauth (~> 2.1.0)
omniauth-github
omniauth-rails_csrf_protection
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/controlled_vocabs.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CVTerms = {
dataType: "html",
data: {
source_ontology_id: $j('select#sample_controlled_vocab_source_ontology').val(),
root_uri: $j('#sample_controlled_vocab_ols_root_term_uri').val(),
root_uris: $j('#sample_controlled_vocab_ols_root_term_uris').val(),
include_root_term: $j('#include_root_term:checked').val()
},
success: function (resp) {
Expand Down Expand Up @@ -179,7 +179,7 @@ CVTerms = {
$j('select#sample_controlled_vocab_source_ontology').on('change', function () {
var selected = this.selectedOptions[0];
if (selected.value == "") {
$j('#sample_controlled_vocab_ols_root_term_uri').val('');
$j('#sample_controlled_vocab_ols_root_term_uris').val('');
$j('#ontology-root-uri').hide();
} else {
$j('#ontology-root-uri').show();
Expand Down
66 changes: 34 additions & 32 deletions app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ class AssaysController < ApplicationController
before_action :find_assets, only: [:index]
before_action :find_and_authorize_requested_item,
only: %i[edit update destroy manage manage_update show new_object_based_on_existing_one]
before_action :fix_assay_linkage, only: [:destroy]
before_action :delete_linked_sample_types, only: [:destroy]

# project_membership_required_appended is an alias to project_membership_required, but is necessary to include the actions
# defined in the application controller
before_action :project_membership_required_appended, only: [:new_object_based_on_existing_one]

# Only for ISA JSON compliant assays
# => Fix sample type linkage
before_action :fix_assay_linkage_when_deleting_assays, only: :destroy
# => Delete sample type of deleted assay
before_action :delete_linked_sample_types, only: :destroy
# => Rearrange positions
after_action :rearrange_assay_positions_at_destroy, only: :destroy

include Seek::Publishing::PublishingCommon

include Seek::IsaGraphExtensions
Expand Down Expand Up @@ -106,30 +112,6 @@ def create
end
end

def delete_linked_sample_types
return unless is_single_page_assay?
return if @assay.sample_type.nil?

@assay.sample_type.destroy
end

def fix_assay_linkage
return unless is_single_page_assay?
return unless @assay.has_linked_child_assay?

previous_assay_linked_st_id = @assay.previous_linked_sample_type&.id

next_assay = Assay.all.detect do |a|
a.sample_type&.sample_attributes&.first&.linked_sample_type_id == @assay.sample_type_id
end

next_assay_st_attr = next_assay.sample_type&.sample_attributes&.first

return unless next_assay && previous_assay_linked_st_id && next_assay_st_attr

next_assay_st_attr.update(linked_sample_type_id: previous_assay_linked_st_id)
end

def update
update_assay_organisms @assay, params
update_assay_human_diseases @assay, params
Expand Down Expand Up @@ -178,6 +160,32 @@ def show

private

def delete_linked_sample_types
return unless @assay.is_isa_json_compliant?
return if @assay.sample_type.nil?

@assay.sample_type.destroy
end

def fix_assay_linkage_when_deleting_assays
return unless @assay.is_isa_json_compliant?
return unless @assay.has_linked_child_assay?

previous_assay_linked_st_id = @assay.previous_linked_sample_type&.id

next_assay = @assay.next_linked_child_assay

next_assay_st_attr = next_assay.sample_type&.sample_attributes&.detect(&:input_attribute?)

return unless next_assay && previous_assay_linked_st_id && next_assay_st_attr

next_assay_st_attr.update(linked_sample_type_id: previous_assay_linked_st_id)
end

def rearrange_assay_positions_at_destroy
rearrange_assay_positions(@assay.assay_stream)
end

def assay_params
params.require(:assay).permit(:title, :description, :study_id, :assay_class_id, :assay_type_uri, :technology_type_uri,
:license, *creator_related_params, :position, { document_ids: [] },
Expand All @@ -194,10 +202,4 @@ def assay_params
assay_params[:model_ids].select! { |id| Model.find_by_id(id).try(:can_view?) } if assay_params.key?(:model_ids)
end
end

def is_single_page_assay?
return false unless params.key?(:return_to)

params[:return_to].start_with? '/single_pages/'
end
end
23 changes: 8 additions & 15 deletions app/controllers/git_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class GitController < ApplicationController
before_action :fetch_git_version
before_action :get_tree, only: [:tree]
before_action :get_blob, only: [:blob, :download, :raw]
before_action :coerce_format

user_content_actions :raw

Expand All @@ -17,6 +16,11 @@ class GitController < ApplicationController
rescue_from Git::InvalidPathException, with: :render_invalid_path_error
rescue_from URI::InvalidURIError, with: :render_invalid_url_error

# See: config/initializers/action_dispatch_http_mime_negotiation.rb
def self.ignore_format_from_extension
true
end

def browse
respond_to do |format|
format.html
Expand All @@ -25,12 +29,12 @@ def browse

def tree
respond_to do |format|
format.json { render json: @tree, adapter: :attributes, root: '' }
if request.xhr?
format.html { render partial: 'tree' }
else
format.html
end
format.json { render json: @tree, adapter: :attributes, root: '' }
end
end

Expand All @@ -40,12 +44,12 @@ def download

def blob
respond_to do |format|
format.json { render json: @blob, adapter: :attributes, root: '' }
if request.xhr?
format.html { render partial: 'blob' }
else
format.html
end
format.json { render json: @blob, adapter: :attributes, root: '' }
end
end

Expand Down Expand Up @@ -118,7 +122,6 @@ def update

def operation_response(notice = nil, status: 200)
respond_to do |format|
format.json { render json: { }, status: status, adapter: :attributes, root: '' }
format.html do
if request.xhr?
render partial: 'files', locals: { resource: @parent_resource, git_version: @git_version }, status: status
Expand All @@ -127,6 +130,7 @@ def operation_response(notice = nil, status: 200)
redirect_to polymorphic_path(@parent_resource, tab: 'files')
end
end
format.json { render json: { }, status: status, adapter: :attributes, root: '' }
end
end

Expand Down Expand Up @@ -226,17 +230,6 @@ def add_remote_file
@git_version.save!
end

def coerce_format
# I have to do this because Rails doesn't seem to be behaving as expected.
# In routes.rb, the git routes are scoped with "format: false", so Rails should disregard the extension
# (e.g. /git/1/blob/my_file.yml) when determining the response format.
# However this results in an UnknownFormat error when trying to load the HTML view, as Rails still seems to be
# looking for an e.g. application/yaml view.
# You can fix this by adding { defaults: { format: :html } }, but then it is not possible to request JSON,
# even with an explicit `Accept: application/json` header! -Finn
request.format = :html unless json_api_request?
end

def file_content
file_params.key?(:content) ? StringIO.new(Base64.decode64(file_params[:content])) : file_params[:data]
end
Expand Down
43 changes: 39 additions & 4 deletions app/controllers/isa_assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class IsaAssaysController < ApplicationController

before_action :set_up_instance_variable
before_action :find_requested_item, only: %i[edit update]
before_action :initialize_isa_assay, only: :create
before_action :fix_assay_linkage_for_new_assays, only: :create
after_action :rearrange_assay_positions_create_isa_assay, only: :create

def new
if params[:is_assay_stream]
Expand All @@ -14,10 +17,6 @@ def new
end

def create
@isa_assay = IsaAssay.new(isa_assay_params)
update_sharing_policies @isa_assay.assay
@isa_assay.assay.contributor = current_person
@isa_assay.sample_type.contributor = User.current_user.person if isa_assay_params[:sample_type]
if @isa_assay.save
redirect_to single_page_path(id: @isa_assay.assay.projects.first, item_type: 'assay',
item_id: @isa_assay.assay, notice: 'The ISA assay was created successfully!')
Expand Down Expand Up @@ -66,6 +65,42 @@ def update

private

def fix_assay_linkage_for_new_assays
return unless @isa_assay.assay.is_isa_json_compliant?
return if @isa_assay.assay.is_assay_stream? # Should not fix anything when creating an assay stream

previous_sample_type = SampleType.find(params[:isa_assay][:input_sample_type_id])
previous_assay = previous_sample_type.assays.first

# In case an assay is inserted right at the beginning of an assay stream,
# the next assay is the current first one in the assay stream.
next_assay = previous_assay.nil? ? @isa_assay.assay.assay_stream.next_linked_child_assay : previous_assay.next_linked_child_assay

# In case no next assay (an assay was appended to the end of the stream), assay linkage does not have to be fixed.
return unless next_assay

next_assay_input_attribute_id = next_assay.sample_type.sample_attributes.detect(&:input_attribute?).id
return unless next_assay_input_attribute_id

# Add link of next assay sample type to currently created assay sample type
updated_lsai = @isa_assay.assay.sample_type.linked_sample_attribute_ids.push(next_assay_input_attribute_id)
@isa_assay.assay.sample_type.update(linked_sample_attribute_ids: updated_lsai)
end

def rearrange_assay_positions_create_isa_assay
return if @isa_assay.assay.is_assay_stream?
return unless @isa_assay.assay.is_isa_json_compliant?

rearrange_assay_positions(@isa_assay.assay.assay_stream)
end

def initialize_isa_assay
@isa_assay = IsaAssay.new(isa_assay_params)
update_sharing_policies @isa_assay.assay
@isa_assay.assay.contributor = current_person
@isa_assay.sample_type.contributor = User.current_user.person if isa_assay_params[:sample_type]
end

def isa_assay_params
# TODO: get the params from a shared module
isa_assay_params = params.require(:isa_assay).permit(
Expand Down
16 changes: 9 additions & 7 deletions app/controllers/sample_controlled_vocabs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class SampleControlledVocabsController < ApplicationController

before_action :samples_enabled?, except: :typeahead
before_action :login_required, except: %i[show index]
before_action :is_user_admin_auth, only: %i[destroy update]
before_action :find_and_authorize_requested_item, except: %i[index new create]
before_action :find_assets, only: :index
before_action :auth_to_create, only: %i[new create]
Expand Down Expand Up @@ -89,13 +88,16 @@ def fetch_ols_terms_html
error_msg = nil
begin
source_ontology = params[:source_ontology_id]
root_uri = params[:root_uri]

raise 'No root URI provided' if root_uri.blank?
root_uris = params[:root_uris]

raise 'No root URI provided' if root_uris.blank?
@terms = []
client = Ebi::OlsClient.new
@terms = client.all_descendants(source_ontology, root_uri)
@terms.reject! { |t| t[:iri] == root_uri } unless params[:include_root_term] == '1'
root_uris.split(',').collect(&:strip).reject(&:blank?).each do |uri|
terms = client.all_descendants(source_ontology, uri)
terms.reject! { |t| t[:iri] == uri } unless params[:include_root_term] == '1'
@terms = @terms | terms
end
error_msg = "There are no descendant terms to populate the list." unless @terms.present?
rescue StandardError => e
error_msg = e.message
Expand Down Expand Up @@ -129,7 +131,7 @@ def typeahead
private

def cv_params
params.require(:sample_controlled_vocab).permit(:title, :description, :group, :source_ontology, :ols_root_term_uri,
params.require(:sample_controlled_vocab).permit(:title, :description, :group, :source_ontology, :ols_root_term_uris,
:required, :short_name,
{ sample_controlled_vocab_terms_attributes: %i[id _destroy label
iri parent_iri] })
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def update
end

def delete_linked_sample_types
return unless is_single_page_study?
return unless @study.is_isa_json_compliant?
return if @study.sample_types.empty?

# The study sample types must be destroyed in reversed order
Expand Down Expand Up @@ -361,9 +361,3 @@ def study_params
{ extended_metadata_attributes: determine_extended_metadata_keys })
end
end

def is_single_page_study?
return false unless params.key?(:return_to)

params[:return_to].start_with? '/single_pages/'
end
6 changes: 6 additions & 0 deletions app/forms/isa_assay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def populate(id)
def validate_objects
@assay.errors.each { |e| errors.add(:base, "[Assay]: #{e.full_message}") } unless @assay.valid?

if @assay.new_record? && @assay.next_linked_child_assay&.sample_type&.samples&.any?
next_assay_id = @assay.next_linked_child_assay.id
next_assay_title = @assay.next_linked_child_assay.title
errors.add(:base, "[Assay]: Not allowed to create an assay before assay '#{next_assay_id} - #{next_assay_title}'. It has samples linked to it.")
end

return if @assay.is_assay_stream?

errors.add(:base, '[Assay]: The assay is missing a sample type.') if @sample_type.nil?
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/dynamic_table_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def dt_aggregated(study, assay = nil)
# Links all sample_types in a sequence of sample_types
def link_sequence(sample_type)
sequence = [sample_type]
while link = sample_type.sample_attributes.detect(&:seek_sample_multi?)&.linked_sample_type
while link = sample_type.previous_linked_sample_type
sequence << link
sample_type = link
end
Expand Down Expand Up @@ -96,8 +96,8 @@ def dt_cols(sample_type)
is_seek_multi_sample = a.sample_attribute_type.base_type == Seek::Samples::BaseType::SEEK_SAMPLE_MULTI
is_cv_list = a.sample_attribute_type.base_type == Seek::Samples::BaseType::CV_LIST
cv_allows_free_text = a.allow_cv_free_text
attribute.merge!({ multi_link: true, linked_sample_type: a.linked_sample_type.id }) if is_seek_multi_sample
attribute.merge!({ multi_link: false, linked_sample_type: a.linked_sample_type.id }) if is_seek_sample
attribute.merge!({ multi_link: true, linked_sample_type: a.linked_sample_type_id }) if is_seek_multi_sample
attribute.merge!({ multi_link: false, linked_sample_type: a.linked_sample_type_id }) if is_seek_sample
attribute.merge!({is_cv_list: , cv_allows_free_text:}) if is_cv_list
attribute
end
Expand Down
Loading

0 comments on commit 2294395

Please sign in to comment.