(ctx: &ReducerContext)
| 22 | |
| 23 | #[spacetimedb::settings] |
| 24 | const CASE_CONVERSION_POLICY: CaseConversionPolicy = CaseConversionPolicy::None; |
| 25 | |
| 26 | #[spacetimedb::reducer(init)] |
| 27 | pub fn initialize(ctx: &ReducerContext) -> Result<(), String> { |
| 28 | if let Some(config) = ctx.db.config().version().find(0) { |
| 29 | if config.env != "dev" { |
| 30 | // This check is to prevent access to this reducer after the db has been initialized. |
| 31 | if ServerIdentity::validate_server_or_admin(ctx).is_err() { |
| 32 | return Err("Caller is not the owner of the database".into()); |
| 33 | } |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | if ctx |
| 38 | .db |
| 39 | .identity_role() |
| 40 | .try_insert(IdentityRole { |
| 41 | role: Role::Admin, |
| 42 | identity: ctx.sender(), |
| 43 | }) |
| 44 | .is_err() |
| 45 | { |
| 46 | log::error!("Failed to insert owner identity"); |
| 47 | } |
| 48 | if ctx |
| 49 | .db |
| 50 | .identity_role() |
| 51 | .try_insert(IdentityRole { |
| 52 | role: Role::Admin, |
| 53 | identity: ctx.database_identity(), |
| 54 | }) |
| 55 | .is_err() |
| 56 | { |
| 57 | log::error!("Failed to insert database identity"); |
| 58 | } |
| 59 | |
| 60 | ServerIdentity::set(ctx); |
| 61 | |
| 62 | if ctx |
| 63 | .db |
| 64 | .admin_broadcast() |
| 65 | .try_insert(AdminBroadcast { |
| 66 | version: 0, |
| 67 | title: String::new(), |
| 68 | message: String::new(), |
| 69 | sign_out: false, |
| 70 | timestamp: ctx.timestamp, |
| 71 | }) |
| 72 | .is_err() |
| 73 | { |
| 74 | log::error!("Failed to insert AdminBroadcast"); |
| 75 | } |
| 76 | |
| 77 | if ctx |
| 78 | .db |
| 79 | .globals() |
| 80 | .try_insert(Globals { |
| 81 | version: 0, |
nothing calls this directly
no outgoing calls
no test coverage detected