1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-01-01 00:18:50 +00:00
comunicapiv3/src/data/group_member.rs

68 lines
2.0 KiB
Rust
Raw Normal View History

2020-06-24 07:08:31 +00:00
//! # Group membership information
//!
//! @author Pierre Hubert
use crate::data::group_id::GroupID;
2020-06-27 16:28:38 +00:00
use crate::data::user::UserID;
2020-06-24 07:08:31 +00:00
2020-06-27 16:28:38 +00:00
#[derive(PartialEq, Eq, PartialOrd)]
2020-06-24 07:08:31 +00:00
pub enum GroupMembershipLevel {
ADMINISTRATOR = 0,
MODERATOR = 1,
MEMBER = 2,
INVITED = 3,
2020-06-27 16:28:38 +00:00
// When the group membership has not been approved yet
PENDING = 4,
// Simple visit
VISITOR = 5,
2020-06-24 07:08:31 +00:00
}
2020-06-25 06:16:20 +00:00
impl GroupMembershipLevel {
pub fn to_api(&self) -> String {
match self {
GroupMembershipLevel::ADMINISTRATOR => "administrator",
GroupMembershipLevel::MODERATOR => "moderator",
GroupMembershipLevel::MEMBER => "member",
GroupMembershipLevel::INVITED => "invited",
GroupMembershipLevel::PENDING => "pending",
GroupMembershipLevel::VISITOR => "visitor",
}.to_string()
}
2020-06-29 06:17:51 +00:00
pub fn from_api(level: &str) -> GroupMembershipLevel {
match level {
"administrator" => GroupMembershipLevel::ADMINISTRATOR,
"moderator" => GroupMembershipLevel::MODERATOR,
"member" => GroupMembershipLevel::MEMBER,
"invited" => GroupMembershipLevel::INVITED,
"pending" => GroupMembershipLevel::PENDING,
"visitor" => GroupMembershipLevel::VISITOR,
_ => GroupMembershipLevel::VISITOR,
}
}
2020-06-25 06:16:20 +00:00
}
2020-06-24 07:08:31 +00:00
pub struct GroupMember {
pub id: u64,
pub user_id: UserID,
pub group_id: GroupID,
pub time_create: u64,
pub level: GroupMembershipLevel,
2020-06-27 16:28:38 +00:00
pub following: bool,
}
#[cfg(test)]
mod tests {
use crate::data::group_member::GroupMembershipLevel;
#[test]
fn membership_level_coherence() {
assert!(GroupMembershipLevel::ADMINISTRATOR < GroupMembershipLevel::MODERATOR);
assert!(GroupMembershipLevel::MODERATOR < GroupMembershipLevel::MEMBER);
assert!(GroupMembershipLevel::MEMBER < GroupMembershipLevel::INVITED);
assert!(GroupMembershipLevel::INVITED < GroupMembershipLevel::PENDING);
assert!(GroupMembershipLevel::PENDING < GroupMembershipLevel::VISITOR);
}
2020-06-24 07:08:31 +00:00
}