Merge pull request #3027 from okriuchykhin/ok_SCI_5246

Remove Demo project and Samples inventory [SCI-5246][SCI-5248]
This commit is contained in:
Alex Kriuchykhin 2021-02-04 11:28:09 +01:00 committed by GitHub
commit 1466ae114f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 2971 additions and 1627 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 538 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

View file

@ -1,18 +0,0 @@
# Content for tables used in demo project.
module1:
experimental_design_table: '{"data":[["group/time","1 dpi","6 dpi","",""],["PVYNTN","1","1","",""],["mock","1","1","",""],["","","","",""]]}'
module2:
samples_table: '{"data":[["Name","Sample type"],["Mock 1dpi","potatoe leaves"],["Mock 6dpi","potatoe leaves"],["PVY NTN 1dpi","potatoe leaves"],["PVY NTN 6dpi","potatoe leaves"]]}'
module3:
nanodrop: '{"data":[["Sample name","ng/ul ","260/280 ","260/230 "],["PVY NTN 6dpi","1.05","1.39","1.61"],["PVY NTN 1dpi","320.52","2.16","2.26"],["Mock 6dpi","906.19","2.15","2.26"],["Mock 1dpi","940.22","2.17","2.27"]]}'
module4:
volumes: '{"data":[["Amount of starting material (mg)","Volume of Buffer RLT (µl)"],["<20","350"],["20 - 30","600"]]}'
dna_q: '{"data":[["Sample 1","Quantity "],["1","0,2"],["2","0,5"],["3","0,4"],["4","1,1"],["5","12,5"],["6","0,05"],["7","0"],["8","0"],["9","0"],["10","0"],["11","0"],["12","4,7"],["13","2,3"],["14","5,6"],["15","2,6"],["16","8,9"],["17","1,7"],["18","1"]]}'
module6:
mastermix: '{"data":[["Date:","","","","","","","","","","","",""],["Reaction volume:","20 ul","","","","","","","","","","",""],["UMM/reaction:","10 µl","","","","","","","","","","",""],["sample/reaction:","6 µl","","","","","","","","","","",""],["","","","","","","","","","","","",""],["Chemistry","TaqMan","","","SYBR Green I","","","TaqMan","","","SYBR Green I","",""],["Gene","cox","","","cab4","","","PVY-NTN","","","PR-1","",""],["","conc.*","final conc.**","µl/reaction","conc.*","final conc.**","µl/reaction","conc.*","final conc.**","µl/reaction","conc.*","final conc.**","µl/reaction"],["Probe","10 µM","150 nM","0.3","/","/","/","5 µM","150 nM","0.6","/","/","/"],["FP","30 µM","300 nM","0.2","30 µM","300 nM ","0.2","10 µM","250 nM","0.5","30 µM","300 nM ","0.2"],["RP","30 µM","300 nM","0.2","30 µM","300 nM ","0.2","10 µM","250 nM","0.5","30 µM","300 nM ","0.2"]]}'
distribution: '{"data":[["%{sample0} (100x)\t","%{sample0} (100x)\t","%{sample0} (100x)\t","%{sample0} (100x)\t","%{sample0} (100x)\t","%{sample0} (100x)\t","%{sample0} (100x)\t","%{sample0} (100x)\t",null,null,"Mix smpl (10x)\t","Mix smpl (10x)\t"],["%{sample0} (1000x)\t","%{sample0} (1000x)\t","%{sample0} (1000x)\t","%{sample0} (1000x)\t","%{sample0} (1000x)\t","%{sample0} (1000x)\t","%{sample0} (1000x)\t","%{sample0} (1000x)\t",null,null,"Mix smpl (100x)\t","Mix smpl (100x)\t"],["%{sample1} (100x)\t","%{sample1} (100x)\t","%{sample1} (100x)\t","%{sample1} (100x)\t","%{sample1} (100x)\t","%{sample1} (100x)\t","%{sample1} (100x)\t","%{sample1} (100x)\t",null,null,"Mix smpl (1000x)\t","Mix smpl (1000x)\t"],["%{sample1} (1000x)\t","%{sample1} (1000x)\t","%{sample1} (1000x)\t","%{sample1} (1000x)\t","%{sample1} (1000x)\t","%{sample1} (1000x)\t","%{sample1} (1000x)\t","%{sample1} (1000x)\t",null,null,"Mix smpl (10000x)\t","Mix smpl (10000x)\t"],["%{sample2} (100x)\t","%{sample2} (100x)\t","%{sample2} (100x)\t","%{sample2} (100x)\t","%{sample2} (100x)\t","%{sample2} (100x)\t","%{sample2} (100x)\t","%{sample2} (100x)\t",null,null,"NTC1","NTC2"],["%{sample2} (1000x)\t","%{sample2} (1000x)\t","%{sample2} (1000x)\t","%{sample2} (1000x)\t","%{sample2} (1000x)\t","%{sample2} (1000x)\t","%{sample2} (1000x)\t","%{sample2} (1000x)\t",null,null,"NTC1","NTC2"],["%{sample3} (100x)\t","%{sample3} (100x)\t","%{sample3} (100x)\t","%{sample3} (100x)\t","%{sample3} (100x)\t","%{sample3} (100x)\t","%{sample3} (100x)\t","%{sample3} (100x)\t",null,null,"NTC1","NTC2"],["%{sample3} (1000x)\t","%{sample3} (1000x)\t","%{sample3} (1000x)\t","%{sample3} (1000x)\t","%{sample3} (1000x)\t","%{sample3} (1000x)\t","%{sample3} (1000x)\t","%{sample3} (1000x)\t",null,null,"NTC1","NTC2"],[null,null,null,null,null,null,null,null,null,null,null,null]]}'
qpcr_raw_data: '{"data":[["Sample 1","Quantity ","Column 3","Column 4"],["2","0,2","0,4","0,08"],["2","0,5","1","0,5"],["3","0,4","1,2","0,48"],["4","1,1","4,4","4,84"],["5","12,5","62,5","781,25"],["6","0,05","0,3","0,015"],["7","0","4","0"],["8","0","0","0"],["9","0","0","0"],["10","0","0","0"],["11","0","0","0"],["12","4,7","56,4","265,08"],["13","2,3","30","69"],["14","5,6","78,4","439,04"],["15","2,6","39","101,4"],["16","8,9","142,4","1267,36"],["17","1,7","28,9","49,13"],["18","1","18","18"],["","","",""]]}'
module7:
qpcr_results: '{"data":[["Sample 1","Quantity ",null,null,null],["1","0,2",null,null,null],["2","0,5",null,null,null],["3","0,4",null,null,null],["4","1,1",null,null,null],["5","12,5",null,null,null],["6","0,05",null,null,null],["7","0",null,null,null],["8","0",null,null,null],["9","0",null,null,null],["10","0",null,null,null],["11","0",null,null,null],["12","4,7",null,null,null],["13","2,3",null,null,null],["14","5,6",null,null,null],["15","2,6",null,null,null],["16","8,9",null,null,null],["17","1,7",null,null,null],["18","1",null,null,null]]}'

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 474 KiB

