Password-protected shared folders

This commit is contained in:
yflory
2018-10-05 18:06:11 +02:00
parent e6379dacd8
commit bf55657993
7 changed files with 44 additions and 29 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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 = {};

View File

@@ -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; }

View File

@@ -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 []; }