mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 08:25:16 +00:00
Can get information about a single post
This commit is contained in:
@ -16,8 +16,9 @@ use crate::data::config::conf;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::group::GroupAccessLevel;
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::post::{Post, PostAccessLevel};
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, user_helper, virtual_directory_helper};
|
||||
use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, posts_helper, user_helper, virtual_directory_helper};
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
use crate::utils::string_utils::{check_url, remove_html_nodes};
|
||||
use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path};
|
||||
@ -545,4 +546,19 @@ impl HttpRequestHandler {
|
||||
|
||||
Ok(Some(dir))
|
||||
}
|
||||
|
||||
/// Get information about a post whose ID was specified in the request
|
||||
pub fn post_post_with_access(&mut self, name: &str, min_level: PostAccessLevel) -> ResultBoxError<Post> {
|
||||
let post_id = self.post_u64(name)?;
|
||||
let post = self.ok_or_not_found(
|
||||
posts_helper::get_single(post_id),
|
||||
"Requested post not found!",
|
||||
)?;
|
||||
|
||||
if posts_helper::get_access_level(&post, &self.user_id_opt())? < min_level {
|
||||
self.forbidden("You are not allowed to access this post information!".to_string())?;
|
||||
}
|
||||
|
||||
Ok(post)
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ impl PostVisibilityLevel {
|
||||
|
||||
/// Post access level (for a given user)
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(PartialEq, PartialOrd)]
|
||||
pub enum PostAccessLevel {
|
||||
//When a user can't access to a post
|
||||
NO_ACCESS = 0,
|
||||
@ -141,4 +142,16 @@ impl Post {
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::data::post::PostAccessLevel;
|
||||
|
||||
#[test]
|
||||
fn access_level_coherence() {
|
||||
assert!(PostAccessLevel::NO_ACCESS < PostAccessLevel::BASIC_ACCESS);
|
||||
assert!(PostAccessLevel::BASIC_ACCESS < PostAccessLevel::INTERMEDIATE_ACCESS);
|
||||
assert!(PostAccessLevel::INTERMEDIATE_ACCESS < PostAccessLevel::FULL_ACCESS);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user