add: letters api

This commit is contained in:
trisua 2025-08-02 00:44:23 -04:00
parent 46e38042ce
commit 2e60cbc464
9 changed files with 247 additions and 31 deletions

View file

@ -1,5 +1,6 @@
use serde::{Serialize, Deserialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
use crate::model::auth::User;
/// A letter is the most basic structure of the mail system. Letters are sent
/// and received by users.
@ -41,4 +42,9 @@ impl Letter {
replying_to,
}
}
/// Check if the given user can read the letter.
pub fn can_read(&self, user: &User) -> bool {
(user.id == self.owner) | self.receivers.contains(&user.id)
}
}

View file

@ -76,6 +76,8 @@ pub enum AppScope {
UserReadServices,
/// Read the user's products.
UserReadProducts,
/// Read the user's letters.
UserReadLetters,
/// Create posts as the user.
UserCreatePosts,
/// Create messages as the user.
@ -102,6 +104,8 @@ pub enum AppScope {
UserCreateServices,
/// Create products on behalf of the user.
UserCreateProducts,
/// Create letters on behalf of the user.
UserCreateLetters,
/// Delete posts owned by the user.
UserDeletePosts,
/// Delete messages owned by the user.
@ -146,6 +150,8 @@ pub enum AppScope {
UserManageProducts,
/// Manage the user's channel mutes.
UserManageChannelMutes,
/// Manage the user's letters.
UserManageLetters,
/// Edit posts created by the user.
UserEditPosts,
/// Edit drafts created by the user.