1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 08:55:16 +00:00

Can get the list of available target to create new posts

This commit is contained in:
2020-07-09 13:26:39 +02:00
parent 82adbbcd6d
commit 05b743fa36
6 changed files with 64 additions and 2 deletions

View File

@ -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)

View File

@ -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)