//! The seeded people: three fixed harness accounts and the ordinary users //! everything else is written as. use mt_core::types::CommunityRole; use sqlx::PgPool; use uuid::Uuid; pub(super) struct SeedUser { pub(super) id: Uuid, } /// A harness account: the local row plus the roles it carries per community. pub(super) struct HarnessUser { pub(super) id: Uuid, pub(super) rust_role: CommunityRole, pub(super) music_role: CommunityRole, } /// The three accounts the browser harness logs in as. /// /// `mnw_account_id` is the join to MNW and these values are fixed on both /// sides: the MNW example seed creates the same three ids in /// `server/src/seed/harness.rs`, which is what lets roles be assigned here /// before anyone has logged in. The two lists have to be edited together, and /// the MNW side has a test pinning the literals to make that hard to forget. /// /// `is_fan_plus`/`is_creator` mirror the perks MNW will report at login. They /// are denormalised onto the row for post rendering, and login overwrites them /// from userinfo, so seeding them wrong is cosmetic rather than a privilege /// question. Seed them right anyway: a pre-login render of a seeded post is one /// of the things the harness looks at. pub(super) async fn seed_harness_users(pool: &PgPool) -> Vec { let harness_data = [ ( "00000000-0000-0000-0000-00000000f001", "harness_fan", "Harness Fan", true, false, CommunityRole::Member, CommunityRole::Member, ), ( "00000000-0000-0000-0000-00000000f002", "harness_creator", "Harness Creator", false, true, CommunityRole::Member, CommunityRole::Member, ), ( "00000000-0000-0000-0000-00000000f003", "harness_owner", "Harness Owner", false, false, CommunityRole::Owner, CommunityRole::Moderator, ), ]; let mut users = Vec::new(); for (uuid_str, username, display_name, is_fan_plus, is_creator, rust_role, music_role) in harness_data { let id = Uuid::parse_str(uuid_str).unwrap(); sqlx::query( "INSERT INTO users (mnw_account_id, username, display_name, is_fan_plus, is_creator) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (mnw_account_id) DO UPDATE SET username = EXCLUDED.username, display_name = EXCLUDED.display_name, is_fan_plus = EXCLUDED.is_fan_plus, is_creator = EXCLUDED.is_creator", ) .bind(id) .bind(username) .bind(display_name) .bind(is_fan_plus) .bind(is_creator) .execute(pool) .await .expect("failed to seed harness user"); users.push(HarnessUser { id, rust_role, music_role, }); } users } pub(super) async fn seed_users(pool: &PgPool) -> Vec { let user_data = [ ("00000000-0000-0000-0000-000000000001", "admin", "Admin"), ("00000000-0000-0000-0000-000000000002", "maxmj", "Max"), ( "00000000-0000-0000-0000-000000000003", "synthwave99", "Juno", ), ("00000000-0000-0000-0000-000000000004", "basshunter", "Erik"), ("00000000-0000-0000-0000-000000000005", "tape_hiss", "Rae"), ("00000000-0000-0000-0000-000000000006", "drumroom", "Cole"), ("00000000-0000-0000-0000-000000000007", "patchwork", "Lina"), ("00000000-0000-0000-0000-000000000008", "detuned", "Kai"), ("00000000-0000-0000-0000-000000000009", "resampled", "Noor"), ("00000000-0000-0000-0000-00000000000a", "clipgain", "Wren"), ]; let mut users = Vec::new(); for (uuid_str, username, display_name) in &user_data { let id = Uuid::parse_str(uuid_str).unwrap(); sqlx::query( "INSERT INTO users (mnw_account_id, username, display_name) VALUES ($1, $2, $3) ON CONFLICT (mnw_account_id) DO NOTHING", ) .bind(id) .bind(username) .bind(display_name) .execute(pool) .await .expect("failed to seed user"); users.push(SeedUser { id }); } users }