scheduling creation of demo project at the sign in time

remove wrong schema, fix comment, add migration
This commit is contained in:
Miha Mencin 2019-03-04 18:11:50 +01:00
parent 2ba040980f
commit fa7bba9de7
4 changed files with 49 additions and 28 deletions

View file

@ -47,7 +47,17 @@ class Users::SessionsController < Devise::SessionsController
def after_sign_in
flash[:system_notification_modal] = true
# 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
end
protected

View file

@ -11,6 +11,38 @@ module FirstTimeDataGenerator
# Do nothing
return unless team
# Skip this team if user already has a demo project
return if team.projects.where(demo: true).any?
name = '[NEW] Demo project by SciNote'
exp_name = 'Polymerase chain reaction'
# If there is an existing demo project, archive and rename it
if team.projects.where(name: name).present?
# TODO: check if we still need this code
# old = team.projects.where(name: 'Demo project - qPCR')[0]
# old.archive! user
i = 1
while team.projects.where(
name: name = "#{name} (#{i})"
).present?
i += 1
end
end
project = Project.create(
visibility: 0,
name: name,
due_date: nil,
team: team,
created_by: user,
created_at: generate_random_time(1.week.ago),
last_modified_by: user,
archived: false,
template: false,
demo: true
)
# check if samples repo already exist, then create custom repository samples
repository = Repository.where(team: team).where(name: REPO_SAMPLES_NAME)
repository =
@ -192,33 +224,6 @@ module FirstTimeDataGenerator
)
end
name = 'Demo project'
name = '[NEW] Demo project by SciNote'
exp_name = 'Polymerase chain reaction'
# If there is an existing demo project, archive and rename it
if team.projects.where(name: name).present?
# TODO: check if we still need this code
# old = team.projects.where(name: 'Demo project - qPCR')[0]
# old.archive! user
i = 1
while team.projects.where(
name: name = "#{name} (#{i})"
).present?
i += 1
end
end
project = Project.create(
visibility: 0,
name: name,
due_date: nil,
team: team,
created_by: user,
created_at: generate_random_time(1.week.ago),
last_modified_by: user,
archived: false
)
experiment_description =
'Polymerase chain reaction (PCR) monitors the amplification of DNA ' \
'in real time (qPCR cyclers constantly scan qPCR plates). It is, in ' \

View file

@ -0,0 +1,5 @@
class AddDemoFlagToProject < ActiveRecord::Migration[5.1]
def change
add_column :projects, :demo, :boolean, null: false, default: false
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190227125352) do
ActiveRecord::Schema.define(version: 20190304153544) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -298,6 +298,7 @@ ActiveRecord::Schema.define(version: 20190227125352) do
t.datetime "restored_on"
t.string "experiments_order"
t.boolean "template"
t.boolean "demo", default: false, null: false
t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_projects_on_name", using: :gin
t.index ["archived_by_id"], name: "index_projects_on_archived_by_id"
t.index ["created_by_id"], name: "index_projects_on_created_by_id"