From aacf87cf40dfea20721561b7a45216bd22df5f85 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 25 Jun 2020 08:22:26 +0200 Subject: [PATCH] Fix issue --- src/helpers/groups_helper.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/helpers/groups_helper.rs b/src/helpers/groups_helper.rs index ee59ffb..47c0ce0 100644 --- a/src/helpers/groups_helper.rs +++ b/src/helpers/groups_helper.rs @@ -174,23 +174,26 @@ pub fn search_group(query: &str, limit: u64) -> ResultBoxError> { /// Get information about the membership of a user over a group pub fn get_membership(group_id: &GroupID, user_id: Option) -> ResultBoxError { + let default_membership = GroupMember { + id: 0, + user_id: 0, + group_id: group_id.clone(), + time_create: 0, + level: GroupMembershipLevel::VISITOR, + following: false, + }; + if user_id == None { - return Ok(GroupMember { - id: 0, - user_id: 0, - group_id: group_id.clone(), - time_create: 0, - level: GroupMembershipLevel::VISITOR, - following: false, - }); + return Ok(default_membership); } let user_id = user_id.unwrap(); - database::QueryInfo::new(GROUPS_MEMBERS_TABLE) + Ok(database::QueryInfo::new(GROUPS_MEMBERS_TABLE) .cond_group_id("groups_id", group_id) .cond_user_id("user_id", user_id) .query_row(db_to_group_member) + .unwrap_or(default_membership)) } /// Get the membership level of a user for a group