diff --git a/bin/tau/tau-cli/src/jsonrpc.rs b/bin/tau/tau-cli/src/jsonrpc.rs index 01f3f3bdf..8f23d5096 100644 --- a/bin/tau/tau-cli/src/jsonrpc.rs +++ b/bin/tau/tau-cli/src/jsonrpc.rs @@ -84,10 +84,10 @@ pub async fn get_state(url: &str, id: u64) -> Result { } // Set comment for a task and returns `true` upon success. -// --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_author, comment_content], "id": 1} +// --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_content], "id": 1} // <-- {"jsonrpc": "2.0", "result": true, "id": 1} -pub async fn set_comment(url: &str, id: u64, author: &str, content: &str) -> Result { - let req = jsonrpc::request(json!("set_comment"), json!([id, author, content])); +pub async fn set_comment(url: &str, id: u64, content: &str) -> Result { + let req = jsonrpc::request(json!("set_comment"), json!([id, content])); request(req, url.to_string()).await } diff --git a/bin/tau/tau-cli/src/main.rs b/bin/tau/tau-cli/src/main.rs index c0f6724a6..49ada93c0 100644 --- a/bin/tau/tau-cli/src/main.rs +++ b/bin/tau/tau-cli/src/main.rs @@ -68,8 +68,8 @@ async fn start(mut options: CliTau) -> Result<()> { let rank = rank.unwrap_or(0.0); add(rpc_addr, - json!([{"title": title, "desc": desc, "assign": assign, "project": project, "due": due, "rank": rank}]), - ).await?; + json!([{"title": title, "desc": desc, "assign": assign, "project": project, "due": due, "rank": rank}]), + ).await?; } Some(CliTauSubCommands::Update { id, key, value }) => { @@ -111,18 +111,16 @@ async fn start(mut options: CliTau) -> Result<()> { } }, - Some(CliTauSubCommands::Comment { id, author, content }) => match (author, content) { - (Some(author), Some(content)) => { - set_comment(rpc_addr, id, author.trim(), content.trim()).await?; + Some(CliTauSubCommands::Comment { id, content }) => match content { + Some(content) => { + set_comment(rpc_addr, id, content.trim()).await?; } - (None, None) => { + None => { let rep = get_by_id(rpc_addr, id).await?; let comments = get_comments(rep)?; println!("Comments on Task with id {}:\n{}", id, comments); } - (None, Some(_)) => error!("Please provide the author name"), - (Some(_), None) => error!("Please provide some content"), }, Some(CliTauSubCommands::List {}) | None => { diff --git a/bin/tau/tau-cli/src/util.rs b/bin/tau/tau-cli/src/util.rs index ac8557b5f..177614876 100644 --- a/bin/tau/tau-cli/src/util.rs +++ b/bin/tau/tau-cli/src/util.rs @@ -58,8 +58,6 @@ pub enum CliTauSubCommands { Comment { /// Task ID id: u64, - /// Comment author - author: Option, /// Comment content content: Option, }, @@ -73,6 +71,7 @@ pub struct TaskInfo { pub id: u32, pub title: String, pub desc: String, + pub owner: String, pub assign: Vec, pub project: Vec, pub due: Option, @@ -190,6 +189,7 @@ pub fn desc_in_editor() -> Result> { pub fn show_task(task: Value, taskinfo: TaskInfo, current_state: String) -> Result<()> { let mut table = table!([Bd => "ref_id", &taskinfo.ref_id], ["id", &taskinfo.id.to_string()], + [Bd =>"owner", &taskinfo.owner], [Bd =>"title", &taskinfo.title], ["desc", &taskinfo.desc], [Bd =>"assign", get_from_task(task.clone(), "assign")?], diff --git a/bin/tau/taud/src/jsonrpc.rs b/bin/tau/taud/src/jsonrpc.rs index cba91c893..0f9f70b44 100644 --- a/bin/tau/taud/src/jsonrpc.rs +++ b/bin/tau/taud/src/jsonrpc.rs @@ -24,10 +24,11 @@ use crate::{ pub struct JsonRpcInterface { dataset_path: PathBuf, notify_queue_sender: async_channel::Sender>, + nickname: String, } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct BaseTaskInfo { +struct BaseTaskInfo { title: String, desc: String, assign: Vec, @@ -70,8 +71,9 @@ impl JsonRpcInterface { pub fn new( notify_queue_sender: async_channel::Sender>, dataset_path: PathBuf, + nickname: String, ) -> Self { - Self { notify_queue_sender, dataset_path } + Self { notify_queue_sender, dataset_path, nickname } } // RPCAPI: @@ -94,8 +96,14 @@ impl JsonRpcInterface { let args = params.as_array().unwrap(); let task: BaseTaskInfo = serde_json::from_value(args[0].clone())?; - let mut new_task: TaskInfo = - TaskInfo::new(&task.title, &task.desc, task.due, task.rank, &self.dataset_path)?; + let mut new_task: TaskInfo = TaskInfo::new( + &task.title, + &task.desc, + &self.nickname, + task.due, + task.rank, + &self.dataset_path, + )?; new_task.set_project(&task.project); new_task.set_assign(&task.assign); @@ -174,21 +182,20 @@ impl JsonRpcInterface { // RPCAPI: // Set comment for a task and returns `true` upon success. - // --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_author, comment_content], "id": 1} + // --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_content], "id": 1} // <-- {"jsonrpc": "2.0", "result": true, "id": 1} async fn set_comment(&self, params: Value) -> TaudResult { debug!(target: "tau", "JsonRpc::set_comment() params {}", params); let args = params.as_array().unwrap(); - if args.len() != 3 { + if args.len() != 2 { return Err(TaudError::InvalidData("len of params should be 3".into())) } - let comment_author: String = serde_json::from_value(args[1].clone())?; - let comment_content: String = serde_json::from_value(args[2].clone())?; + let comment_content: String = serde_json::from_value(args[1].clone())?; let mut task: TaskInfo = self.load_task_by_id(&args[0])?; - task.set_comment(Comment::new(&comment_content, &comment_author)); + task.set_comment(Comment::new(&comment_content, &self.nickname)); self.notify_queue_sender.send(Some(task)).await.map_err(Error::from)?; Ok(json!(true)) diff --git a/bin/tau/taud/src/main.rs b/bin/tau/taud/src/main.rs index 4b9f62682..881cd4071 100644 --- a/bin/tau/taud/src/main.rs +++ b/bin/tau/taud/src/main.rs @@ -1,5 +1,5 @@ use async_std::sync::{Arc, Mutex}; -use std::fs::create_dir_all; +use std::{env, fs::create_dir_all}; use async_executor::Executor; use crypto_box::{aead::Aead, Box, SecretKey, KEY_SIZE}; @@ -86,6 +86,14 @@ async_daemonize!(realmain); async fn realmain(settings: Args, executor: Arc>) -> Result<()> { let datastore_path = expand_path(&settings.datastore)?; + let nickname = + if settings.nickname.is_some() { settings.nickname } else { env::var("USER").ok() }; + + if nickname.is_none() { + error!("Provide a nickname in config file"); + return Ok(()) + } + // mkdir datastore_path if not exists create_dir_all(datastore_path.join("month"))?; create_dir_all(datastore_path.join("task"))?; @@ -99,14 +107,17 @@ async fn realmain(settings: Args, executor: Arc>) -> Result<()> { save::(&datastore_path.join("secret_key"), &sk_string)?; secret } else { - let loaded_key = match load::(&datastore_path.join("secret_key")) { - Ok(key) => key, - Err(_) => { - error!("Could not load secret key from file, please run \"taud --help\" for more information"); - return Ok(()) - } - }; - let sk_bytes = hex::decode(loaded_key)?; + let loaded_key = load::(&datastore_path.join("secret_key")); + + if loaded_key.is_err() { + error!( + "Could not load secret key from file, \ + please run \"taud --help\" for more information" + ); + return Ok(()) + } + + let sk_bytes = hex::decode(loaded_key.unwrap())?; let sk_bytes: [u8; KEY_SIZE] = sk_bytes.as_slice().try_into()?; SecretKey::try_from(sk_bytes)? }; @@ -124,7 +135,8 @@ async fn realmain(settings: Args, executor: Arc>) -> Result<()> { let (rpc_snd, rpc_rcv) = async_channel::unbounded::>(); - let rpc_interface = Arc::new(JsonRpcInterface::new(rpc_snd, datastore_path.clone())); + let rpc_interface = + Arc::new(JsonRpcInterface::new(rpc_snd, datastore_path.clone(), nickname.unwrap())); let executor_cloned = executor.clone(); let rpc_listener_task = diff --git a/bin/tau/taud/src/month_tasks.rs b/bin/tau/taud/src/month_tasks.rs index 7ed46c673..2c03e680a 100644 --- a/bin/tau/taud/src/month_tasks.rs +++ b/bin/tau/taud/src/month_tasks.rs @@ -154,7 +154,8 @@ mod tests { // load and save TaskInfo /////////////////////// - let mut task = TaskInfo::new("test_title", "test_desc", None, 0.0, &dataset_path)?; + let mut task = + TaskInfo::new("test_title", "test_desc", "NICKNAME", None, 0.0, &dataset_path)?; task.save(&dataset_path)?; @@ -194,7 +195,8 @@ mod tests { // activate task /////////////////////// - let task = TaskInfo::new("test_title_3", "test_desc", None, 0.0, &dataset_path)?; + let task = + TaskInfo::new("test_title_3", "test_desc", "NICKNAME", None, 0.0, &dataset_path)?; task.save(&dataset_path)?; diff --git a/bin/tau/taud/src/settings.rs b/bin/tau/taud/src/settings.rs index 3e8a8b832..9e53948cd 100644 --- a/bin/tau/taud/src/settings.rs +++ b/bin/tau/taud/src/settings.rs @@ -31,4 +31,7 @@ pub struct Args { /// Generate a new secret key #[structopt(long)] pub key_gen: bool, + /// Current display name + #[structopt(long)] + pub nickname: Option, } diff --git a/bin/tau/taud/src/task_info.rs b/bin/tau/taud/src/task_info.rs index a6a025355..db1628874 100644 --- a/bin/tau/taud/src/task_info.rs +++ b/bin/tau/taud/src/task_info.rs @@ -53,6 +53,7 @@ pub struct TaskInfo { id: u32, title: String, desc: String, + owner: String, assign: TaskAssigns, project: TaskProjects, due: Option, @@ -66,6 +67,7 @@ impl TaskInfo { pub fn new( title: &str, desc: &str, + owner: &str, due: Option, rank: f32, dataset_path: &Path, @@ -91,6 +93,7 @@ impl TaskInfo { id, title: title.into(), desc: desc.into(), + owner: owner.into(), assign: TaskAssigns(vec![]), project: TaskProjects(vec![]), due, diff --git a/bin/tau/taud_config.toml b/bin/tau/taud_config.toml index abc02f065..db54a75d8 100644 --- a/bin/tau/taud_config.toml +++ b/bin/tau/taud_config.toml @@ -4,6 +4,9 @@ ## Sets Datastore Path #datastore="~/.config/tau" +## Current display name +#nickname="NICKNAME" + ## Raft net settings [net] ## P2P accept address