files-personal-settings.mjs 4.8 KB

12
  1. /*! third party licenses: dist/vendor.LICENSE.txt */
  2. import{af as d,F as f,bR as a,b$ as l,aV as n}from"./core-common.mjs";import{d as h}from"./chunks/index-DCgLaXhm.mjs";import{R as p}from"./chunks/index-D0hy_tCT.mjs";import{l as i}from"./chunks/logger-R_K4lHwR.mjs";import{n as u}from"./chunks/icons-TElqpmA8.mjs";import{z as c,B as m}from"./chunks/_plugin-vue2_normalizer-VrK6B12S-BQkexw0P.mjs";import"./chunks/preload-helper-BG02UnR2.mjs";import"./chunks/index-PaKKd09k.mjs";import"./chunks/index-CiG5J8j_.mjs";const g=p(t("files","Choose a file or folder to transfer")).setMultiSelect(!1).setType(1).allowDirectories().build(),b={name:"TransferOwnershipDialogue",components:{NcSelect:d,NcButton:f},data(){return{directory:void 0,directoryPickerError:void 0,submitError:void 0,loadingUsers:!1,selectedUser:null,userSuggestions:{},config:{minSearchStringLength:parseInt(OC.config["sharing.minSearchStringLength"],10)||0}}},computed:{canSubmit(){return!!this.directory&&!!this.selectedUser},formatedUserSuggestions(){return Object.keys(this.userSuggestions).map(e=>{const r=this.userSuggestions[e];return{user:r.uid,displayName:r.displayName,icon:"icon-user"}})},submitButtonText(){if(!this.canSubmit)return t("files","Transfer");const e=this.readableDirectory.split("/");return t("files","Transfer {path} to {userid}",{path:e[e.length-1],userid:this.selectedUser.displayName})},readableDirectory(){return this.directory?this.directory.substring(1):""}},created(){this.findUserDebounced=h(this.findUser,300),this.findUser("")},methods:{start(){this.directoryPickerError=void 0,g.pick().then(e=>e===""?"/":e).then(e=>{if(i.debug("path ".concat(e," selected for transferring ownership")),!e.startsWith("/"))throw new Error(t("files","Invalid path selected"));this.directory=e}).catch(e=>{i.error("Selecting object for transfer aborted: ".concat(e.message||"Unknown error"),{error:e}),this.directoryPickerError=e.message||t("files","Unknown error"),c(this.directoryPickerError)})},async findUser(e){if(this.query=e.trim(),!(e.length<this.config.minSearchStringLength)){this.loadingUsers=!0;try{const r=await a.get(l("apps/files_sharing/api/v1/sharees"),{params:{format:"json",itemType:"file",search:e,perPage:20,lookup:!1}});this.userSuggestions={},r.data.ocs.data.exact.users.concat(r.data.ocs.data.users).forEach(s=>{n.set(this.userSuggestions,s.value.shareWith,{uid:s.value.shareWith,displayName:s.label})})}catch(r){i.error("could not fetch users",{error:r})}finally{this.loadingUsers=!1}}},submit(){this.canSubmit||i.warn("ignoring form submit"),this.submitError=void 0;const e={path:this.directory,recipient:this.selectedUser.user};i.debug("submit transfer ownership form",e);const r=l("apps/files/api/v1/transferownership");a.post(r,e).then(s=>s.data).then(s=>{i.info("Transfer ownership request sent",{data:s}),this.directory=void 0,this.selectedUser=null,m(t("files","Ownership transfer request sent"))}).catch(s=>{var o;i.error("Could not send ownership transfer request",{error:s}),((o=s==null?void 0:s.response)==null?void 0:o.status)===403?this.submitError=t("files","Cannot transfer ownership of a file or folder you do not own"):this.submitError=s.message||t("files","Unknown error"),c(this.submitError)})}}};var y=function(){var e=this,r=e._self._c;return r("div",[r("h3",[e._v(e._s(e.t("files","Transfer ownership of a file or folder"))+" ")]),r("form",{on:{submit:function(s){return s.preventDefault(),e.submit.apply(null,arguments)}}},[r("p",{staticClass:"transfer-select-row"},[r("span",[e._v(e._s(e.readableDirectory))]),e.directory===void 0?r("NcButton",{staticClass:"transfer-select-row__choose_button",on:{click:function(s){return s.preventDefault(),e.start.apply(null,arguments)}}},[e._v(" "+e._s(e.t("files","Choose file or folder to transfer"))+" ")]):r("NcButton",{on:{click:function(s){return s.preventDefault(),e.start.apply(null,arguments)}}},[e._v(" "+e._s(e.t("files","Change"))+" ")])],1),r("p",{staticClass:"new-owner-row"},[r("label",{attrs:{for:"targetUser"}},[r("span",[e._v(e._s(e.t("files","New owner")))])]),r("NcSelect",{staticClass:"middle-align",attrs:{"input-id":"targetUser",options:e.formatedUserSuggestions,multiple:!1,loading:e.loadingUsers,label:"displayName","user-select":!0},on:{search:e.findUserDebounced},model:{value:e.selectedUser,callback:function(s){e.selectedUser=s},expression:"selectedUser"}})],1),r("p",[r("NcButton",{attrs:{"native-type":"submit",type:"primary",disabled:!e.canSubmit}},[e._v(" "+e._s(e.submitButtonText)+" ")])],1)])])},v=[],w=u(b,y,v,!1,null,"07bcf6b6");const U=w.exports,S={name:"PersonalSettings",components:{TransferOwnershipDialogue:U}};var _=function(){var e=this,r=e._self._c;return r("div",{staticClass:"section",attrs:{id:"files-personal-settings"}},[r("h2",[e._v(e._s(e.t("files","Files")))]),r("TransferOwnershipDialogue")],1)},k=[],N=u(S,_,k,!1,null,null);const T=N.exports;if(n.prototype.t=t,!window.TESTING){const e=n.extend(T);new e().$mount("#files-personal-settings")}