feat: add multi-user support and role-based access control #31

This commit is contained in:
rustmailer
2025-12-26 14:27:04 +08:00
parent 1e2f526a07
commit 4af5176b65
181 changed files with 23745 additions and 3187 deletions
+26 -26
View File
@@ -17,10 +17,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::modules::database::manager::DB_MANAGER;
use crate::modules::database::{find_impl, upsert_impl};
use crate::modules::error::BichonResult;
use crate::utc_now;
// use crate::modules::database::manager::DB_MANAGER;
// use crate::modules::database::{find_impl, upsert_impl};
// use crate::modules::error::BichonResult;
// use crate::utc_now;
use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
@@ -37,34 +37,34 @@ pub struct SystemSetting {
}
impl SystemSetting {
pub fn new(key: String, value: String) -> Self {
Self {
key,
value,
created_at: utc_now!(),
updated_at: utc_now!(),
}
}
// pub fn new(key: String, value: String) -> Self {
// Self {
// key,
// value,
// created_at: utc_now!(),
// updated_at: utc_now!(),
// }
// }
//overwrite
pub async fn set(&self) -> BichonResult<()> {
upsert_impl(DB_MANAGER.meta_db(), self.to_owned()).await
}
// pub async fn set(&self) -> BichonResult<()> {
// upsert_impl(DB_MANAGER.meta_db(), self.to_owned()).await
// }
pub fn get(key: &str) -> BichonResult<Option<SystemSetting>> {
find_impl(DB_MANAGER.meta_db(), key)
}
// pub fn get(key: &str) -> BichonResult<Option<SystemSetting>> {
// find_impl(DB_MANAGER.meta_db(), key)
// }
// pub async fn list() -> RustMailerResult<Vec<SystemSetting>> {
// list_all_impl(DB_MANAGER.metadata_db()).await
// }
pub fn get_existing_value(key: &str) -> BichonResult<Option<String>> {
let setting = Self::get(key)?;
Ok(setting.map(|s| s.value))
}
// pub fn get_existing_value(key: &str) -> BichonResult<Option<String>> {
// let setting = Self::get(key)?;
// Ok(setting.map(|s| s.value))
// }
pub async fn set_value(key: &str, value: String) -> BichonResult<()> {
let setting = Self::new(key.to_string(), value);
setting.set().await
}
// pub async fn set_value(key: &str, value: String) -> BichonResult<()> {
// let setting = Self::new(key.to_string(), value);
// setting.set().await
// }
}