From 93a71667109d7110d9c538e4e8873f79b03d83b6 Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 26 Mar 2020 13:20:20 -0600 Subject: [PATCH] Add hidden upload directory as mail action --- api/src/Sharing.php | 1 + api/src/Vfs/HiddenUploadSharing.php | 5 +-- filemanager/inc/class.filemanager_ui.inc.php | 12 ++++++ filemanager/js/app.js | 38 +++++++++++++++++ filemanager/js/app.ts | 45 ++++++++++++++++++++ mail/inc/class.mail_compose.inc.php | 2 +- 6 files changed, 98 insertions(+), 5 deletions(-) diff --git a/api/src/Sharing.php b/api/src/Sharing.php index 659cf60043..8c95b43b9f 100644 --- a/api/src/Sharing.php +++ b/api/src/Sharing.php @@ -691,6 +691,7 @@ class Sharing $arr['title'] = lang('Filemanager directory'); break; case 'shareUploadDir': + case 'mail_shareUploadDir': $arr['title'] = lang('Upload directory'); break; } diff --git a/api/src/Vfs/HiddenUploadSharing.php b/api/src/Vfs/HiddenUploadSharing.php index 0208cb8c78..530b0659b7 100644 --- a/api/src/Vfs/HiddenUploadSharing.php +++ b/api/src/Vfs/HiddenUploadSharing.php @@ -103,10 +103,7 @@ class HiddenUploadSharing extends Sharing $path = parent::validate_path($path, $mode); // Set up anonymous upload directory - if ($action_id == 'shareUploadDir') - { - static::create_hidden_upload($path, $extra); - } + static::create_hidden_upload($path, $extra); return parent::create($action_id, $path, $mode, $name, $recipients, $extra); } diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index c7a3e36264..d73da8c3c0 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -290,6 +290,18 @@ class filemanager_ui $actions['share']['children']['share_mail']['children']['mail_'.$mode]['disableClass'] = 'isDir'; } } + foreach(Vfs\HiddenUploadSharing::$modes as $mode => $data) + { + $actions['share']['children']['share_mail']['children']['mail_shareUploadDir'] = array( + 'caption' => $data['label'], + 'hint' => $data['title'], + 'icon' => 'upload', + 'group' => 3, + 'data' => ['share_writable' => $mode], + 'enabled' => 'javaScript:app.filemanager.hidden_upload_enabled', + 'onExecute' => 'javaScript:app.filemanager.mail_share_link', + ); + } } // This would be done automatically, but we're overriding diff --git a/filemanager/js/app.js b/filemanager/js/app.js index c1e468c104..8dd846f604 100644 --- a/filemanager/js/app.js +++ b/filemanager/js/app.js @@ -241,6 +241,44 @@ var filemanagerAPP = /** @class */ (function (_super) { 'preset[filemode]': _action.id.substr(5) }); }; + /** + * Mail files action: open compose with already linked files + * We're only interested in hidden upload shares here, open_mail can handle + * the rest + * + * @param {egwAction} _action + * @param {egwActionObject[]} _selected + */ + filemanagerAPP.prototype.mail_share_link = function (_action, _selected) { + if (_action.id !== 'mail_shareUploadDir') { + return this.mail(_action, _selected); + } + var path = this.id2path(_selected[0].id); + this.share_link(_action, _selected, null, false, false, this._mail_link_callback); + return true; + }; + /** + * Callback with the share link to append to an email + * + * @param {Object} _data + * @param {String} _data.share_link Link to the share + * @param {String} _data.title Title for the link + * @param {String} [_data.msg] Error message + */ + filemanagerAPP.prototype._mail_link_callback = function (_data) { + debugger; + if (_data.msg || !_data.share_link) + window.egw_refresh(_data.msg, this.appname); + var params = { + 'preset[body]': '' + _data.title + '', + 'mimeType': 'html' // always open compose in html mode, as attachment links look a lot nicer in html + }; + var content = { + mail_htmltext: ['
' + _data.title + ''], + mail_plaintext: ["\n" + _data.share_link] + }; + return egw.openWithinWindow("mail", "setCompose", content, params, /mail.mail_compose.compose/); + }; /** * Trigger Upload after each file is uploaded * @param {type} _event diff --git a/filemanager/js/app.ts b/filemanager/js/app.ts index 38ca96e172..1e4f074dbf 100644 --- a/filemanager/js/app.ts +++ b/filemanager/js/app.ts @@ -275,6 +275,51 @@ export class filemanagerAPP extends EgwApp }); } + /** + * Mail files action: open compose with already linked files + * We're only interested in hidden upload shares here, open_mail can handle + * the rest + * + * @param {egwAction} _action + * @param {egwActionObject[]} _selected + */ + mail_share_link(_action, _selected) + { + if(_action.id !== 'mail_shareUploadDir') + { + return this.mail(_action, _selected); + } + let path = this.id2path(_selected[0].id); + + this.share_link(_action, _selected, null, false, false, this._mail_link_callback); + + return true; + } + + /** + * Callback with the share link to append to an email + * + * @param {Object} _data + * @param {String} _data.share_link Link to the share + * @param {String} _data.title Title for the link + * @param {String} [_data.msg] Error message + */ + _mail_link_callback(_data) + { + debugger; + if (_data.msg || !_data.share_link) window.egw_refresh(_data.msg, this.appname); + + let params = { + 'preset[body]': ''+_data.title+'', + 'mimeType': 'html'// always open compose in html mode, as attachment links look a lot nicer in html + }; + let content = { + mail_htmltext: ['
'+_data.title+''], + mail_plaintext: ["\n"+_data.share_link] + }; + return egw.openWithinWindow("mail", "setCompose", content, params, /mail.mail_compose.compose/); + } + /** * Trigger Upload after each file is uploaded * @param {type} _event diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index 171f1a0836..a7f90583e1 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -983,7 +983,7 @@ class mail_compose if (isset($_REQUEST['preset']['file'])) { $content['filemode'] = !empty($_REQUEST['preset']['filemode']) && - isset(Vfs\Sharing::$modes[$_REQUEST['preset']['filemode']]) ? + (isset(Vfs\Sharing::$modes[$_REQUEST['preset']['filemode']]) || isset(Vfs\HiddenUploadSharing::$modes[$_REQUEST['preset']['filemode']])) ? $_REQUEST['preset']['filemode'] : Vfs\Sharing::ATTACH; $this->addPresetFiles($content, $insertSigOnTop, $alwaysAttachVCardAtCompose);