Skip to content

Commit

Permalink
Merge branch 'main' into hide-non-ISA-compliant-elements
Browse files Browse the repository at this point in the history
  • Loading branch information
somathias committed Sep 22, 2023
2 parents f3a9fe0 + 4ffd32f commit ab5da33
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 235 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public/javascripts/i18n.js
public/javascripts/translations.js
public/stylesheets/*_cached.css
public/system/
public/sitemaps/*

public/assets/
public/assets_dev/
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ gem 'ransack'

gem 'terser', '~> 1.1', '>= 1.1.1'


# Rails 4 upgrade
gem 'activerecord-session_store'
gem 'rails-observers'
Expand Down Expand Up @@ -177,6 +178,8 @@ group :development do

gem 'web-console', '>= 4.1.0'
gem 'rack-mini-profiler', '~> 2.0'
gem "flamegraph", "~> 0.9.5"
gem "stackprof", "~> 0.2.25"
gem 'listen', '~> 3.3'
end

Expand All @@ -202,3 +205,5 @@ group :test, :development do
gem 'teaspoon'
gem 'teaspoon-mocha'
end

gem "sitemap_generator", "~> 6.3"
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ GEM
loofah (>= 2.3.1)
sax-machine (>= 1.0)
ffi (1.15.5)
flamegraph (0.9.5)
fssm (0.2.10)
gem-licenses (0.2.2)
gitlab_omniauth-ldap (2.2.0)
Expand Down Expand Up @@ -828,6 +829,8 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
sitemap_generator (6.3.0)
builder (~> 3.0)
slop (3.6.0)
snaky_hash (2.0.0)
hashie
Expand All @@ -852,6 +855,7 @@ GEM
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
stackprof (0.2.25)
stringio (3.0.1)
sunspot (2.6.0)
pr_geohash (~> 1.0)
Expand Down Expand Up @@ -990,6 +994,7 @@ DEPENDENCIES
exception_notification
factory_bot (~> 6.2.1)
feedjira
flamegraph (~> 0.9.5)
fleximage!
fssm
gem-licenses
Expand Down Expand Up @@ -1073,8 +1078,10 @@ DEPENDENCIES
seedbank
simple-spreadsheet-extractor (~> 0.18.0)
simplecov
sitemap_generator (~> 6.3)
sprockets-rails
sqlite3 (~> 1.4)
stackprof (~> 0.2.25)
stringio (= 3.0.1)
sunspot_matchers
sunspot_rails
Expand Down
20 changes: 16 additions & 4 deletions app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AssaysController < ApplicationController
before_action :assays_enabled?
before_action :find_assets, :only=>[:index]
before_action :find_and_authorize_requested_item, :only=>[:edit, :update, :destroy, :manage, :manage_update, :show, :new_object_based_on_existing_one]
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
Expand All @@ -18,7 +19,7 @@ class AssaysController < ApplicationController
api_actions :index, :show, :create, :update, :destroy

def new_object_based_on_existing_one
@existing_assay = Assay.find(params[:id])
@existing_assay = Assay.find(params[:id])
@assay = @existing_assay.clone_with_associations

if @existing_assay.can_view?
Expand Down Expand Up @@ -62,9 +63,7 @@ def new_object_based_on_existing_one
flash[:error]="You do not have the necessary permissions to copy this #{t('assays.assay')}"
redirect_to @existing_assay
end


end
end

def new
@assay=setup_new_asset
Expand Down Expand Up @@ -112,6 +111,13 @@ def create
end
end


def delete_linked_sample_types
return unless is_single_page_assay?

@assay.sample_type.destroy
end

def update
update_assay_organisms @assay, params
update_assay_human_diseases @assay, params
Expand Down Expand Up @@ -177,4 +183,10 @@ 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
19 changes: 18 additions & 1 deletion app/controllers/studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class StudiesController < ApplicationController
before_action :studies_enabled?
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 :delete_linked_sample_types, only: [:destroy]

# project_membership_required_appended is an alias to project_membership_required, but is necesary to include the actions
# defined in the application controller
Expand Down Expand Up @@ -88,6 +89,16 @@ def update
end
end

def delete_linked_sample_types
return unless is_single_page_study?

# The study sample types must be destroyed in reversed order
# otherwise the first sample type won't be removed becaused it is linked from the second
study_st_ids = @study.sample_types.map(&:id).sort { |a, b| b <=> a }
SampleType.destroy(study_st_ids)
end


def show
@study = Study.find(params[:id])

Expand Down Expand Up @@ -201,7 +212,7 @@ def batch_create
study_params = {
title: params[:studies][:title][index],
description: params[:studies][:description][index],
investigation_id: params[:study][:investigation_id],
investigation_id: params[:study][:investigation_id],
custom_metadata: CustomMetadata.new(
custom_metadata_type: metadata_types,
data: metadata
Expand Down Expand Up @@ -351,3 +362,9 @@ def study_params
{ custom_metadata_attributes: determine_custom_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: 3 additions & 3 deletions app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def task_status

def populate_template
uploaded_file = params[:template_json_file]
dir = Rails.root.join('config', 'default_data', 'source_types')
dir = Seek::Config.append_filestore_path('source_types')

if Dir.exist?(dir)
`rm #{dir}/*`
Expand Down Expand Up @@ -146,11 +146,11 @@ def set_status
end

def lockfile
Rails.root.join('tmp', 'populate_templates.lock')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.lock')
end

def resultfile
Rails.root.join('tmp', 'populate_templates.result')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.result')
end

def running!
Expand Down
6 changes: 5 additions & 1 deletion app/models/assay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def short_description
end

def state_allows_delete?(*args)
assets.empty? && publications.empty? && super
assets.empty? && publications.empty? && associated_samples_through_sample_type.empty? && super
end

# returns true if this is a modelling class of assay
Expand All @@ -90,6 +90,10 @@ def is_experimental?
!assay_class.nil? && assay_class.key == 'EXP'
end

def associated_samples_through_sample_type
(sample_type.nil? || sample_type.samples.nil?) ? [] : sample_type.samples
end

# Create or update relationship of this assay to another, with a specific relationship type and version
def associate(asset, options = {})
if asset.is_a?(Organism)
Expand Down
15 changes: 12 additions & 3 deletions app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Study < ApplicationRecord

enum status: [:planned, :running, :completed, :cancelled, :failed]
belongs_to :assignee, class_name: 'Person'

searchable(:auto_index => false) do
text :experimentalists
end if Seek::Config.solr_enabled
Expand All @@ -22,7 +22,7 @@ class Study < ApplicationRecord
has_many :sop_versions, through: :assays

has_one :external_asset, as: :seek_entity, dependent: :destroy

has_and_belongs_to_many :sops

has_and_belongs_to_many :sample_types
Expand All @@ -41,7 +41,16 @@ def assets
end

def state_allows_delete? *args
assays.empty? && super
assays.empty? && associated_samples_through_sample_type.empty? && super
end

def associated_samples_through_sample_type
return [] if sample_types.nil?
st_samples = []
sample_types.map do |st|
st.samples.map { |sts| st_samples.push sts }
end
st_samples
end

def clone_with_associations
Expand Down
4 changes: 4 additions & 0 deletions app/views/general/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
show_new_button = true unless local_assigns.has_key?(:show_new_button)
title ||= nil
subtitle ||= nil
isa_templates_enabled = Seek::Config.sample_type_template_enabled && Seek::Config.project_single_page_advanced_enabled
%>

<div class="pull-right">
<% if show_new_button && controller_model.can_create? %>
<% if isa_templates_enabled %>
<%= link_to "Query by #{t('template').pluralize}", query_form_samples_path, class: "btn btn-default btn" %>
<% end %>
<%= button_link_to(new_item_label, "new", new_item_path) %>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/programmes/activation_review.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render :partial => "general/item_title",:locals => {:item=>@programme, :title_prefix=>"Acitivation required for: "} %>
<%= render :partial => "general/item_title",:locals => {:item=>@programme, :title_prefix=>"Activation required for: "} %>

<p>
A <%= t('programme') %> has been created by a user, and requires activation. The <%= t('programme') %> created is <%= link_to @programme.title, @programme %>.
Expand Down
5 changes: 5 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def offset(off_hours)
runner "Seek::BioSchema::DataDump.generate_dumps"
end

# Generate a new sitemap...
every 1.day, at: '12:45 am' do
rake "-s sitemap:refresh"
end

# not safe to automatically add in a non containerised environment
if Seek::Docker.using_docker?
every 10.minutes do
Expand Down
19 changes: 19 additions & 0 deletions config/sitemap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://github.com/kjvarga/sitemap_generator#sitemapgenerator
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps"
SitemapGenerator::Sitemap.create_index = "auto"
SitemapGenerator::Sitemap.compress = false
SitemapGenerator::Sitemap.default_host = URI.parse(Seek::Config.site_base_url)

SitemapGenerator::Sitemap.create do
Seek::Util.searchable_types.each do |type|
add polymorphic_path(type), lastmod: type.maximum(:updated_at), changefreq: 'daily', priority: 0.7
end
end

Seek::Util.searchable_types.each do |type|
SitemapGenerator::Sitemap.create(filename: type.table_name, include_root: false) do
type.authorized_for('view', nil).find_all do |obj|
add polymorphic_path(obj), lastmod: obj.updated_at, changefreq: 'daily', priority: 0.7
end
end
end
6 changes: 3 additions & 3 deletions lib/seek/isa_templates/template_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.extract_templates
disable_authorization_checks do
client = Ebi::OlsClient.new
project = Project.find_or_create_by(title: 'Default Project')
directory = Rails.root.join('config', 'default_data', 'source_types')
directory = Seek::Config.append_filestore_path('source_types')
directory_files = Dir.exist?(directory) ? Dir.glob("#{directory}/*.json") : []
raise '<ul><li>Make sure to upload files that have the ".json" extension.</li></ul>' if directory_files == []

Expand Down Expand Up @@ -172,11 +172,11 @@ def self.seed_isa_tags
end

def self.lockfile
Rails.root.join('tmp', 'populate_templates.lock')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.lock')
end

def self.resultfile
Rails.root.join('tmp', 'populate_templates.result')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.result')
end
end
end
Expand Down
Loading

0 comments on commit ab5da33

Please sign in to comment.