mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-20 14:15:22 +00:00
Upgrade UserID to a structure
This commit is contained in:
src
api_data
conversation_api.rsconversation_message_api.rscurrent_user_id.rscustom_emoji.rsglobal_search_result_api.rslist_unread_conversations_api.rsres_find_user_by_virtual_directory.rsres_find_virtual_directory.rsuser_info.rs
controllers
data
helpers
account_helper.rsbackground_image_helper.rsconversations_helper.rscustom_emojies_helper.rsdatabase.rsfriends_helper.rsgroups_helper.rslikes_helper.rsuser_helper.rs
utils
@@ -367,7 +367,7 @@ impl HttpRequestHandler {
|
||||
|
||||
/// Get user ID. This function assess that a user ID is available to continue
|
||||
pub fn user_id(&self) -> ResultBoxError<UserID> {
|
||||
match self.curr_user_id {
|
||||
match self.curr_user_id.clone() {
|
||||
Some(s) => Ok(s),
|
||||
None => Err(ExecError::boxed_new("Could not get required user ID!"))
|
||||
}
|
||||
@@ -375,7 +375,7 @@ impl HttpRequestHandler {
|
||||
|
||||
/// Get a user ID, if available
|
||||
pub fn user_id_opt(&self) -> Option<UserID> {
|
||||
self.curr_user_id
|
||||
self.curr_user_id.clone()
|
||||
}
|
||||
|
||||
/// Get an email included in the request
|
||||
@@ -390,7 +390,7 @@ impl HttpRequestHandler {
|
||||
}
|
||||
|
||||
/// Get a list of integers included in the request
|
||||
pub fn post_numbers_list(&mut self, name: &str, min_len: usize) -> ResultBoxError<Vec<i64>> {
|
||||
pub fn post_numbers_list(&mut self, name: &str, min_len: usize) -> ResultBoxError<Vec<u64>> {
|
||||
let param = self.post_string_opt(name, min_len, min_len != 0)?;
|
||||
let mut list = vec![];
|
||||
|
||||
@@ -399,7 +399,7 @@ impl HttpRequestHandler {
|
||||
continue;
|
||||
}
|
||||
|
||||
list.push(split.parse::<i64>()?);
|
||||
list.push(split.parse::<u64>()?);
|
||||
}
|
||||
|
||||
if list.len() < min_len {
|
||||
@@ -411,14 +411,14 @@ impl HttpRequestHandler {
|
||||
|
||||
/// Get the ID of a user included in a POST request
|
||||
pub fn post_user_id(&mut self, name: &str) -> ResultBoxError<UserID> {
|
||||
let user_id = self.post_i64(name)?;
|
||||
let user_id = UserID::new(self.post_u64(name)?);
|
||||
|
||||
if user_id < 1 {
|
||||
if user_id.id() < 1 {
|
||||
self.bad_request(format!("Invalid user specified in '{}'!", name))?;
|
||||
}
|
||||
|
||||
if !user_helper::exists(user_id)? {
|
||||
self.not_found(format!("User with ID {} not found!", user_id))?;
|
||||
if !user_helper::exists(&user_id)? {
|
||||
self.not_found(format!("User with ID {} not found!", user_id.id()))?;
|
||||
}
|
||||
|
||||
Ok(user_id)
|
||||
@@ -444,7 +444,7 @@ impl HttpRequestHandler {
|
||||
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)? {
|
||||
if !conversations_helper::does_user_belongs_to(&self.user_id()?, conv_id)? {
|
||||
self.forbidden(format!("You do not belong to conversation {} !", conv_id))?;
|
||||
}
|
||||
|
||||
|
@@ -3,14 +3,31 @@ use crate::utils::user_data_utils::user_data_url;
|
||||
///! User information
|
||||
///!
|
||||
///! @author Pierre Hubert
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct UserID(u64);
|
||||
|
||||
pub type UserID = i64;
|
||||
impl UserID {
|
||||
/// Initialize a new user ID object
|
||||
pub fn new(id: u64) -> UserID {
|
||||
UserID(id)
|
||||
}
|
||||
|
||||
/// Get the current ID stored in this structure
|
||||
pub fn id(&self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Check if the ID currently stored in this structure is valid or not
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.0 > 0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum UserPageStatus {
|
||||
OPEN,
|
||||
PUBLIC,
|
||||
PRIVATE
|
||||
PRIVATE,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -18,7 +35,7 @@ pub enum UserPageStatus {
|
||||
pub enum AccountImageVisibility {
|
||||
FRIENDS,
|
||||
COMUNIC_USERS,
|
||||
EVERYONE
|
||||
EVERYONE,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -41,7 +58,6 @@ pub struct User {
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
||||
/// Get the URL pointing to the default account image
|
||||
pub fn default_account_image_url() -> String {
|
||||
user_data_url(crate::constants::DEFAULT_ACCOUNT_IMAGE)
|
||||
|
Reference in New Issue
Block a user