mirror of
https://github.com/modrinth/code.git
synced 2026-08-31 12:05:53 +00:00
Merge branch 'main' into boris/dev-1126-v2
This commit is contained in:
@@ -42,6 +42,7 @@ pub struct LegacyResultSearchProject {
|
||||
pub client_side: String,
|
||||
pub server_side: String,
|
||||
pub environment: Vec<String>,
|
||||
pub disclosure_types: Vec<String>,
|
||||
pub gallery: Vec<String>,
|
||||
pub featured_gallery: Option<String>,
|
||||
pub color: Option<u32>,
|
||||
@@ -151,8 +152,11 @@ impl LegacyResultSearchProject {
|
||||
client_side,
|
||||
server_side,
|
||||
environment: environments,
|
||||
disclosure_types: result_search_project.disclosure_types,
|
||||
versions,
|
||||
latest_version: result_search_project.version_id,
|
||||
latest_version: result_search_project
|
||||
.version_id
|
||||
.unwrap_or_default(),
|
||||
categories,
|
||||
|
||||
project_id: result_search_project.project_id,
|
||||
|
||||
@@ -111,8 +111,10 @@ impl DisclosureLockStatus {
|
||||
pub struct ProjectDisclosureData {
|
||||
#[serde(flatten)]
|
||||
pub disclosure: ProjectDisclosure,
|
||||
pub set_by_moderator: bool,
|
||||
pub lock_status: DisclosureLockStatus,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub set_by_moderator: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub lock_status: Option<DisclosureLockStatus>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub updated_by: Option<UserId>,
|
||||
@@ -124,16 +126,18 @@ impl ProjectDisclosureData {
|
||||
pub fn from_db(
|
||||
value: DBProjectDisclosure,
|
||||
viewer_is_moderator: bool,
|
||||
viewer_is_member: bool,
|
||||
) -> Self {
|
||||
let updated_by = (!value.set_by_moderator || viewer_is_moderator)
|
||||
.then_some(value.updated_by.into());
|
||||
|
||||
Self {
|
||||
disclosure: value.disclosure,
|
||||
set_by_moderator: value.set_by_moderator,
|
||||
lock_status: value.lock_status,
|
||||
set_by_moderator: (viewer_is_member || viewer_is_moderator)
|
||||
.then_some(value.set_by_moderator),
|
||||
lock_status: (viewer_is_member || viewer_is_moderator)
|
||||
.then_some(value.lock_status),
|
||||
updated_at: value.updated_at,
|
||||
updated_by,
|
||||
updated_by: ((!value.set_by_moderator && viewer_is_member)
|
||||
|| viewer_is_moderator)
|
||||
.then_some(value.updated_by.into()),
|
||||
deleted_at: value.deleted_at,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ pub mod organizations;
|
||||
pub mod pack;
|
||||
pub mod pats;
|
||||
pub mod payouts;
|
||||
pub mod preferences;
|
||||
pub mod projects;
|
||||
pub mod reports;
|
||||
pub mod sessions;
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
use component_derive::Component;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema, Default, Component)]
|
||||
pub struct UserPreferences {
|
||||
#[component(nested)]
|
||||
pub appearance: AppearancePreferences,
|
||||
#[component(nested)]
|
||||
pub behavior: BehaviorPreferences,
|
||||
#[component(nested)]
|
||||
pub localization: LocalizationPreferences,
|
||||
#[component(nested)]
|
||||
pub layouts: LayoutPreferences,
|
||||
#[component(nested)]
|
||||
pub sidebars: SidebarPreferences,
|
||||
#[component(nested)]
|
||||
pub social: SocialPreferences,
|
||||
}
|
||||
|
||||
impl UserPreferences {
|
||||
pub fn resolve(overrides: Option<PartialUserPreferences>) -> Self {
|
||||
let mut preferences = Self::default();
|
||||
if let Some(overrides) = overrides {
|
||||
overrides.apply_to(&mut preferences);
|
||||
}
|
||||
preferences
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, ToSchema, Default, PartialEq, Component,
|
||||
)]
|
||||
pub struct AppearancePreferences {
|
||||
pub auto: bool,
|
||||
pub theme: Theme,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Component)]
|
||||
pub struct BehaviorPreferences {
|
||||
pub minimize_app: bool,
|
||||
pub hide_right_sidebar: bool,
|
||||
pub show_jump_in: bool,
|
||||
pub compact_instance_cards: bool,
|
||||
pub show_play_time: bool,
|
||||
pub hide_nametag: bool,
|
||||
pub warn_on_unknown_modpacks: bool,
|
||||
pub skip_non_essential_warnings: bool,
|
||||
}
|
||||
|
||||
impl Default for BehaviorPreferences {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
minimize_app: false,
|
||||
hide_right_sidebar: false,
|
||||
show_jump_in: true,
|
||||
compact_instance_cards: false,
|
||||
show_play_time: true,
|
||||
hide_nametag: false,
|
||||
warn_on_unknown_modpacks: true,
|
||||
skip_non_essential_warnings: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, ToSchema, Default, Clone, PartialEq,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Theme {
|
||||
Light,
|
||||
#[default]
|
||||
Dark,
|
||||
Oled,
|
||||
Retro,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Component)]
|
||||
pub struct LocalizationPreferences {
|
||||
pub locale: String,
|
||||
}
|
||||
|
||||
impl Default for LocalizationPreferences {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
locale: "en-US".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Component)]
|
||||
pub struct LayoutPreferences {
|
||||
pub mods: LayoutOption,
|
||||
pub plugins: LayoutOption,
|
||||
pub datapacks: LayoutOption,
|
||||
pub shaders: LayoutOption,
|
||||
pub resourcepacks: LayoutOption,
|
||||
pub modpacks: LayoutOption,
|
||||
pub servers: LayoutOption,
|
||||
pub users: LayoutOption,
|
||||
}
|
||||
|
||||
impl Default for LayoutPreferences {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mods: LayoutOption::Rows,
|
||||
plugins: LayoutOption::Rows,
|
||||
datapacks: LayoutOption::Rows,
|
||||
shaders: LayoutOption::Grid,
|
||||
resourcepacks: LayoutOption::Grid,
|
||||
modpacks: LayoutOption::Rows,
|
||||
servers: LayoutOption::Rows,
|
||||
users: LayoutOption::Rows,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum LayoutOption {
|
||||
Grid,
|
||||
Rows,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, ToSchema, Default, PartialEq, Component,
|
||||
)]
|
||||
pub struct SidebarPreferences {
|
||||
pub right_aligned_search: bool,
|
||||
pub left_aligned_content: bool,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, ToSchema, Default, PartialEq, Component,
|
||||
)]
|
||||
pub struct SocialPreferences {
|
||||
pub friend_privacy: FriendPrivacy,
|
||||
pub shared_instances_privacy: InvitePrivacy,
|
||||
pub hosting_access_privacy: InvitePrivacy,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, ToSchema, Default, Clone, PartialEq,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum FriendPrivacy {
|
||||
None,
|
||||
Mutual,
|
||||
#[default]
|
||||
Everyone,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, ToSchema, Default, Clone, PartialEq,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InvitePrivacy {
|
||||
None,
|
||||
Friends,
|
||||
#[default]
|
||||
Everyone,
|
||||
}
|
||||
Reference in New Issue
Block a user