From b7635deb8b614a44f1f335d8aec1c15edf790418 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 27 Nov 2026 12:06:03 +0300 Subject: [PATCH] Honor channel permission hints for file moves and directory downloads --- CHANGELOG.md | 2 ++ docs/mobile-port-progress.md | 2 ++ .../src/app/runtime/file_actions/browser.rs | 27 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6ba3ff..49ee54f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- The channel file browser disables Move when the channel denies rename. Download Folder requires both browsing and downloading permission. + - Check the dimensions of inline channel images before allocating decoded pixels. - Reject zero transfer IDs for pause, resume and cancel before dispatch. diff --git a/docs/mobile-port-progress.md b/docs/mobile-port-progress.md index 992f763..b22efb7 100644 --- a/docs/mobile-port-progress.md +++ b/docs/mobile-port-progress.md @@ -4,6 +4,8 @@ ## Возврат к разработке на ПК, 2026-11-26 +Windows, база `de99c5f`: файловый браузер учитывает запрет переименования для «Переместить» и запрет просмотра или скачивания для «Скачать папку». Четыре теста модели меню прошли. Проверка отображения разрешений не заменяет живое выполнение mkdir/rename/delete; эти команды остаются открытыми. + Windows, база `b4e084d`: закрыт `command:file_fetch_image` для классического beta14. Проверены байты и отрисовка PNG в окне Slint, а также отбрасывание устаревших результатов после переподключения. Ограничения размеров проверяются до декодирования растра. Прошли четыре нативных проверки и тест stdio. Стенд остановлен. Windows, база `c6cb353`: проверены `file_pause`, `file_resume` и `file_cancel` из панели Slint на классическом beta14. Отмена частично скачанного файла не оставила ни результата, ни временного файла; продолжение второй передачи дало точные 4 МиБ. Прошли живой тест, проверка границ ID через stdio и четыре теста ядра. Стенд остановлен. diff --git a/native/src/app/runtime/file_actions/browser.rs b/native/src/app/runtime/file_actions/browser.rs index 7019213..da566b9 100644 --- a/native/src/app/runtime/file_actions/browser.rs +++ b/native/src/app/runtime/file_actions/browser.rs @@ -50,7 +50,16 @@ fn project_browser(target:&Target,channel:u64,path:&str,reply:&Value,mode:Storag } if path!="/"{let up=Target{entity:Entity::File{channel_id:channel,path:parent(path),directory:true},name:"..".into(),..target.clone()};d.entries.insert(0,entry(up.clone(),"..".into(),String::new(),vec![action(&up,Operation::FileBrowse,c)]));} for row in &mut d.entries{ - if row.title!=".."{row.actions.push(action(&row.target,Operation::FileMove,c));if matches!(row.target.entity,Entity::File{directory:true,..}){row.actions.push(action(&row.target,Operation::FileDownload,c));row.actions.push(action(&row.target,Operation::FileCopyLink,c));}} + if row.title!=".."{ + let mut move_item=action(&row.target,Operation::FileMove,c); + if reply["capabilities"]["rename"]==false{move_item.enabled=false;move_item.reason=c.text("admin.denied");} + row.actions.push(move_item); + if matches!(row.target.entity,Entity::File{directory:true,..}){ + let mut download=action(&row.target,Operation::FileDownload,c); + if reply["capabilities"]["download"]==false||reply["capabilities"]["browse"]==false{download.enabled=false;download.reason=c.text("admin.denied");} + row.actions.push(download);row.actions.push(action(&row.target,Operation::FileCopyLink,c)); + } + } for a in &mut row.actions{a.form=None;mode.restrict(channel,a,c);} } Ok(d) @@ -148,6 +157,22 @@ mod tests { assert_eq!(StorageMode::from_server(&Value::Null,Some(&json!({"storage":{"s3":true}}))),mode); } + #[test] + fn legacy_move_and_folder_download_follow_channel_permissions() { + let catalog=Catalog::default(); + let target=Target{session:Some(SessionKey{connection_id:"c1".into(),session:1,generation:1}),entity:Entity::Channel{id:4},..Target::application()}; + for (rename,download,browse) in [(false,true,true),(true,false,true),(true,true,false),(true,true,true)] { + let reply=json!({"channel_id":4,"path":"/","entries":[{"name":"folder","type":"folder"},{"name":"file","type":"file"}], + "capabilities":{"rename":rename,"download":download,"browse":browse}}); + let panel=project_browser(&target,4,"/",&reply,StorageMode::Legacy,&catalog).unwrap(); + for row in &panel.entries { + let enabled=|op|row.actions.iter().find(|a|a.operation==op).unwrap().enabled; + assert_eq!(enabled(Operation::FileMove),rename); + assert_eq!(enabled(Operation::FileDownload),download && (row.title!="folder" || browse)); + } + } + } + #[test] fn signed_storage_and_channel_permissions_both_gate_file_actions() { let c=Catalog::default();