Files
eminuxCRM/db/seeds.rb
T
eminuxandCursor c4e5f289cf
CI / scan_ruby (push) Failing after 11m20s
CI / scan_js (push) Successful in 10m35s
CI / lint (push) Has been cancelled
Commit iniziale di eminuxCRM: CRM Rails con pipeline, campagne email e Docker.
Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-17 23:01:48 +02:00

104 lines
3.2 KiB
Ruby

# frozen_string_literal: true
puts "Seeding eminuxCRM..."
Current.user = nil
admin = User.find_or_initialize_by(email: "admin@simplecrm.local")
admin.assign_attributes(
first_name: "Admin",
last_name: "eminuxCRM",
role: "admin",
password: "password123",
password_confirmation: "password123",
active: true
)
admin.save!
user1 = User.find_or_initialize_by(email: "marco@simplecrm.local")
user1.assign_attributes(
first_name: "Marco",
last_name: "Bianchi",
role: "user",
password: "password123",
password_confirmation: "password123",
active: true
)
user1.save!
user2 = User.find_or_initialize_by(email: "lucia@simplecrm.local")
user2.assign_attributes(
first_name: "Lucia",
last_name: "Verdi",
role: "user",
password: "password123",
password_confirmation: "password123",
active: true
)
user2.save!
Current.user = admin
projects = [
["MatchLiveTV", "matchlivetv", "Streaming e diritti sportivi", 0],
["RiskMeter", "riskmeter", "Risk management", 1],
["Cardoo", "cardoo", "Cardoo", 2]
].map do |name, code, description, position|
project = Project.find_or_initialize_by(code: code)
project.assign_attributes(name: name, description: description, position: position, active: true)
project.save!
project
end
matchlivetv, riskmeter, cardoo = projects
# Utenti normali: Marco → MatchLiveTV + RiskMeter; Lucia → MatchLiveTV + Cardoo
[user1, user2].each { |u| Project.find_each { |p| u.user_projects.find_or_create_by!(project: p) { |up| up.enabled = false } } }
user1.enable_project!(matchlivetv)
user1.enable_project!(riskmeter)
user1.disable_project!(cardoo)
user2.enable_project!(matchlivetv)
user2.enable_project!(cardoo)
user2.disable_project!(riskmeter)
Current.project = matchlivetv
%w[Light Full Partnership Evento Altro].each_with_index do |name, idx|
Product.find_or_create_by!(code: name.parameterize) do |p|
p.name = name
p.position = idx
p.active = true
end
end
goal = SalesGoal.find_or_initialize_by(name: "Prime 10 società paganti", project: matchlivetv)
goal.assign_attributes(
metric: "customers_acquired",
target_value: 10,
start_date: Date.new(2026, 8, 16),
end_date: Date.new(2026, 9, 30),
active: true
)
goal.save!
SalesGoal.where(project_id: matchlivetv.id).where.not(id: goal.id).update_all(active: false)
template = MailTemplate.find_or_initialize_by(project: matchlivetv, name: "Presentazione MatchLiveTV")
template.assign_attributes(
subject: "MatchLiveTV per {{societa}}",
body_html: <<~HTML
<p>Ciao {{contatto_nome}},</p>
<p>scriviamo a <strong>{{societa}}</strong> ({{regione}}) per presentarti MatchLiveTV.</p>
<p>Possiamo aiutarvi a trasmettere le giovanili in modo semplice, con un piano {{piano}}.</p>
<p>A presto,<br>Il team MatchLiveTV</p>
HTML
)
template.save!
puts "Seed completato (utenti, progetti, prodotti, obiettivo, template email)."
puts "Censimento MatchLiveTV: bin/rails matchlivetv:reset_campaign"
puts "Progetti: #{Project.ordered.map(&:name).join(', ')}"
puts "Utenti:"
puts " admin@simplecrm.local / password123 (admin — tutti i progetti)"
puts " marco@simplecrm.local / password123 (MatchLiveTV, RiskMeter)"
puts " lucia@simplecrm.local / password123 (MatchLiveTV, Cardoo)"