mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can get the list of available target to create new posts
This commit is contained in:
parent
82adbbcd6d
commit
05b743fa36
@ -35,4 +35,5 @@ pub mod movie_api;
|
||||
pub mod survey_choice_api;
|
||||
pub mod survey_api;
|
||||
pub mod comment_api;
|
||||
pub mod res_create_post;
|
||||
pub mod res_create_post;
|
||||
pub mod posts_targets_api;
|
22
src/api_data/posts_targets_api.rs
Normal file
22
src/api_data/posts_targets_api.rs
Normal file
@ -0,0 +1,22 @@
|
||||
//! # Posts targets
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::user::UserID;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct PostsTargets {
|
||||
friends: Vec<u64>,
|
||||
groups: Vec<u64>,
|
||||
}
|
||||
|
||||
impl PostsTargets {
|
||||
pub fn new(f: &Vec<UserID>, g: &Vec<GroupID>) -> PostsTargets {
|
||||
PostsTargets {
|
||||
friends: f.iter().map(|f| f.id()).collect(),
|
||||
groups: g.iter().map(|f| f.id()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::api_data::post_api::PostAPI;
|
||||
use crate::api_data::posts_targets_api::PostsTargets;
|
||||
use crate::api_data::res_create_post::ResCreatePost;
|
||||
use crate::constants::{PATH_POST_IMAGES, PATH_POST_PDF};
|
||||
use crate::controllers::routes::RequestResult;
|
||||
@ -11,7 +12,7 @@ use crate::data::group::GroupAccessLevel;
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::new_survey::NewSurvey;
|
||||
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink};
|
||||
use crate::helpers::{groups_helper, posts_helper, survey_helper, user_helper};
|
||||
use crate::helpers::{friends_helper, groups_helper, posts_helper, survey_helper, user_helper};
|
||||
use crate::utils::date_utils::time;
|
||||
use crate::utils::string_utils::{check_string_before_insert, check_youtube_id};
|
||||
use crate::utils::user_data_utils::user_data_path;
|
||||
@ -268,4 +269,12 @@ pub fn delete(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
posts_helper::delete(&post)?;
|
||||
|
||||
r.success("Post deleted.")
|
||||
}
|
||||
|
||||
/// Get the list of targets where the current user can create posts
|
||||
pub fn get_targets(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let friends = friends_helper::get_list_that_allow_posts_from_user(r.user_id_ref()?)?;
|
||||
let groups = groups_helper::get_list_where_user_can_create_posts(r.user_id_ref()?)?;
|
||||
|
||||
r.set_response(PostsTargets::new(&friends, &groups))
|
||||
}
|
@ -214,6 +214,8 @@ pub fn get_routes() -> Vec<Route> {
|
||||
|
||||
Route::post("/posts/delete", Box::new(posts_controller::delete)),
|
||||
|
||||
Route::post("/posts/getAvailableTargets", Box::new(posts_controller::get_targets)),
|
||||
|
||||
|
||||
// Movies controller
|
||||
Route::post("/movies/get_list", Box::new(movies_controller::get_list)),
|
||||
|
@ -83,6 +83,15 @@ fn get_list(friend_query: &GetFriendsQuery) -> ResultBoxError<Vec<Friend>> {
|
||||
query.exec(db_to_friend)
|
||||
}
|
||||
|
||||
/// get the list of friends that allows a given user to create posts on their page
|
||||
pub fn get_list_that_allow_posts_from_user(user_id: &UserID) -> ResultBoxError<Vec<UserID>> {
|
||||
database::QueryInfo::new(FRIENDS_TABLE)
|
||||
.cond_legacy_bool("autoriser_post_page", true)
|
||||
.cond_user_id("ID_amis", user_id)
|
||||
.add_field("ID_personne as user_id")
|
||||
.exec(|r| r.get_user_id("user_id"))
|
||||
}
|
||||
|
||||
/// Send a new friendship request
|
||||
pub fn send_request(user_id: &UserID, target_user: &UserID) -> ResultBoxError {
|
||||
database::InsertQuery::new(FRIENDS_TABLE)
|
||||
|
@ -164,6 +164,25 @@ pub fn get_list_user(user_id: &UserID, only_followed: bool) -> ResultBoxError<Ve
|
||||
query.exec(|row| row.get_group_id("groups_id"))
|
||||
}
|
||||
|
||||
|
||||
/// Get the list of groups where a given user can create posts
|
||||
pub fn get_list_where_user_can_create_posts(user_id: &UserID) -> ResultBoxError<Vec<GroupID>> {
|
||||
database::QueryInfo::new(GROUPS_MEMBERS_TABLE)
|
||||
.alias("m")
|
||||
.join(GROUPS_LIST_TABLE, "g", "m.groups_id = g.id")
|
||||
|
||||
.cond_user_id("user_id", user_id)
|
||||
|
||||
.set_custom_where("level = ? OR level = ? OR (level = ? AND posts_level = ?)")
|
||||
.add_custom_where_argument_u32(GroupMembershipLevel::ADMINISTRATOR.to_db())
|
||||
.add_custom_where_argument_u32(GroupMembershipLevel::MODERATOR.to_db())
|
||||
.add_custom_where_argument_u32(GroupMembershipLevel::MEMBER.to_db())
|
||||
.add_custom_where_argument_u32(GroupPostsCreationLevel::POSTS_LEVEL_ALL_MEMBERS.to_db())
|
||||
|
||||
.add_field("g.id")
|
||||
.exec(|r| r.get_group_id("id"))
|
||||
}
|
||||
|
||||
/// Get information about a group
|
||||
pub fn get_info(group_id: &GroupID) -> ResultBoxError<Group> {
|
||||
database::QueryInfo::new(GROUPS_LIST_TABLE)
|
||||
|
Loading…
Reference in New Issue
Block a user