Skip to content

Commit

Permalink
Merge branch 'main' into full-test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Oct 15, 2024
2 parents 2721d4e + d076dba commit 8771035
Show file tree
Hide file tree
Showing 111 changed files with 2,552 additions and 898 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ GEM
net-smtp (0.4.0.1)
net-protocol
netrc (0.11.0)
nio4r (2.7.0)
nio4r (2.7.3)
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
Expand Down Expand Up @@ -563,7 +563,7 @@ GEM
psych (5.1.0)
stringio
public_suffix (5.0.0)
puma (5.6.8)
puma (5.6.9)
nio4r (~> 2.0)
pyu-ruby-sasl (0.0.3.3)
racc (1.8.0)
Expand Down Expand Up @@ -938,7 +938,7 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
webrick (1.8.2)
webrobots (0.1.2)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/sample_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ var SampleTypes = {
else {
seek_sample_element.hide();
}
},

expandIRI: function () {
var termIRI = $j(this).next('.term-iri');
termIRI.toggleClass('visible');
}

};


$j(document).ready(function() {
$j('.term-label').on('click', SampleTypes.expandIRI);
});
18 changes: 18 additions & 0 deletions app/assets/stylesheets/linked_extended_metadata.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
.term-label {
font-weight: normal;
text-decoration: underline;
}

.term-iri {
display: none;
background-color: rgba(177, 183, 187, 0.47);
color: black;
font-weight: normal;
}

.term-iri.visible {
display: inline;
opacity: 1;
margin-left: 10px;
}

