fixes and functions
This commit is contained in:
+31
-2
@@ -173,6 +173,32 @@ async fn has_write_permission(
|
||||
}
|
||||
}
|
||||
|
||||
async fn upload_limit_for_request(
|
||||
state: &SharedState,
|
||||
headers: &HeaderMap,
|
||||
) -> Result<Option<usize>, ApiError> {
|
||||
if session_user(state, headers).await?.is_some() {
|
||||
return Ok(Some(state.upload_max_size_bytes));
|
||||
}
|
||||
Ok(state
|
||||
.guest_upload_enabled
|
||||
.then_some(state.guest_upload_max_size_bytes))
|
||||
}
|
||||
|
||||
async fn resource_upload_limit(
|
||||
state: &SharedState,
|
||||
headers: &HeaderMap,
|
||||
kind: &str,
|
||||
slug: &str,
|
||||
) -> Result<Option<usize>, ApiError> {
|
||||
let Some(limit) = upload_limit_for_request(state, headers).await? else {
|
||||
return Ok(None);
|
||||
};
|
||||
Ok(has_write_permission(state, headers, kind, slug)
|
||||
.await?
|
||||
.then_some(limit))
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PublishResponse {
|
||||
url: Option<String>,
|
||||
@@ -380,6 +406,7 @@ pub struct NoteInfo {
|
||||
updated_at: String,
|
||||
can_delete_files: bool,
|
||||
can_upload_files: bool,
|
||||
upload_max_size_bytes: Option<usize>,
|
||||
global_color: Option<String>,
|
||||
note_color: Option<String>,
|
||||
authorship_mode: String,
|
||||
@@ -996,8 +1023,9 @@ pub async fn note_info(
|
||||
has_password_write_access(&state, &headers, "workspace", &workspace_slug).await?;
|
||||
let can_manage_authorship = workspace_owner || note_owner || password_write_access;
|
||||
let can_delete_files = can_manage_authorship;
|
||||
let can_upload_files = session_user(&state, &headers).await?.is_some()
|
||||
&& has_write_permission(&state, &headers, "workspace", &workspace_slug).await?;
|
||||
let upload_max_size_bytes =
|
||||
resource_upload_limit(&state, &headers, "workspace", &workspace_slug).await?;
|
||||
let can_upload_files = upload_max_size_bytes.is_some();
|
||||
let can_save_editor_settings = (personal_editor_settings || can_manage_authorship)
|
||||
&& has_write_permission(&state, &headers, "workspace", &workspace_slug).await?;
|
||||
|
||||
@@ -1024,6 +1052,7 @@ pub async fn note_info(
|
||||
updated_at: db::normalize_timestamp(¬e.updated_at),
|
||||
can_delete_files,
|
||||
can_upload_files,
|
||||
upload_max_size_bytes,
|
||||
global_color,
|
||||
note_color,
|
||||
authorship_mode: resource_editor_settings.authorship_mode,
|
||||
|
||||
Reference in New Issue
Block a user