Disable moveToTrash button for pads in shared folders

pull/1/head
yflory 6 years ago
parent 9c58dc216f
commit fc91cf606b

@ -679,17 +679,27 @@ define([
button
.click(common.prepareFeedback(type))
.click(function() {
var msg = common.isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog;
UI.confirm(msg, function (yes) {
if (!yes) { return; }
sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
if (err) { return void callback(err); }
var cMsg = common.isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
var msg = common.fixLinks($('<div>').html(cMsg));
UI.alert(msg);
callback();
sframeChan.query('Q_IS_ONLY_IN_SHARED_FOLDER', null, function (err, res) {
if (err || res.error) { return void console.log(err || res.error); }
var msg = Messages.forgetPrompt;
if (res) {
UI.alert("WIP: This pad is only in a shared folder. You can't move it to the trash. You can use your CryptDrive if you want to delete it from the folder."); // XXX
return;
} else if (!common.isLoggedIn()) {
msg = Messages.fm_removePermanentlyDialog;
}
UI.confirm(msg, function (yes) {
if (!yes) { return; }
sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
if (err) { return void callback(err); }
var cMsg = common.isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
var msg = common.fixLinks($('<div>').html(cMsg));
UI.alert(msg);
callback();
return;
});
});
});
});
break;

@ -311,6 +311,13 @@ define([
});
};
common.isOnlyInSharedFolder = function (data, cb) {
postMessage("IS_ONLY_IN_SHARED_FOLDER", data, function (obj) {
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
});
};
common.setDisplayName = function (value, cb) {
postMessage("SET_DISPLAY_NAME", value, cb);
};

@ -691,8 +691,18 @@ define([
};
// Pads
Store.isOnlyInSharedFolder = function (clientId, channel, cb) {
var res = store.manager.findChannel(channel);
// A pad is only in a shared worker if:
// 1. this pad is in at least one proxy
// 2. no proxy containing this pad is the main drive
return cb (res.length && !res.some(function (obj) {
// Main drive doesn't have an fId (folder ID)
return !obj.fId;
}));
};
Store.moveToTrash = function (clientId, data, cb) {
// XXX move a pad from a shared folder to the trash?
var href = Hash.getRelativeHref(data.href);
store.userObject.forget(href);
sendDriveEvent('DRIVE_CHANGE', {

@ -41,6 +41,7 @@ define([
MOVE_TO_TRASH: Store.moveToTrash,
RESET_DRIVE: Store.resetDrive,
GET_METADATA: Store.getMetadata,
IS_ONLY_IN_SHARED_FOLDER: Store.isOnlyInSharedFolder,
SET_DISPLAY_NAME: Store.setDisplayName,
SET_PAD_ATTRIBUTE: Store.setPadAttribute,
GET_PAD_ATTRIBUTE: Store.getPadAttribute,

@ -84,6 +84,7 @@ define([
Object.keys(Env.folders).forEach(function (fId) {
Env.folders[fId].userObject.findChannels([channel]).forEach(function (id) {
ret.push({
fId: fId,
data: Env.folders[fId].userObject.getFileData(id),
userObject: Env.folders[fId].userObject
});
@ -95,12 +96,15 @@ define([
var findHref = function (Env, href) {
var ret = [];
var id = Env.user.userObject.getIdFromHref(href);
ret.push({
data: Env.user.userObject.getFileData(id),
userObject: Env.user.userObject
});
if (id) {
ret.push({
data: Env.user.userObject.getFileData(id),
userObject: Env.user.userObject
});
}
Object.keys(Env.folders).forEach(function (fId) {
var id = Env.folders[fId].userObject.getIdFromHref(href);
if (!id) { return; }
ret.push({
fId: fId,
data: Env.folders[fId].userObject.getFileData(id),
@ -717,6 +721,7 @@ define([
addPad: callWithEnv(addPad),
// Tools
findChannel: callWithEnv(findChannel),
findHref: callWithEnv(findHref),
user: Env.user,
folders: Env.folders
};

@ -266,7 +266,7 @@ define([
isDeleted: isNewFile && window.location.hash.length > 0,
forceCreationScreen: forceCreationScreen,
password: password,
channel: secret.channel
channel: secret.channel,
};
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
@ -484,6 +484,12 @@ define([
cb();
});
sframeChan.on('Q_IS_ONLY_IN_SHARED_FOLDER', function (data, cb) {
Cryptpad.isOnlyInSharedFolder(secret.channel, function (err, t) {
if (err) { return void cb({error: err}); }
cb(t);
});
});
// Present mode URL
sframeChan.on('Q_PRESENT_URL_GET_VALUE', function (data, cb) {

@ -111,6 +111,10 @@ define({
'Q_GET_PAD_ATTRIBUTE': true,
'Q_SET_PAD_ATTRIBUTE': true,
// Check if a pad is only in a shared folder or (also) in the main drive.
// This allows us to change the behavior of some buttons (trash icon...)
'Q_IS_ONLY_IN_SHARED_FOLDER': true,
// Open/close the File picker (sent from the iframe to the outside)
'EV_FILE_PICKER_OPEN': true,
'EV_FILE_PICKER_CLOSE': true,

@ -308,7 +308,6 @@ define([
result = id;
return true;
}
return;
});
return result;
};

@ -854,7 +854,6 @@ define([
hide.push('properties');
}
// If we're not in the trash nor in a shared folder, hide "remove"
var el = manager.find(path);
if (!manager.isInSharedFolder(path)
&& !$element.is('.cp-app-drive-element-sharedf')) {
hide.push('removesf');

Loading…
Cancel
Save