This commit is contained in:
Zuzanna 2025-11-18 11:51:50 +01:00
parent cccda1bcdb
commit db9130ba84
4 changed files with 73 additions and 8 deletions

View File

@ -161,7 +161,8 @@ const factory = (UserObject, Util, Hash,
var userObjects = _getUserObjects(Env);
var userObject = Env.user.userObject;
userObjects.some(function (uo) {
if (Object.keys(uo.getFileData(id)).length) {
console.log("hello2")
if (Object.keys(uo.getFileData(id, true)).length) {
userObject = uo;
return true;
}
@ -187,6 +188,8 @@ const factory = (UserObject, Util, Hash,
var data = Env.user.proxy[UserObject.SHARED_FOLDERS][id];
if (data && !editable) { data = JSON.parse(JSON.stringify(data)); }
// If it's not a shared folder, check the pads
console.log("hello3")
if (!data) { data = Env.user.userObject.getFileData(id, editable); }
ret.push({
id: id,
@ -196,6 +199,8 @@ const factory = (UserObject, Util, Hash,
});
Object.keys(Env.folders).forEach(function (fId) {
Env.folders[fId].userObject.findChannels([channel]).forEach(function (id) {
console.log("hello4")
ret.push({
id: id,
fId: fId,
@ -212,6 +217,8 @@ const factory = (UserObject, Util, Hash,
var findHref = function (Env, href) {
var ret = [];
var id = Env.user.userObject.getIdFromHref(href);
console.log("hello5")
if (id) {
ret.push({
data: Env.user.userObject.getFileData(id),
@ -221,6 +228,8 @@ const factory = (UserObject, Util, Hash,
Object.keys(Env.folders).forEach(function (fId) {
var id = Env.folders[fId].userObject.getIdFromHref(href);
if (!id) { return; }
console.log("hello6")
ret.push({
fId: fId,
data: Env.folders[fId].userObject.getFileData(id),
@ -313,10 +322,16 @@ const factory = (UserObject, Util, Hash,
};
var _getFileData = function (Env, id, editable) {
// console.log("beep?", Env.edPublic)
var userObjects = _getUserObjects(Env);
var data = {};
// console.log("beep!", _getUserObjects(Env))
userObjects.some(function (uo) {
data = uo.getFileData(id, editable);
data = uo.getFileData(id, editable, Env.edPublic);
// console.log("beep???", data)
if (data && Object.keys(data).length) { return true; }
});
return data;
@ -408,7 +423,10 @@ const factory = (UserObject, Util, Hash,
// Get the owned files in the main drive that are also duplicated in shared folders
var _isDuplicateOwned = function (Env, path, id) {
if (path && _isInSharedFolder(Env, path)) { return; }
// if (path && _isInSharedFolder(Env, path)) { console.log ("beep!!")
// return true; }
console.log("hello7")
var data = _getFileData(Env, id || Env.user.userObject.find(path));
if (!data) { return; }
if (!_ownedByMe(Env, data.owners)) { return; }
@ -1152,6 +1170,7 @@ const factory = (UserObject, Util, Hash,
var _updateStaticAccess = function (Env, id, cb) {
var uo = _getUserObjectFromId(Env, id);
var sd = uo.getFileData(id, true);
// console.log()
sd.atime = +new Date();
Env.onSync(cb);
};

View File

@ -123,6 +123,7 @@ const factory = (Util, Hash,
exp.cryptor = createCryptor(config.editKey);
exp.setReadOnly = function (state, key) {
console.log("here!", state, key)
config.editKey = key;
exp.cryptor = createCryptor(key);
exp.cryptor.k = Math.random();
@ -318,11 +319,13 @@ const factory = (Util, Hash,
};
// Get data from AllFiles (Cryptpad_RECENTPADS)
var getFileData = exp.getFileData = function (file, editable) {
var getFileData = exp.getFileData = function (file, editable, edPub) {
if (!file) { return; }
var link;
// editable = true
try {
link = (files[STATIC_DATA] || {})[file];
// console.log("hello# 1", link)
} catch (err) {
console.error(err);
}
@ -334,12 +337,29 @@ const factory = (Util, Hash,
var data;
try {
data = files[FILES_DATA][file] || {};
// console.log("hello# 2")
} catch (err) {
console.error(err);
data = {};
}
// console.log("hello#", files[FILES_DATA], file)
// for
if (data.owners) {
// console.log("blorp!", data.owners, edPub)
var owner = data?.owners.includes(edPub)
editable = owner ? true : editable
// console.log("boink?", owner, editable)
}
if (!editable) {
// console.log("boink@", owner, editable)
data = JSON.parse(JSON.stringify(data));
// console.log("hello", data)
// console.log("hello", files)
if (data.href && data.href.indexOf('#') === -1) {
// Encrypted href: decrypt it if we can, otherwise remove it
if (config.editKey) {
@ -348,7 +368,11 @@ const factory = (Util, Hash,
} catch (e) {
delete data.href;
}
} else {
}
// else if () {
// }
else if (!data.owners && !data?.owners.includes(edPub)) {
delete data.href;
}
}
@ -461,6 +485,7 @@ const factory = (Util, Hash,
var _getFiles = {};
_getFiles['array'] = function (cat) {
if (!files[cat]) { files[cat] = []; }
console.log()
return files[cat].slice();
};
getHrefArray().forEach(function (c) {

View File

@ -101,6 +101,8 @@ const factory = (Hash, Util, UserObject, Cache,
// If we try to load an existing shared folder (isNew === false) but this folder
// doesn't exist in the database, abort and cb
nThen(function (waitFor) {
console.log("here5")
// If we're in onCacheReady, make sure we have a cache for this shared folder
if (config.cache) {
Cache.getChannelCache(secret.channel, waitFor(function (err) {
@ -112,6 +114,8 @@ const factory = (Hash, Util, UserObject, Cache,
}));
}
}).nThen(function (waitFor) {
console.log("here4")
isNewChannel(null, { channel: secret.channel }, waitFor(function (obj) {
if (obj.isNew && !isNew) {
store.manager.deprecateProxy(id, secret.channel, obj.reason);
@ -120,6 +124,8 @@ const factory = (Hash, Util, UserObject, Cache,
}
}));
}).nThen(function () {
console.log("here3")
var sf = allSharedFolders[secret.channel];
if (sf && sf.readOnly && secondaryKey) {
// We were in readOnly mode and now we know the edit keys!
@ -269,6 +275,8 @@ const factory = (Hash, Util, UserObject, Cache,
SF.upgrade = function (channel, secret) {
console.log("here2")
var sf = allSharedFolders[channel];
if (!sf || !sf.readOnly) { return; }
if (!sf.rt.setReadOnly) { return; }
@ -276,10 +284,13 @@ const factory = (Hash, Util, UserObject, Cache,
if (!secret.keys || !secret.keys.editKeyStr) { return; }
var crypto = Crypto.createEncryptor(secret.keys);
sf.readOnly = false;
sf.rt.setReadOnly(false, crypto);
};
SF.leave = function (channel, teamId) {
console.log("here1")
var sf = allSharedFolders[channel];
if (!sf) { return; }
var clients = sf.teams;

View File

@ -1254,8 +1254,7 @@ define([
var defaultInApp = ['application/pdf'];
var openFile = function (el, isRo, app) {
// In anonymous drives, `el` already contains file data
var data = el.channel ? el : manager.getFileData(el);
var data = manager.getFileData(el, isRo, edPublic);
if (data.static) {
if (data.href) {
common.openUnsafeURL(data.href);
@ -1269,6 +1268,7 @@ define([
}
var href = isRo ? data.roHref : (data.href || data.roHref);
console.log("hrefhere", href, isRo, data)
var parsed = Hash.parsePadUrl(href);
if (parsed.hashData && parsed.hashData.type === 'file' && !app
@ -2265,10 +2265,13 @@ define([
var href = data.href || data.roHref;
if (!data) { return void logError("No data for the file", element); }
console.log("THIS here", data, edPublic)
if (!data.href && manager.isInSharedFolder($element.data('path'))) {
Object.keys(files.filesData).forEach(function (file) {
if (files.filesData[file].channel === data.channel && files.filesData[file].href && files.filesData[file].href.includes('edit')) {
console.log("beepfile", files.filesData[file].channel, files.filesData[file])
if (files.filesData[file].channel === data.channel && files.filesData[file].href && files.filesData[file].href.includes('edit') && data.owners.includes(edPublic)) {
href = files.filesData[file].href;
data.href = href;
}
@ -2281,6 +2284,13 @@ define([
$element.addClass('cp-border-color-'+hrefData.type);
}
console.log("href!", href, Hash.parsePadUrl(href))
var hrefData = Hash.parsePadUrl(href);
if (hrefData.type) {
$element.addClass('cp-border-color-'+hrefData.type);
}
var $state = $('<span>', {'class': 'cp-app-drive-element-state'});
if (hrefData.hashData && hrefData.hashData.mode === 'view') {
var $ro = $readonlyIcon.clone().appendTo($state);