1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Can get a conversation ID from a POST request

This commit is contained in:
2020-06-12 09:04:43 +02:00
parent bfd7cc0630
commit 619fc171e1
3 changed files with 28 additions and 3 deletions

View File

@ -12,7 +12,7 @@ use crate::data::api_client::APIClient;
use crate::data::config::conf;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper, user_helper};
use crate::helpers::{account_helper, api_helper, user_helper, conversations_helper};
use crate::utils::virtual_directories_utils::check_virtual_directory;
/// Http request handler
@ -264,6 +264,10 @@ impl HttpRequestHandler {
Ok(self.post_string(name)?.parse::<i64>()?)
}
pub fn post_u64(&mut self, name: &str) -> ResultBoxError<u64> {
Ok(self.post_string(name)?.parse::<u64>()?)
}
/// Get a boolean included in a POST request
pub fn post_bool(&mut self, name: &str) -> ResultBoxError<bool> {
Ok(self.post_string(name)?.eq("true"))
@ -343,4 +347,15 @@ impl HttpRequestHandler {
Ok(dir)
}
/// Get & return the ID of the conversation included in the POST request
pub fn post_conv_id(&mut self, name: &str) -> ResultBoxError<u64> {
let conv_id = self.post_u64(name)?;
if !conversations_helper::does_user_belongs_to(self.user_id()?, conv_id)? {
self.forbidden(format!("You do not belong to conversation {} !", conv_id))?;
}
Ok(conv_id)
}
}