From 4c30cd201e611af54c2f9f1113a37568543db48d Mon Sep 17 00:00:00 2001 From: Sphereso Date: Thu, 11 Jul 2024 22:48:16 +0200 Subject: [PATCH] backend: add admin flag --- crates/entity/src/user.rs | 3 +++ crates/migration/src/m20240705_100914_create_user.rs | 2 ++ .../src/m20240708_085852_create_admin_user.rs | 10 ++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/entity/src/user.rs b/crates/entity/src/user.rs index c9836c0..1adb33f 100644 --- a/crates/entity/src/user.rs +++ b/crates/entity/src/user.rs @@ -19,6 +19,7 @@ pub struct Model { pub name: String, pub email: String, pub hash: String, + pub admin: bool, } #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] @@ -27,6 +28,7 @@ pub enum Column { Name, Email, Hash, + Admin, } #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] @@ -52,6 +54,7 @@ impl ColumnTrait for Column { Self::Name => ColumnType::String(None).def(), Self::Email => ColumnType::String(None).def().unique(), Self::Hash => ColumnType::String(None).def(), + Self::Admin => ColumnType::Boolean.def(), } } } diff --git a/crates/migration/src/m20240705_100914_create_user.rs b/crates/migration/src/m20240705_100914_create_user.rs index 2c8146c..739cc63 100644 --- a/crates/migration/src/m20240705_100914_create_user.rs +++ b/crates/migration/src/m20240705_100914_create_user.rs @@ -21,6 +21,7 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(User::Name).string().not_null()) .col(ColumnDef::new(User::Email).string().not_null().unique_key()) .col(ColumnDef::new(User::Hash).string().not_null()) + .col(ColumnDef::new(User::Admin).boolean().not_null()) .to_owned(), ) .await @@ -40,4 +41,5 @@ enum User { Name, Email, Hash, + Admin, } diff --git a/crates/migration/src/m20240708_085852_create_admin_user.rs b/crates/migration/src/m20240708_085852_create_admin_user.rs index df2bd1c..3f7539d 100644 --- a/crates/migration/src/m20240708_085852_create_admin_user.rs +++ b/crates/migration/src/m20240708_085852_create_admin_user.rs @@ -17,8 +17,13 @@ impl MigrationTrait for Migration { .expect("Generating Admin Password Hash failed"); let insert = Query::insert() .into_table(User::Table) - .columns([User::Name, User::Email, User::Hash]) - .values_panic(["admin".into(), "admin".into(), hash.to_string().into()]) + .columns([User::Name, User::Email, User::Hash, User::Admin]) + .values_panic([ + "admin".into(), + "admin".into(), + hash.to_string().into(), + true.into(), + ]) .to_owned(); manager.exec_stmt(insert).await?; @@ -36,4 +41,5 @@ enum User { Name, Email, Hash, + Admin, }