mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can determine post access level
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::user::UserID;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum PostVisibilityLevel {
|
||||
//Posts that can be seen by anyone
|
||||
@ -31,6 +32,33 @@ impl PostVisibilityLevel {
|
||||
}
|
||||
}
|
||||
|
||||
/// Post access level (for a given user)
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum PostAccessLevel {
|
||||
//When a user can't access to a post
|
||||
NO_ACCESS = 0,
|
||||
|
||||
//When a user can see a post and perform basic actions such as liking
|
||||
BASIC_ACCESS = 1,
|
||||
|
||||
//When a user has intermediate access to the post (delete post)
|
||||
INTERMEDIATE_ACCESS = 2,
|
||||
|
||||
//When a user has a full access to the post
|
||||
FULL_ACCESS = 3,
|
||||
}
|
||||
|
||||
impl PostAccessLevel {
|
||||
pub fn to_api(&self) -> String {
|
||||
match self {
|
||||
PostAccessLevel::NO_ACCESS => "no-access",
|
||||
PostAccessLevel::BASIC_ACCESS => "basic",
|
||||
PostAccessLevel::INTERMEDIATE_ACCESS => "intermediate",
|
||||
PostAccessLevel::FULL_ACCESS => "full",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum PostPageKind {
|
||||
PAGE_KIND_USER(UserID),
|
||||
|
@ -26,6 +26,14 @@ impl UserID {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.0 > 0
|
||||
}
|
||||
|
||||
/// Turn this `UserID` object as an instance. An invalid user id will become `None` variant
|
||||
pub fn as_option(&self) -> Option<UserID> {
|
||||
match self.is_valid() {
|
||||
true => Some(self.clone()),
|
||||
false => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
Reference in New Issue
Block a user