After

Width:  |  Height:  |  Size: 474 KiB

View file

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View file

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

View file

Before

Width:  |  Height:  |  Size: 187 KiB

After

Width:  |  Height:  |  Size: 187 KiB

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,9 @@ class RepositoriesController < ApplicationController
def index
respond_to do |format|
format.html do; end
format.html do
render 'empty_index' if @repositories.blank?
end
format.json do
render json: prepare_repositories_datatable(@repositories, current_team, params)
end

View file

@ -25,7 +25,7 @@ class Users::SessionsController < Devise::SessionsController
def create
super
generate_demo_project
generate_templates_project
end
def two_factor_recovery
@ -80,7 +80,7 @@ class Users::SessionsController < Devise::SessionsController
session.delete(:otp_user_id)
sign_in(user)
generate_demo_project
generate_templates_project
flash[:notice] = t('devise.sessions.signed_in')
redirect_to stored_location_for(:user) || root_path
else
@ -100,7 +100,7 @@ class Users::SessionsController < Devise::SessionsController
session.delete(:otp_user_id)
if user.recover_2fa!(params[:recovery_code])
sign_in(user)
generate_demo_project
generate_templates_project
flash[:notice] = t('devise.sessions.signed_in')
redirect_to root_path
else
@ -130,17 +130,9 @@ class Users::SessionsController < Devise::SessionsController
end
end
def generate_demo_project
def generate_templates_project
# Schedule templates creation for user
TemplatesService.new.schedule_creation_for_user(current_user)
# Schedule demo project creation for user
current_user.created_teams.each do |team|
FirstTimeDataGenerator.delay(
queue: :new_demo_project,
priority: 10
).seed_demo_data_with_id(current_user.id, team.id)
end
rescue StandardError => e
Rails.logger.fatal("User ID #{current_user.id}: Error creating inital projects on sign_in: #{e.message}")
end

