new finctions and fixes
This commit is contained in:
+69
-19
@@ -38,7 +38,16 @@ pub struct PadInfo {
|
||||
note_color: Option<String>,
|
||||
authorship_mode: String,
|
||||
colors_enabled: bool,
|
||||
compact_view: bool,
|
||||
editor_line_numbers: bool,
|
||||
preview_line_numbers: bool,
|
||||
line_links: bool,
|
||||
font_family: String,
|
||||
font_size: i64,
|
||||
personal_editor_settings: bool,
|
||||
can_save_editor_settings: bool,
|
||||
can_manage_authorship: bool,
|
||||
files: Vec<MarkdownFileReference>,
|
||||
}
|
||||
|
||||
pub async fn create_pad(
|
||||
@@ -92,14 +101,24 @@ pub async fn pad_info(
|
||||
)
|
||||
.await?;
|
||||
let (global_color, note_color) = editor_colors(&state, &headers, "pad", &slug).await?;
|
||||
let (authorship_mode, colors_enabled) = editor_settings(&state, "pad", &slug).await?;
|
||||
let can_save_editor_settings =
|
||||
crate::auth::resource_permission(&state, "pad", &slug, bearer_token(&headers))
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.as_deref()
|
||||
== Some("rw");
|
||||
let (editor_preferences, personal_editor_settings) = user_editor_preferences(
|
||||
&state,
|
||||
&headers,
|
||||
db::EditorPreferenceResource::Pad(pad.id),
|
||||
)
|
||||
.await?;
|
||||
let resource_editor_settings =
|
||||
db::load_resource_editor_settings(&state.db, "pad", &slug).await?;
|
||||
let can_manage_authorship = crate::auth::is_resource_owner(
|
||||
&state,
|
||||
"pad",
|
||||
&slug,
|
||||
user_session_token(&headers),
|
||||
)
|
||||
.await
|
||||
.unwrap_or(false);
|
||||
let can_save_editor_settings = personal_editor_settings
|
||||
&& has_write_permission(&state, &headers, "pad", &slug).await?;
|
||||
if pad.is_private == 0
|
||||
&& !db::pad_public_page_disabled(&state.db, pad.id).await?
|
||||
&& !db::pad_public_page_enabled(&state.db, pad.id).await?
|
||||
@@ -116,19 +135,21 @@ pub async fn pad_info(
|
||||
private: pad.is_private != 0,
|
||||
created_at: db::normalize_timestamp(&pad.created_at),
|
||||
updated_at: db::normalize_timestamp(&pad.updated_at),
|
||||
can_delete_files: crate::auth::is_resource_owner(
|
||||
&state,
|
||||
"pad",
|
||||
&slug,
|
||||
bearer_token(&headers),
|
||||
)
|
||||
.await
|
||||
.unwrap_or(false),
|
||||
can_delete_files: can_manage_authorship,
|
||||
global_color,
|
||||
note_color,
|
||||
authorship_mode,
|
||||
colors_enabled,
|
||||
authorship_mode: resource_editor_settings.authorship_mode,
|
||||
colors_enabled: resource_editor_settings.colors_enabled,
|
||||
compact_view: editor_preferences.compact_view,
|
||||
editor_line_numbers: editor_preferences.editor_line_numbers,
|
||||
preview_line_numbers: editor_preferences.preview_line_numbers,
|
||||
line_links: editor_preferences.line_links,
|
||||
font_family: editor_preferences.font_family,
|
||||
font_size: editor_preferences.font_size,
|
||||
personal_editor_settings,
|
||||
can_save_editor_settings,
|
||||
can_manage_authorship,
|
||||
files: markdown_file_references(&state, Some(pad.id), None, None).await?,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -138,7 +159,20 @@ pub async fn set_pad_editor_settings(
|
||||
Path(slug): Path<String>,
|
||||
Json(payload): Json<EditorSettingsRequest>,
|
||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||
save_editor_settings(&state, &headers, "pad", &slug, "pad", &slug, payload).await
|
||||
let pad = db::find_pad(&state.db, &slug)
|
||||
.await?
|
||||
.ok_or_else(ApiError::not_found_note)?;
|
||||
save_editor_settings(
|
||||
&state,
|
||||
&headers,
|
||||
"pad",
|
||||
&slug,
|
||||
"pad",
|
||||
&slug,
|
||||
db::EditorPreferenceResource::Pad(pad.id),
|
||||
payload,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn pad_editor_color(
|
||||
@@ -382,11 +416,19 @@ pub async fn public_page(
|
||||
.await?
|
||||
.ok_or_else(ApiError::not_found_note)?;
|
||||
ensure_public_page_access(&state, &headers, &page).await?;
|
||||
let files = markdown_file_references(
|
||||
&state,
|
||||
page.pad_id,
|
||||
page.note_id,
|
||||
Some(&page.content),
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(PublicPageResponse {
|
||||
title: page.title,
|
||||
content: page.content,
|
||||
updated_at: db::normalize_timestamp(&page.updated_at),
|
||||
allow_task_updates: page.allow_task_updates,
|
||||
files,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -408,11 +450,19 @@ pub async fn update_public_task(
|
||||
let page = db::update_public_task(&state.db, &token, payload.source_line, payload.checked)
|
||||
.await?
|
||||
.ok_or_else(ApiError::not_found_note)?;
|
||||
let files = markdown_file_references(
|
||||
&state,
|
||||
page.pad_id,
|
||||
page.note_id,
|
||||
Some(&page.content),
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(PublicPageResponse {
|
||||
title: page.title,
|
||||
content: page.content,
|
||||
updated_at: db::normalize_timestamp(&page.updated_at),
|
||||
allow_task_updates: page.allow_task_updates,
|
||||
files,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user