.linked_extended_metdata .panel-default .panel-heading {
font-weight: bold;
color: #333;
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ div.renderer {
color: if(lightness($text-color) > 50, darken($text-color, 20%), lighten($text-color, 30%));
}

.select2-results__option--highlighted .subtle {
color: unset;
}

span.truncated-name {
display: inline-block;
overflow: hidden;
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ def update_settings
Seek::Config.metadata_license = params[:metadata_license]
Seek::Config.recommended_data_licenses = params[:recommended_data_licenses]&.compact_blank
Seek::Config.recommended_software_licenses = params[:recommended_software_licenses]&.compact_blank
Seek::Config.sandbox_instance_url = params[:sandbox_instance_url]
Seek::Config.sandbox_instance_name = params[:sandbox_instance_name]
update_flag = (pubmed_email == '' || pubmed_email_valid) && (crossref_email == '' || crossref_email_valid)
update_redirect_to update_flag, 'settings'
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/extended_metadata_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class ExtendedMetadataTypesController < ApplicationController
before_action :find_requested_item, only: [:administer_update, :show]
include Seek::IndexPager

api_actions :index, :show

# generated for form, to display fields for selected metadata type
def form_fields
id = params[:id]
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/human_diseases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class HumanDiseasesController < ApplicationController
include Seek::ExternalServiceWrapper
include Seek::IndexPager

api_actions :index, :show, :create, :update, :destroy

def show
respond_to do |format|
format.html
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/isa_assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def new
end

def create
update_sharing_policies @isa_assay.assay
@isa_assay.sample_type.policy = @isa_assay.assay.policy
if @isa_assay.save
flash[:notice] = "The #{t('isa_assay')} was successfully created.<br/>".html_safe
respond_to do |format|
Expand All @@ -66,8 +68,9 @@ def edit
end

def update
update_sharing_policies @isa_assay.assay
@isa_assay.assay.attributes = isa_assay_params[:assay]

@isa_assay.sample_type.policy = @isa_assay.assay.policy
# update the sample_type
unless @isa_assay&.assay&.is_assay_stream?
if requested_item_authorized?(@isa_assay.sample_type)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/isa_studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def new
def create
@isa_study = IsaStudy.new(isa_study_params)
update_sharing_policies @isa_study.study
@isa_study.source.policy = @isa_study.study.policy
@isa_study.sample_collection.policy = @isa_study.study.policy
@isa_study.source.contributor = User.current_user.person
@isa_study.sample_collection.contributor = User.current_user.person
@isa_study.study.sample_types = [@isa_study.source, @isa_study.sample_collection]
Expand Down Expand Up @@ -43,6 +45,8 @@ def update
# update the study
@isa_study.study.attributes = isa_study_params[:study]
update_sharing_policies @isa_study.study
@isa_study.source.policy = @isa_study.study.policy
@isa_study.sample_collection.policy = @isa_study.study.policy
update_relationships(@isa_study.study, isa_study_params[:study])

# update the source
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def submit_fairdata_station
path = params[:datastation_data].path
policy = Policy.new
policy.set_attributes_with_sharing(policy_params)
datadata_inv = Seek::FairDataStation::Reader.instance.parse_graph(path)
@investigation = Seek::FairDataStation::Writer.instance.construct_isa(datadata_inv.first, current_person, [@project], policy)
datadata_inv = Seek::FairDataStation::Reader.new.parse_graph(path)
@investigation = Seek::FairDataStation::Writer.new.construct_isa(datadata_inv.first, current_person, [@project], policy)
@investigation.save!

respond_to do |format|
Expand Down
100 changes: 48 additions & 52 deletions app/controllers/sample_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ class SampleTypesController < ApplicationController
respond_to :html, :json
include Seek::UploadHandling::DataUpload
include Seek::IndexPager
include Seek::AssetsCommon

before_action :samples_enabled?
before_action :find_sample_type, only: [:show, :edit, :update, :destroy, :template_details, :batch_upload]
before_action :check_no_created_samples, only: [:destroy]
before_action :find_and_authorize_requested_item, except: %i[create batch_upload index new template_details]
before_action :find_sample_type, only: %i[batch_upload template_details]
before_action :check_isa_json_compliance, only: %i[edit update manage manage_update]
before_action :find_assets, only: [:index]
before_action :auth_to_create, only: [:new, :create]
before_action :project_membership_required, only: [:create, :new, :select, :filter_for_select]
before_action :auth_to_create, only: %i[new create]
before_action :project_membership_required, only: %i[create new select filter_for_select]

before_action :authorize_requested_sample_type, except: [:index, :new, :create]

api_actions :index
api_actions :index, :show, :create, :update, :destroy

# GET /sample_types/1 ,'sample_attributes','linked_sample_attributes'
# GET /sample_types/1.json
def show
respond_to do |format|
format.html
format.json {render json: @sample_type, include: [params[:include]]}
format.json { render json: @sample_type, include: [params[:include]] }
end
end

Expand All @@ -28,7 +30,7 @@ def show
def new
@tab = 'manual'

attr = params["sample_type"] ? sample_type_params : {}
attr = params['sample_type'] ? sample_type_params : {}
@sample_type = SampleType.new(attr)
@sample_type.sample_attributes.build(is_title: true, required: true) # Initial attribute

Expand Down Expand Up @@ -62,17 +64,24 @@ def create
@sample_type = SampleType.new(sample_type_params)
@sample_type.contributor = User.current_user.person

# Update sharing policies
update_sharing_policies(@sample_type)
# Update relationships
update_relationships(@sample_type, params)
# Update tags
update_annotations(params[:tag_list], @sample_type)

# removes controlled vocabularies or linked seek samples where the type may differ
@sample_type.resolve_inconsistencies
@tab = 'manual'

respond_to do |format|
if @sample_type.save
format.html { redirect_to @sample_type, notice: 'Sample type was successfully created.' }
format.json { render json: @sample_type, status: :created, location: @sample_type, include: [params[:include]]}
format.json { render json: @sample_type, status: :created, location: @sample_type, include: [params[:include]] }
else
format.html { render action: 'new' }
format.json { render json: @sample_type.errors, status: :unprocessable_entity}
format.json { render json: @sample_type.errors, status: :unprocessable_entity }
end
end
end
Expand All @@ -83,31 +92,25 @@ def update

@sample_type.update(sample_type_params)
@sample_type.resolve_inconsistencies

# Update sharing policies
update_sharing_policies(@sample_type)
# Update relationships
update_relationships(@sample_type, params)
# Update tags
update_annotations(params[:tag_list], @sample_type)

respond_to do |format|
if @sample_type.save
format.html { redirect_to @sample_type, notice: 'Sample type was successfully updated.' }
format.json {render json: @sample_type, include: [params[:include]]}
format.json { render json: @sample_type, include: [params[:include]] }
else
format.html { render action: 'edit', status: :unprocessable_entity }
format.json { render json: @sample_type.errors, status: :unprocessable_entity}
format.json { render json: @sample_type.errors, status: :unprocessable_entity }
end
end
end

# DELETE /sample_types/1
# DELETE /sample_types/1.json
def destroy
respond_to do |format|
if @sample_type.can_delete? && @sample_type.destroy
format.html { redirect_to @sample_type,location: sample_types_path, notice: 'Sample type was successfully deleted.' }
format.json {render json: @sample_type, include: [params[:include]]}
else
format.html { redirect_to @sample_type, location: sample_types_path, notice: 'It was not possible to delete the sample type.' }
format.json { render json: @sample_type.errors, status: :unprocessable_entity}
end
end
end

def template_details
render partial: 'template'
end
Expand All @@ -133,40 +136,39 @@ def filter_for_select
render partial: 'sample_types/select/filtered_sample_types'
end

def batch_upload

end
def batch_upload; end

private

def sample_type_params
attributes = params[:sample_type][:sample_attributes]
if (attributes)
if attributes
params[:sample_type][:sample_attributes_attributes] = []
attributes.each do |attribute|
if attribute[:sample_attribute_type]
if attribute[:sample_attribute_type][:id]
attribute[:sample_attribute_type_id] = attribute[:sample_attribute_type][:id].to_i
elsif attribute[:sample_attribute_type][:title]
attribute[:sample_attribute_type_id] = SampleAttributeType.where(title: attribute[:sample_attribute_type][:title]).first.id
attribute[:sample_attribute_type_id] =
SampleAttributeType.where(title: attribute[:sample_attribute_type][:title]).first.id
end
end
attribute[:unit_id] = Unit.where(symbol: attribute[:unit_symbol]).first.id unless attribute[:unit_symbol].nil?
params[:sample_type][:sample_attributes_attributes] << attribute
end
end

if (params[:sample_type][:assay_assets_attributes])
if params[:sample_type][:assay_assets_attributes]
params[:sample_type][:assay_ids] = params[:sample_type][:assay_assets_attributes].map { |x| x[:assay_id] }
end

params.require(:sample_type).permit(:title, :description, {tags: []}, :template_id, *creator_related_params,
params.require(:sample_type).permit(:title, :description, { tags: [] }, :template_id, *creator_related_params,
{ project_ids: [],
sample_attributes_attributes: [:id, :title, :pos, :required, :is_title,
:description, :pid, :sample_attribute_type_id,
:sample_controlled_vocab_id, :isa_tag_id,
:allow_cv_free_text, :linked_sample_type_id,
:unit_id, :_destroy] }, :assay_ids => [])
sample_attributes_attributes: %i[id title pos required is_title
description pid sample_attribute_type_id
sample_controlled_vocab_id isa_tag_id
allow_cv_free_text linked_sample_type_id
unit_id _destroy] }, assay_ids: [])
end


Expand All @@ -179,28 +181,22 @@ def build_sample_type_from_template
@sample_type.build_attributes_from_template
end

private
def check_isa_json_compliance
@sample_type ||= SampleType.find(params[:id])
return unless Seek::Config.isa_json_compliance_enabled && @sample_type.is_isa_json_compliant?

flash[:error] = 'This sample type is ISA JSON compliant and cannot be managed.'
redirect_to sample_types_path
end

def find_sample_type
scope = Seek::Config.isa_json_compliance_enabled ? SampleType.without_template : SampleType
@sample_type = scope.find(params[:id])
end

#intercepts the standard 'find_and_authorize_requested_item' for additional special check for a referring_sample_id
def authorize_requested_sample_type
privilege = Seek::Permissions::Translator.translate(action_name)
return if privilege.nil?

if privilege == :view && params[:referring_sample_id].present?
@sample_type.can_view?(User.current_user,Sample.find_by_id(params[:referring_sample_id])) || find_and_authorize_requested_item
else
find_and_authorize_requested_item
end

end

def check_no_created_samples
if (count = @sample_type.samples.count) > 0
@sample_type ||= SampleType.find(params[:id])
if (count = @sample_type.samples.count).positive?
flash[:error] = "Cannot #{action_name} this sample type - There are #{count} samples using it."
redirect_to @sample_type
end
Expand Down
Loading

0 comments on commit 8771035

Please sign in to comment.