add: layouts api

This commit is contained in:
trisua 2025-07-02 20:14:04 -04:00
parent c83d0a9fc0
commit b493b2ade8
10 changed files with 353 additions and 22 deletions

View file

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::model::layouts::CustomizablePage;
use super::{
oauth::AuthGrant,
permissions::{FinePermission, SecondaryPermission},
@ -63,11 +61,6 @@ pub struct User {
/// Users collect achievements through little actions across the site.
#[serde(default)]
pub achievements: Vec<Achievement>,
/// The ID of each layout the user is using.
///
/// Only applies if the user is a supporter.
#[serde(default)]
pub layouts: HashMap<CustomizablePage, usize>,
}
pub type UserConnections =
@ -326,7 +319,6 @@ impl User {
invite_code: 0,
secondary_permissions: SecondaryPermission::DEFAULT,
achievements: Vec::new(),
layouts: HashMap::new(),
}
}

View file

@ -1,5 +1,6 @@
use std::{collections::HashMap, fmt::Display};
use serde::{Deserialize, Serialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
use crate::model::auth::DefaultTimelineChoice;
/// Each different page which can be customized.
@ -20,10 +21,26 @@ pub struct Layout {
pub title: String,
pub privacy: LayoutPrivacy,
pub pages: Vec<LayoutPage>,
pub replaces: CustomizablePage,
}
impl Layout {
/// Create a new [`Layout`].
pub fn new(title: String, owner: usize, replaces: CustomizablePage) -> Self {
Self {
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
created: unix_epoch_timestamp(),
owner,
title,
privacy: LayoutPrivacy::Public,
pages: Vec::new(),
replaces,
}
}
}
/// The privacy of the layout, which controls who has the ability to view it.
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, PartialEq, Eq)]
pub enum LayoutPrivacy {
Public,
Private,

View file

@ -68,8 +68,8 @@ pub enum AppScope {
UserReadJournals,
/// Read the user's notes.
UserReadNotes,
/// Read the user's links.
UserReadLinks,
/// Read the user's layouts.
UserReadLayouts,
/// Create posts as the user.
UserCreatePosts,
/// Create messages as the user.
@ -88,8 +88,8 @@ pub enum AppScope {
UserCreateJournals,
/// Create notes on behalf of the user.
UserCreateNotes,
/// Create links on behalf of the user.
UserCreateLinks,
/// Create layouts on behalf of the user.
UserCreateLayouts,
/// Delete posts owned by the user.
UserDeletePosts,
/// Delete messages owned by the user.
@ -124,8 +124,8 @@ pub enum AppScope {
UserManageJournals,
/// Manage the user's notes.
UserManageNotes,
/// Manage the user's links.
UserManageLinks,
/// Manage the user's layouts.
UserManageLayouts,
/// Edit posts created by the user.
UserEditPosts,
/// Edit drafts created by the user.