Password-protected shared folders
parent
e6379dacd8
commit
bf55657993
|
@ -156,7 +156,7 @@ define([
|
|||
}
|
||||
|
||||
var parsed = Hash.parsePadUrl(data.href || data.roHref);
|
||||
if (owned && parsed.hashData.type === 'pad') {
|
||||
if (!data.noEditPassword && owned && parsed.hashData.type === 'pad') {
|
||||
var sframeChan = common.getSframeChannel();
|
||||
var changePwTitle = Messages.properties_changePassword;
|
||||
var changePwConfirm = Messages.properties_confirmChange;
|
||||
|
|
|
@ -128,6 +128,7 @@ define([
|
|||
href: '/drive/#' + Hash.getEditHashFromKeys(secret),
|
||||
roHref: '/drive/#' + Hash.getViewHashFromKeys(secret),
|
||||
channel: secret.channel,
|
||||
password: secret.password,
|
||||
ctime: +new Date()
|
||||
}
|
||||
}, cb);
|
||||
|
|
|
@ -386,14 +386,14 @@ define([
|
|||
if (data.folderData) { return; }
|
||||
|
||||
// Folder creation
|
||||
var hash = Hash.createRandomHash('drive');
|
||||
var href = '/drive/#' + hash;
|
||||
var secret = Hash.getSecrets('drive', hash);
|
||||
var hash = Hash.createRandomHash('drive', data.password);
|
||||
var secret = Hash.getSecrets('drive', hash, data.password);
|
||||
var hashes = Hash.getHashes(secret);
|
||||
folderData = {
|
||||
href: href,
|
||||
roHref: '/drive/#' + Hash.getViewHashFromKeys(secret),
|
||||
href: '/drive/#' + hashes.editHash,
|
||||
roHref: '/drive/#' + hashes.viewHash,
|
||||
channel: secret.channel,
|
||||
ctime: +new Date()
|
||||
ctime: +new Date(),
|
||||
};
|
||||
if (data.password) { folderData.password = data.password; }
|
||||
if (data.owned) { folderData.owners = [Env.edPublic]; }
|
||||
|
@ -541,6 +541,11 @@ define([
|
|||
// Set the value everywhere the given pad is stored (main and shared folders)
|
||||
var setPadAttribute = function (Env, data, cb) {
|
||||
cb = cb || function () {};
|
||||
if (!data.attr || !data.attr.trim()) { return void cb("E_INVAL_ATTR"); }
|
||||
var sfId = Env.user.userObject.getSFIdFromHref(data.href);
|
||||
if (sfId) {
|
||||
Env.user.proxy[UserObject.SHARED_FOLDERS][sfId][data.attr] = data.value;
|
||||
}
|
||||
var datas = findHref(Env, data.href);
|
||||
var nt = nThen;
|
||||
datas.forEach(function (d) {
|
||||
|
@ -557,6 +562,10 @@ define([
|
|||
// correct one.
|
||||
var getPadAttribute = function (Env, data, cb) {
|
||||
cb = cb || function () {};
|
||||
var sfId = Env.user.userObject.getSFIdFromHref(data.href);
|
||||
if (sfId) {
|
||||
return void cb(null, Env.user.proxy[UserObject.SHARED_FOLDERS][sfId][data.attr]);
|
||||
}
|
||||
var datas = findHref(Env, data.href);
|
||||
var nt = nThen;
|
||||
var res = {};
|
||||
|
|
|
@ -204,6 +204,10 @@ define([
|
|||
// If no password, continue...
|
||||
todo();
|
||||
}
|
||||
}).nThen(function (waitFor) {
|
||||
if (cfg.afterSecrets) {
|
||||
cfg.afterSecrets(Cryptpad, Utils, secret, waitFor());
|
||||
}
|
||||
}).nThen(function (waitFor) {
|
||||
// Check if the pad exists on server
|
||||
if (!window.location.hash) { isNewFile = true; return; }
|
||||
|
|
|
@ -320,6 +320,18 @@ define([
|
|||
return result;
|
||||
};
|
||||
|
||||
exp.getSFIdFromHref = function (href) {
|
||||
var result;
|
||||
getFiles([SHARED_FOLDERS]).some(function (id) {
|
||||
if (files[SHARED_FOLDERS][id].href === href ||
|
||||
files[SHARED_FOLDERS][id].roHref === href) {
|
||||
result = id;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// SEARCH
|
||||
var _findFileInRoot = function (path, file) {
|
||||
if (!isPathIn(path, [ROOT, TRASH])) { return []; }
|
||||
|
|
|
@ -1763,8 +1763,8 @@ define([
|
|||
h('h4', Messages.sharedFolders_create),
|
||||
h('label', {for: 'cp-app-drive-sf-name'}, Messages.sharedFolders_create_name),
|
||||
h('input#cp-app-drive-sf-name', {type: 'text', placeholder: Messages.fm_newFolder}),
|
||||
//h('label', {for: 'cp-app-drive-sf-password'}, Messages.sharedFolders_create_password),
|
||||
//UI.passwordInput({id: 'cp-app-drive-sf-password'}),
|
||||
h('label', {for: 'cp-app-drive-sf-password'}, Messages.sharedFolders_create_password),
|
||||
UI.passwordInput({id: 'cp-app-drive-sf-password'}),
|
||||
h('span', {
|
||||
style: 'display:flex;align-items:center;justify-content:space-between'
|
||||
}, [
|
||||
|
@ -1784,8 +1784,7 @@ define([
|
|||
|
||||
// Get the values
|
||||
var newName = $(content).find('#cp-app-drive-sf-name').val();
|
||||
//var password = $(content).find('#cp-app-drive-sf-password').val() || undefined;
|
||||
var password;
|
||||
var password = $(content).find('#cp-app-drive-sf-password').val() || undefined;
|
||||
var owned = $(content).find('#cp-app-drive-sf-owned').is(':checked');
|
||||
|
||||
cb({
|
||||
|
@ -3067,7 +3066,8 @@ define([
|
|||
|
||||
if (manager.isSharedFolder(el)) {
|
||||
delete data.roHref;
|
||||
data.noPassword = true;
|
||||
//data.noPassword = true;
|
||||
data.noEditPassword = true;
|
||||
data.noExpiration = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,21 +36,13 @@ define([
|
|||
};
|
||||
window.addEventListener('message', onMsg);
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
var getSecrets = function (Cryptpad, Utils, cb) {
|
||||
var afterSecrets = function (Cryptpad, Utils, secret, cb) {
|
||||
var hash = window.location.hash.slice(1);
|
||||
var secret = Utils.Hash.getSecrets('drive', hash);
|
||||
if (hash && Utils.LocalStore.isLoggedIn()) {
|
||||
// Add a shared folder!
|
||||
// TODO password?
|
||||
Cryptpad.addSharedFolder(secret, function (id) {
|
||||
window.CryptPad_newSharedFolder = id;
|
||||
// Update the hash in the address bar
|
||||
var ohc = window.onhashchange;
|
||||
window.onhashchange = function () {};
|
||||
window.location.hash = "";
|
||||
window.onhashchange = ohc;
|
||||
ohc({reset:true});
|
||||
cb(null, secret);
|
||||
cb();
|
||||
});
|
||||
return;
|
||||
} else if (hash) {
|
||||
|
@ -58,14 +50,11 @@ define([
|
|||
window.CryptPad_newSharedFolder = id;
|
||||
var data = {
|
||||
href: Utils.Hash.getRelativeHref(window.location.href),
|
||||
password: secret.password
|
||||
};
|
||||
Cryptpad.loadSharedFolder(id, data, function () {
|
||||
cb(null, secret);
|
||||
});
|
||||
return;
|
||||
return void Cryptpad.loadSharedFolder(id, data, cb);
|
||||
}
|
||||
// No password for drive
|
||||
cb(null, secret);
|
||||
cb();
|
||||
};
|
||||
var addRpc = function (sframeChan, Cryptpad, Utils) {
|
||||
sframeChan.on('EV_BURN_ANON_DRIVE', function () {
|
||||
|
@ -123,7 +112,7 @@ define([
|
|||
});
|
||||
};
|
||||
SFCommonO.start({
|
||||
getSecrets: getSecrets,
|
||||
afterSecrets: afterSecrets,
|
||||
noHash: true,
|
||||
noRealtime: true,
|
||||
driveEvents: true,
|
||||
|
|
Loading…
Reference in New Issue