|
1 | | -alias CodeCorps.{Category, Organization, OrganizationMembership, Project, ProjectCategory, ProjectSkill, Repo, Role, Skill, Task, User} |
| 1 | +alias CodeCorps.{Category, Organization, OrganizationMembership, Project, ProjectCategory, ProjectSkill, Repo, Role, Skill, Task, User, UserCategory, UserRole, UserSkill} |
2 | 2 |
|
3 | 3 | # Users |
4 | 4 |
|
5 | 5 | users = [ |
6 | 6 | %{ |
7 | | - username: "adminstrator", |
8 | | - email: "admin@example.org", |
| 7 | + email: "owner@codecorps.org", |
| 8 | + first_name: "Code Corps", |
| 9 | + last_name: "Owner", |
9 | 10 | password: "password", |
10 | | - admin: true |
| 11 | + username: "codecorps-owner" |
11 | 12 | }, |
12 | 13 | %{ |
13 | | - username: "testuser", |
14 | | - email: "test@example.com", |
15 | | - password: "test123", |
16 | | - admin: false |
| 14 | + email: "admin@codecorps.org", |
| 15 | + first_name: "Code Corps", |
| 16 | + last_name: "Admin", |
| 17 | + password: "password", |
| 18 | + username: "codecorps-admin" |
17 | 19 | }, |
| 20 | + %{ |
| 21 | + email: "contributor@codecorps.org", |
| 22 | + first_name: "Code Corps", |
| 23 | + last_name: "Contributor", |
| 24 | + password: "password", |
| 25 | + username: "codecorps-contributor" |
| 26 | + }, |
| 27 | + %{ |
| 28 | + email: "pending@codecorps.org", |
| 29 | + first_name: "Code Corps", |
| 30 | + last_name: "Pending", |
| 31 | + password: "password", |
| 32 | + username: "codecorps-pending" |
| 33 | + } |
18 | 34 | ] |
19 | 35 |
|
20 | 36 | cond do |
21 | 37 | Repo.all(User) != [] -> |
22 | 38 | IO.puts "Users detected, aborting user seed." |
23 | 39 | true -> |
24 | 40 | Enum.each(users, fn user -> |
25 | | - %User{} |
26 | | - |> User.registration_changeset(user) |
27 | | - |> Repo.insert! |
| 41 | + result = |
| 42 | + %User{} |
| 43 | + |> User.registration_changeset(user) |
| 44 | + |> Repo.insert! |
| 45 | + |
| 46 | + result |
| 47 | + |> User.update_changeset(user) |
| 48 | + |> Repo.update! |
28 | 49 | end) |
29 | 50 | end |
30 | 51 |
|
@@ -287,7 +308,7 @@ cond do |
287 | 308 | number: i, |
288 | 309 | project_id: 1, |
289 | 310 | user_id: 1, |
290 | | - task_list_id: 1 |
| 311 | + task_list_id: Enum.random([1, 2, 3, 4]) |
291 | 312 | }) |
292 | 313 | |> Repo.insert! |
293 | 314 | end |
@@ -321,12 +342,127 @@ cond do |
321 | 342 | Repo.all(OrganizationMembership) != [] -> |
322 | 343 | IO.puts "Organization memberships detected, aborting this seed." |
323 | 344 | true -> |
324 | | - owner = %{ |
325 | | - organization_id: 1, |
326 | | - member_id: 1 |
327 | | - } |
| 345 | + contributors = [ |
| 346 | + %{ |
| 347 | + organization_id: 1, |
| 348 | + member_id: 1, |
| 349 | + role: "owner" |
| 350 | + }, |
| 351 | + %{ |
| 352 | + organization_id: 1, |
| 353 | + member_id: 2, |
| 354 | + role: "admin" |
| 355 | + }, |
| 356 | + %{ |
| 357 | + organization_id: 1, |
| 358 | + member_id: 3, |
| 359 | + role: "contributor" |
| 360 | + }, |
| 361 | + %{ |
| 362 | + organization_id: 1, |
| 363 | + member_id: 4, |
| 364 | + role: "pending" |
| 365 | + } |
| 366 | + ] |
328 | 367 |
|
329 | | - %OrganizationMembership{} |
330 | | - |> OrganizationMembership.create_owner_changeset(owner) |
331 | | - |> Repo.insert! |
| 368 | + Enum.each(contributors, fn user -> |
| 369 | + membership = |
| 370 | + %OrganizationMembership{} |
| 371 | + |> OrganizationMembership.create_changeset(user) |
| 372 | + |> Repo.insert! |
| 373 | + |
| 374 | + membership |
| 375 | + |> OrganizationMembership.update_changeset(user) |
| 376 | + |> Repo.update! |
| 377 | + end) |
| 378 | +end |
| 379 | + |
| 380 | +cond do |
| 381 | + Repo.all(UserCategory) != [] -> |
| 382 | + IO.puts "User categories detected, aborting this seed." |
| 383 | + true -> |
| 384 | + user_categories = [ |
| 385 | + %{ |
| 386 | + category_id: 1, |
| 387 | + user_id: 1 |
| 388 | + }, |
| 389 | + %{ |
| 390 | + category_id: 1, |
| 391 | + user_id: 2 |
| 392 | + }, |
| 393 | + %{ |
| 394 | + category_id: 1, |
| 395 | + user_id: 3 |
| 396 | + }, |
| 397 | + %{ |
| 398 | + category_id: 1, |
| 399 | + user_id: 4 |
| 400 | + } |
| 401 | + ] |
| 402 | + |
| 403 | + Enum.each(user_categories, fn user_category -> |
| 404 | + %UserCategory{} |
| 405 | + |> UserCategory.create_changeset(user_category) |
| 406 | + |> Repo.insert! |
| 407 | + end) |
| 408 | +end |
| 409 | + |
| 410 | +cond do |
| 411 | + Repo.all(UserRole) != [] -> |
| 412 | + IO.puts "User roles detected, aborting this seed." |
| 413 | + true -> |
| 414 | + user_roles = [ |
| 415 | + %{ |
| 416 | + role_id: 1, |
| 417 | + user_id: 1 |
| 418 | + }, |
| 419 | + %{ |
| 420 | + role_id: 1, |
| 421 | + user_id: 2 |
| 422 | + }, |
| 423 | + %{ |
| 424 | + role_id: 1, |
| 425 | + user_id: 3 |
| 426 | + }, |
| 427 | + %{ |
| 428 | + role_id: 1, |
| 429 | + user_id: 4 |
| 430 | + } |
| 431 | + ] |
| 432 | + |
| 433 | + Enum.each(user_roles, fn user_role -> |
| 434 | + %UserRole{} |
| 435 | + |> UserRole.create_changeset(user_role) |
| 436 | + |> Repo.insert! |
| 437 | + end) |
| 438 | +end |
| 439 | + |
| 440 | +cond do |
| 441 | + Repo.all(UserSkill) != [] -> |
| 442 | + IO.puts "User skills detected, aborting this seed." |
| 443 | + true -> |
| 444 | + user_skills = [ |
| 445 | + %{ |
| 446 | + skill_id: 1, |
| 447 | + user_id: 1 |
| 448 | + }, |
| 449 | + %{ |
| 450 | + skill_id: 1, |
| 451 | + user_id: 2 |
| 452 | + }, |
| 453 | + %{ |
| 454 | + skill_id: 1, |
| 455 | + user_id: 3 |
| 456 | + }, |
| 457 | + %{ |
| 458 | + skill_id: 1, |
| 459 | + user_id: 4 |
| 460 | + } |
| 461 | + ] |
| 462 | + |
| 463 | + Enum.each(user_skills, fn user_skill -> |
| 464 | + %UserSkill{} |
| 465 | + |> UserSkill.create_changeset(user_skill) |
| 466 | + |> Repo.insert! |
| 467 | + end) |
332 | 468 | end |
0 commit comments