Merge pull request #1388 from cryptpad/access_shared_folder

Shared folder access list
This commit is contained in:
yflory 2024-01-29 17:30:30 +01:00 committed by GitHub
commit 788b007c61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 1 deletions

View File

@ -646,7 +646,6 @@ define([
return $div;
};
$(addBtn).click(function () {
var priv = metadataMgr.getPrivateData();
var user = metadataMgr.getUserData();
@ -657,12 +656,14 @@ define([
var $sel = $div.find('.cp-usergrid-user.cp-selected');
var sel = $sel.toArray();
if (!sel.length) { return; }
var dataToAdd = [];
var toAdd = sel.map(function (el) {
var curve = $(el).attr('data-curve');
var teamId = $(el).attr('data-teamid');
// If the pad is woned by a team, we can transfer ownership to ourselves
if (curve === user.curvePublic && teamOwner) { return priv.edPublic; }
var data = friends[curve] || teamsData[teamId];
dataToAdd.push(data);
if (!data) { return; }
return data.edPublic;
}).filter(function (x) { return x; });
@ -690,6 +691,19 @@ define([
}, waitFor(function (err, res) {
err = err || (res && res.error);
redrawAll(true);
dataToAdd.forEach(function(mailbox) {
if (mailbox.notifications && mailbox.curvePublic) {
common.mailbox.sendTo("ADD_TO_ACCESS_LIST", {
channel: channel,
}, {
channel: mailbox.notifications,
curvePublic: mailbox.curvePublic
});
} else {
return;
}
})
if (err) {
waitFor.abort();
var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden

View File

@ -2400,6 +2400,8 @@ define([
Store.loadSharedFolder = function (teamId, id, data, cb, isNew) {
var s = getStore(teamId);
if (!s) { return void cb({ error: 'ENOTFOUND' }); }
var parsed = Hash.parsePadUrl(data.href || data.roHref);
if (!parsed && !parsed.hashData) { return void cb({error: 'EINVAL'}); }
SF.load({
isNew: isNew,
network: store.network || store.networkPromise,

View File

@ -347,6 +347,26 @@ define([
cb(false);
};
handlers['ADD_TO_ACCESS_LIST'] = function(ctx, common, data, cb) {
var msg = data.msg;
var content = msg.content;
var channel = content.channel;
ctx.Store.getAllStores().forEach(function (store) {
var res = store.manager.findChannel(channel);
if (!res.length) { return; }
var data = res[0].data;
var id = res[0].id;
var teamId = store.id;
ctx.Store.loadSharedFolder(teamId, id, data, function () {
}, false);
});
cb(true);
};
// Hide duplicates when receiving an ADD_OWNER notification:
var addOwners = {};
handlers['ADD_OWNER'] = function (ctx, box, data, cb) {