Disable moveToTrash button for pads in shared folders

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

@ -679,7 +679,15 @@ define([
button button
.click(common.prepareFeedback(type)) .click(common.prepareFeedback(type))
.click(function() { .click(function() {
var msg = common.isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog; 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) { UI.confirm(msg, function (yes) {
if (!yes) { return; } if (!yes) { return; }
sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) { sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
@ -691,6 +699,8 @@ define([
return; return;
}); });
}); });
});
}); });
break; break;
case 'present': case 'present':

@ -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) { common.setDisplayName = function (value, cb) {
postMessage("SET_DISPLAY_NAME", value, cb); postMessage("SET_DISPLAY_NAME", value, cb);
}; };

@ -691,8 +691,18 @@ define([
}; };
// Pads // 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) { Store.moveToTrash = function (clientId, data, cb) {
// XXX move a pad from a shared folder to the trash?
var href = Hash.getRelativeHref(data.href); var href = Hash.getRelativeHref(data.href);
store.userObject.forget(href); store.userObject.forget(href);
sendDriveEvent('DRIVE_CHANGE', { sendDriveEvent('DRIVE_CHANGE', {

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

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

@ -266,7 +266,7 @@ define([
isDeleted: isNewFile && window.location.hash.length > 0, isDeleted: isNewFile && window.location.hash.length > 0,
forceCreationScreen: forceCreationScreen, forceCreationScreen: forceCreationScreen,
password: password, password: password,
channel: secret.channel channel: secret.channel,
}; };
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; } for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
@ -484,6 +484,12 @@ define([
cb(); 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 // Present mode URL
sframeChan.on('Q_PRESENT_URL_GET_VALUE', function (data, cb) { sframeChan.on('Q_PRESENT_URL_GET_VALUE', function (data, cb) {

@ -111,6 +111,10 @@ define({
'Q_GET_PAD_ATTRIBUTE': true, 'Q_GET_PAD_ATTRIBUTE': true,
'Q_SET_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) // Open/close the File picker (sent from the iframe to the outside)
'EV_FILE_PICKER_OPEN': true, 'EV_FILE_PICKER_OPEN': true,
'EV_FILE_PICKER_CLOSE': true, 'EV_FILE_PICKER_CLOSE': true,

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

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

Loading…
Cancel
Save