diff --git a/Cargo.toml b/Cargo.toml index 410b47d2..b4f31dee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ features = ["database", "i18n"] [features] # ===== DEFAULT ===== -default = ["chat", "people", "automation", "drive", "tasks", "cache", "directory", "llm", "crawler", "browser", "terminal", "editor", "mail", "whatsapp", "designer", "marketing"] +default = ["chat", "people", "automation", "drive", "tasks", "cache", "directory", "llm", "crawler", "browser", "terminal", "editor", "mail", "whatsapp", "designer", "marketing", "goals", "analytics"] browser = ["automation", "drive", "cache"] terminal = ["automation", "drive", "cache"] diff --git a/src/analytics/goals.rs b/src/analytics/goals.rs index be4d2233..112dd3b1 100644 --- a/src/analytics/goals.rs +++ b/src/analytics/goals.rs @@ -112,6 +112,7 @@ pub struct Objective { pub id: Uuid, pub organization_id: Uuid, pub owner_id: Uuid, + pub owner_name: Option, pub parent_id: Option, pub title: String, pub description: String, @@ -402,6 +403,7 @@ pub struct CreateObjectiveRequest { pub parent_id: Option, pub visibility: Option, pub tags: Option>, + pub owner_id: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -465,6 +467,7 @@ fn record_to_objective(record: ObjectiveRecord) -> Objective { id: record.id, organization_id: record.org_id, owner_id: record.owner_id, + owner_name: None, parent_id: record.parent_id, title: record.title, description: record.description.unwrap_or_default(), @@ -589,11 +592,13 @@ pub async fn list_objectives( pub async fn create_objective( State(state): State>, + user: crate::security::auth::AuthenticatedUser, Json(req): Json, ) -> Result, GoalsError> { let pool = state.conn.clone(); let (org_id, bot_id) = get_bot_context(); - let owner_id = Uuid::nil(); + let owner_id = req.owner_id.unwrap_or(user.user_id); + let owner_name = Some(user.username.clone()); let now = Utc::now(); let tags: Vec> = req.tags.unwrap_or_default().into_iter().map(Some).collect(); @@ -632,7 +637,9 @@ pub async fn create_objective( .map_err(|e| GoalsError::Database(e.to_string()))??; info!("Created objective: {} ({})", record.title, record.id); - Ok(Json(record_to_objective(record))) + let mut obj = record_to_objective(record); + obj.owner_name = owner_name; + Ok(Json(obj)) } pub async fn get_objective( @@ -760,12 +767,13 @@ pub async fn list_key_results( pub async fn create_key_result( State(state): State>, + user: crate::security::auth::AuthenticatedUser, Path(objective_id): Path, Json(req): Json, ) -> Result, GoalsError> { let pool = state.conn.clone(); let (org_id, bot_id) = get_bot_context(); - let owner_id = Uuid::nil(); + let owner_id = user.user_id; let now = Utc::now(); let start_value = req.start_value.unwrap_or(0.0); @@ -889,12 +897,13 @@ pub async fn delete_key_result( pub async fn create_check_in( State(state): State>, + user: crate::security::auth::AuthenticatedUser, Path(key_result_id): Path, Json(req): Json, ) -> Result, GoalsError> { let pool = state.conn.clone(); let (org_id, bot_id) = get_bot_context(); - let user_id = Uuid::nil(); + let user_id = user.user_id; let now = Utc::now(); let pool_clone = pool.clone(); diff --git a/src/analytics/goals_ui.rs b/src/analytics/goals_ui.rs index 90d4749d..a3318fbd 100644 --- a/src/analytics/goals_ui.rs +++ b/src/analytics/goals_ui.rs @@ -288,8 +288,32 @@ pub async fn dashboard_stats(State(state): State>) -> Html } } -pub async fn new_objective_form() -> Html { - Html(r##" +
+ + +