View file

@ -43,8 +43,6 @@ class Team < ApplicationRecord
has_many :shared_repositories, through: :team_repositories, source: :repository
attr_accessor :without_templates
attr_accessor :without_intro_demo
after_create :generate_intro_demo
def default_view_state
{
@ -168,15 +166,4 @@ class Team < ApplicationRecord
return if without_templates
TemplatesService.new.delay(queue: :templates).update_team(self)
end
include FirstTimeDataGenerator
def generate_intro_demo
return if without_intro_demo
user = User.find(created_by_id)
if user.created_teams.order(:created_at).first == self
seed_demo_data(user, self)
end
end
end

View file

@ -57,7 +57,6 @@ class TeamImporter
team_last_modified_by = team.last_modified_by_id
team.last_modified_by_id = nil
team.without_templates = true
team.without_intro_demo = true
team.save!
create_users(team_json['users'], team)

View file

@ -1,60 +0,0 @@
# frozen_string_literal: true
module DelayedUploaderDemo
# Get asset from demo_files folder
def self.get_asset(user, team, file_name)
asset = Asset.create(
created_by: user,
team: team,
last_modified_by: user
)
asset.file.attach(io: File.open("#{Rails.root}/app/assets/demo_files/#{file_name}", 'r'), filename: file_name)
asset
end
# Generates results asset for given module, file_name assumes file is located
# in demo_files.
def self.generate_result_asset(
my_module:,
current_user:,
current_team:,
result_name:,
created_at: Time.now,
file_name:,
comment: nil
)
temp_asset = get_asset(current_user, current_team, file_name)
temp_result = Result.new(
created_at: created_at,
user: current_user,
my_module: my_module,
name: result_name,
asset: temp_asset
)
temp_result.save
# Generate comment if it exists
generate_result_comment(temp_result, current_user, comment) if comment
temp_asset.post_process_file(my_module.experiment.project.team)
end
# Adds asset to existing step
def self.add_step_asset(step:, current_user:, current_team:, file_name:)
temp_asset =
DelayedUploaderDemo.get_asset(current_user, current_team, file_name)
step.assets << temp_asset
temp_asset.post_process_file(step.my_module.experiment.project.team)
end
def self.generate_result_comment(result, user, message, created_at = nil)
created_at ||= result.created_at
ResultComment.create(
user: user,
message: message,
created_at: created_at,
result: result
)
end
end

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,29 @@
<% provide(:head_title, t('libraries.index.head_title')) %>
<% provide(:container_class, 'no-second-nav-container') %>
<%= render partial: 'sidebar', locals: { repositories: @repositories, archived: false } %>
<div class="content-pane flexible repositories-index" data-readonly="<%= !current_user.is_admin_of_team?(current_team) %>">
<div class="content-header">
<h1 data-view-mode="active"><%= t('libraries.index.head_title') %></h1>
</div>
<div class="content-body">
<h1>
<%= t('repositories.index.empty_title') %>
</h1>
<% if can_create_repositories?(current_team) %>
<h5>
<%= t('repositories.index.empty_description_with_create') %>
</h5>
<a id="createRepoBtn" class="btn btn-primary create-new-repository" data-remote="true" href="<%= create_modal_team_repositories_path(current_team) %>">
<span class="fas fa-plus"></span>
<span class="hidden-xs"><%= t('libraries.index.no_libraries.create_new_button') %></span>
</a>
<% else %>
<h5>
<%= t('repositories.index.empty_description_no_create') %>
</h5>
<% end %>
</div>
</div>
<%= javascript_include_tag 'repositories/index' %>

View file

@ -1201,6 +1201,9 @@ en:
index:
head_title: "Inventories"
title: "Inventories"
empty_title: "Your team has no inventories yet"
empty_description_no_create: "It would be a shame to waste all this space. Sadly you dont have permission to add inventories. You can ask your team admin to grant you that permission."
empty_description_with_create: "It would be a shame to waste all this space. Create your first inventory now"
add_new_repository_tab: "Add inventory"
delete_flash: "\"%{name}\" inventory was successfully deleted!"
rename_flash: "\"%{old_name}\" inventory was successfully renamed to \"%{new_name}\"!"

View file

@ -13,7 +13,7 @@ Given default screen size2
| name | email | password | password_confirmation |
| Karli Novak | nonadmin@myorg.com | mypassword1234 | mypassword1234 |
And "nonadmin@myorg.com" is in "BioSistemika Process" team as a "admin"
Given Demo project exists for the "BioSistemika Process" team
Given Templates project exists for the "BioSistemika Process" team
And "nonadmin@myorg.com" is signed in with "mypassword1234"
@javascript

View file

@ -13,7 +13,7 @@ Given the following users are registered
| name | email | password | password_confirmation |
| Karli Novak | nonadmin@myorg.com | mypassword1234 | mypassword1234 |
And "nonadmin@myorg.com" is in "BioSistemika Process" team as a "admin"
Given Demo project exists for the "BioSistemika Process" team
Given Templates project exists for the "BioSistemika Process" team
And "nonadmin@myorg.com" is signed in with "mypassword1234"
@javascript @wip

View file

@ -12,7 +12,7 @@ Background:
| name | email | password | password_confirmation |
| Karli Novak | nonadmin@myorg.com | mypassword1234 | mypassword1234 |
And "nonadmin@myorg.com" is in "BioSistemika Process" team as a "admin"
Given Demo project exists for the "BioSistemika Process" team
Given Templates project exists for the "BioSistemika Process" team
And "nonadmin@myorg.com" is signed in with "mypassword1234"
@javascript

View file

@ -85,12 +85,11 @@ Given(/^the "([^"]*)" team exists$/) do |team_name|
FactoryBot.create(:team, name: team_name)
end
Given(/^Demo project exists for the "([^"]*)" team$/) do |team_name|
Given(/^Templates project exists for the "([^"]*)" team$/) do |team_name|
team = Team.find_by(name: team_name)
user = team.user_teams.where(role: :admin).take.user
seed_demo_data(user, team)
TemplatesService.new.schedule_creation_for_user(user)
end
Given(/^I'm on the projects page of "([^"]*)" team$/) do |team_name|
team = Team.find_by(name: team_name)
@current_user.update(current_team_id: team.id)
@ -238,5 +237,3 @@ Then('I delete downloaded file {string}') do |file_name|
sleep 3
FileUtils.rm_f(Rails.root.join(file_name))
end

View file

@ -16,8 +16,6 @@ require 'capybara/email'
# require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
include FirstTimeDataGenerator
Capybara.default_max_wait_time = 30
#Capybara.asset_host = 'http://localhost:3001'
Capybara.server_port = ENV['CAPYBARA_SERVER_PORT'] || 3000

View file

@ -151,33 +151,4 @@ namespace :data do
end
end
end
desc 'Create demo project on existing users'
task :create_demo_project_on_existing_users,
%i(slice_size) => [:environment] do |_, args|
args.with_defaults(slice_size: 800)
require "#{Rails.root}/app/utilities/first_time_data_generator"
include FirstTimeDataGenerator
Rails.logger.info('Creating demo project on existing users')
Team.all.order(updated_at: :desc)
.each_slice(args[:slice_size]).with_index do |teams, i|
Rails.logger.info("Processing slice with index #{i}. " \
"First team: #{teams.first.id}, " \
"Last team: #{teams.last.id}.")
teams.each do |team|
owner_ut = team.user_teams.where(role: 2).first
next unless owner_ut
FirstTimeDataGenerator.delay(
run_at: i.hours.from_now,
queue: :new_demo_project,
priority: 10
).seed_demo_data_with_id(owner_ut.user.id, team.id)
end
end
end
end

View file

@ -7,7 +7,6 @@ FactoryBot.define do
description { Faker::Lorem.sentence }
space_taken { 1048576 }
without_templates { true }
without_intro_demo { true }
trait :with_members do
users { create_list :user, 3 }
end

View file

@ -4,7 +4,6 @@ require 'rails_helper'
require 'fileutils'
describe TemplatesService do
include FirstTimeDataGenerator
let!(:main_team) { create :team }
let!(:admin_user) { create :user }
@ -12,84 +11,30 @@ describe TemplatesService do
context 'update templates project' do
it 'experiment is added to templates project' do
create(:user_team, user: admin_user, team: main_team)
seed_demo_data(main_team.created_by, main_team)
dj_worker = Delayed::Worker.new
# Two runs are needed to execute additional jobs which get generated
# during first run
Delayed::Job.all.each { |job| dj_worker.run(job) }
Delayed::Job.all.each { |job| dj_worker.run(job) }
demo_exp = main_team.projects.first.experiments.first
exp_exporter = ModelExporters::ExperimentExporter.new(demo_exp.id)
exp_dir = exp_exporter.export_template_to_dir
tmplts_dir = "#{Rails.root}/tmp/testing_templates"
FileUtils.remove_dir(tmplts_dir) if Dir.exist?(tmplts_dir)
FileUtils.mkdir(tmplts_dir)
FileUtils.mv(exp_dir, "#{tmplts_dir}/experiment_#{demo_exp.id}")
templates_project =
create :project, name: 'Templates', template: true, team: main_team
create(
:user_project, :owner, project: templates_project, user: admin_user
)
ts = TemplatesService.new(tmplts_dir)
ts = TemplatesService.new
ts.update_team(main_team)
Delayed::Job.all.each { |job| dj_worker.run(job) }
tmpl_exp = templates_project.experiments.first
tmpl_exp = templates_project.experiments.find_by(name: 'Polymerase chain reaction')
expect(tmpl_exp.name).to eq(demo_exp.name)
expect(tmpl_exp.uuid).to_not eq(nil)
expect(tmpl_exp.my_modules.pluck(:name))
.to match_array(demo_exp.my_modules.active.pluck(:name))
.to match_array(['Data analysis - ddCq', 'Data quality control', 'Experiment design', 'qPCR',
'Reverse transcription', 'RNA isolation', 'RNA quality & quantity - BIOANALYSER',
'Sampling biological material'])
tmpl_tasks = tmpl_exp.my_modules
demo_tasks = demo_exp.my_modules.active
demo_tasks.each do |demo_task|
tmpl_task = tmpl_tasks.find_by_name(demo_task.name)
expect(tmpl_task.name).to eq(demo_task.name)
expect(tmpl_task.task_comments.size)
.to eq(demo_task.task_comments.size)
demo_task.results.each do |demo_res|
tmpl_res = tmpl_task.results.find_by_name(demo_res.name)
expect(tmpl_res.name).to eq(demo_res.name)
if demo_res.asset
expect(tmpl_res.asset.file.attached?).to eq(true)
expect(demo_res.asset.file_name)
.to eq(tmpl_res.asset.file_name)
elsif demo_res.table
expect(demo_res.table.contents).to eq(tmpl_res.table.contents)
elsif demo_res.result_text
expect(demo_res.result_text.text).to eq(tmpl_res.result_text.text)
end
expect(demo_res.result_comments.size)
.to eq(tmpl_res.result_comments.size)
end
unless demo_task.protocol.present? &&
demo_task.protocol.steps.size.positive?
next
end
demo_task.protocol.steps.each do |demo_step|
tmpl_step = tmpl_task.protocol.steps.find_by_name(demo_step.name)
expect(demo_step.name).to eq(tmpl_step.name)
expect(demo_step.description).to eq(tmpl_step.description)
if demo_step.assets.present?
expect(demo_step.assets.map(&:file_name))
.to match_array(tmpl_step.assets.map(&:file_name))
end
tmpl_tasks.each do |tmpl_task|
tmpl_task.protocol.steps.each do |tmpl_step|
tmpl_step.assets.each do |asset|
expect(asset.file.attached?).to eq(true)
end
if demo_step.tables.present?
expect(demo_step.tables.pluck(:contents))
.to match_array(tmpl_step.tables.pluck(:contents))
end
if demo_step.checklists.present?
expect(demo_step.checklists.pluck(:name))
.to match_array(tmpl_step.checklists.pluck(:name))
end
expect(demo_step.step_comments.size)
.to eq(tmpl_step.step_comments.size)
end
end
FileUtils.remove_dir(tmplts_dir)
end
end
end