mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +08:00
Merge pull request #1549 from biosistemika/mm-sci-3119-create-templates-at-login
Prepare a mechanism to schedule the template creation at user login
This commit is contained in:
commit
0bd40dca4e
5 changed files with 60 additions and 28 deletions
|
@ -47,6 +47,17 @@ class Users::SessionsController < Devise::SessionsController
|
||||||
|
|
||||||
def after_sign_in
|
def after_sign_in
|
||||||
flash[:system_notification_modal] = true
|
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
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -55,4 +55,14 @@ class TemplatesService
|
||||||
end
|
end
|
||||||
[updated_counter, processed_counter]
|
[updated_counter, processed_counter]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def schedule_creation_for_user(user)
|
||||||
|
user.teams.each do |team|
|
||||||
|
next if team.projects.where(template: true).any?
|
||||||
|
|
||||||
|
TemplatesService.new.delay(
|
||||||
|
queue: :templates
|
||||||
|
).update_team(team)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,37 @@ module FirstTimeDataGenerator
|
||||||
# Do nothing
|
# Do nothing
|
||||||
return unless team
|
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
|
# check if samples repo already exist, then create custom repository samples
|
||||||
repository = Repository.where(team: team).where(name: REPO_SAMPLES_NAME)
|
repository = Repository.where(team: team).where(name: REPO_SAMPLES_NAME)
|
||||||
repository =
|
repository =
|
||||||
|
@ -192,33 +223,6 @@ module FirstTimeDataGenerator
|
||||||
)
|
)
|
||||||
end
|
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 =
|
experiment_description =
|
||||||
'Polymerase chain reaction (PCR) monitors the amplification of DNA ' \
|
'Polymerase chain reaction (PCR) monitors the amplification of DNA ' \
|
||||||
'in real time (qPCR cyclers constantly scan qPCR plates). It is, in ' \
|
'in real time (qPCR cyclers constantly scan qPCR plates). It is, in ' \
|
||||||
|
|
6
db/migrate/20190304153544_add_demo_flag_to_project.rb
Normal file
6
db/migrate/20190304153544_add_demo_flag_to_project.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
class AddDemoFlagToProject < ActiveRecord::Migration[5.1]
|
||||||
|
def change
|
||||||
|
add_column :projects, :demo, :boolean, null: false, default: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -298,6 +298,7 @@ ActiveRecord::Schema.define(version: 20190227125352) do
|
||||||
t.datetime "restored_on"
|
t.datetime "restored_on"
|
||||||
t.string "experiments_order"
|
t.string "experiments_order"
|
||||||
t.boolean "template"
|
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 "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 ["archived_by_id"], name: "index_projects_on_archived_by_id"
|
||||||
t.index ["created_by_id"], name: "index_projects_on_created_by_id"
|
t.index ["created_by_id"], name: "index_projects_on_created_by_id"
|
||||||
|
|
Loading…
Add table
Reference in a new issue