request capabilities temp

pull/1/head
yflory 6 years ago
parent df5090eaef
commit 6f1e281cf8

@ -693,6 +693,10 @@ define([
pad.onConnectEvent = Util.mkEvent(); pad.onConnectEvent = Util.mkEvent();
pad.onErrorEvent = Util.mkEvent(); pad.onErrorEvent = Util.mkEvent();
pad.requestAccess = function (data, cb) {
postMessage("REQUEST_PAD_ACCESS", data, cb);
};
common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) { common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) {
if (!href) { return void cb({ error: 'EINVAL_HREF' }); } if (!href) { return void cb({ error: 'EINVAL_HREF' }); }
var parsed = Hash.parsePadUrl(href); var parsed = Hash.parsePadUrl(href);

@ -2,9 +2,10 @@ define([
'jquery', 'jquery',
'/common/hyperscript.js', '/common/hyperscript.js',
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-interface.js',
'/common/common-ui-elements.js', '/common/common-ui-elements.js',
'/customize/messages.js', '/customize/messages.js',
], function ($, h, Hash, UIElements, Messages) { ], function ($, h, Hash, UI, UIElements, Messages) {
var handlers = {}; var handlers = {};
@ -84,12 +85,36 @@ define([
key: 'newPadPassword', key: 'newPadPassword',
value: msg.content.password value: msg.content.password
}, todo); }, todo);
common.mailbox.dismiss(data, function (err) {
if (err) { return void console.error(err); }
});
}; };
if (!content.archived) { if (!content.archived) {
content.dismissHandler = defaultDismiss(common, data); content.dismissHandler = defaultDismiss(common, data);
} }
}; };
handlers['REQUEST_PAD_ACCESS'] = function (common, data) {
var content = data.content;
var msg = content.msg;
// Check authenticity
if (msg.author !== msg.content.user.curvePublic) { return; }
// Display the notification
content.getFormatText = function () {
return 'Edit access request: ' + msg.content.channel + ' - ' + msg.content.user.displayName;
};
// if not archived, add handlers
content.handler = function () {
UI.confirm("Give edit rights?", function (yes) {
if (!yes) { return; }
// XXX Command to worker to get the edit href and send it to msg.content.user
});
};
};
return { return {
add: function (common, data) { add: function (common, data) {
var type = data.content.msg.type; var type = data.content.msg.type;

@ -1090,6 +1090,7 @@ define([
var channels = Store.channels = store.channels = {}; var channels = Store.channels = store.channels = {};
Store.joinPad = function (clientId, data) { Store.joinPad = function (clientId, data) {
console.log('joining', data.channel);
var isNew = typeof channels[data.channel] === "undefined"; var isNew = typeof channels[data.channel] === "undefined";
var channel = channels[data.channel] = channels[data.channel] || { var channel = channels[data.channel] = channels[data.channel] || {
queue: [], queue: [],
@ -1243,6 +1244,65 @@ define([
channel.sendMessage(msg, clientId, cb); channel.sendMessage(msg, clientId, cb);
}; };
Store.requestPadAccess = function (clientId, data, cb) {
// Get owners from pad metadata
// Try to find an owner in our friend list
// Mailbox...
var channel = channels[data.channel];
if (!data.send && channel && (!channel.data || !channel.data.channel)) {
var i = 0;
var it = setInterval(function () {
if (channel.data && channel.data.channel) {
clearInterval(it);
Store.requestPadAccess(clientId, data, cb);
return;
}
if (i >= 300) { // One minute timeout
clearInterval(it);
}
i++
}, 200);
return;
};
var fData = channel.data || {};
if (fData.owners) {
var friends = store.proxy.friends || {};
if (Object.keys(friends).length > 1) {
var owner;
fData.owners.some(function (edPublic) {
return Object.keys(friends).some(function (curve) {
if (curve === "me") { return; }
if (edPublic === friends[curve].edPublic &&
friends[curve].notifications) {
owner = friends[curve];
return true;
}
});
});
if (owner) {
console.log(owner);
if (data.send) {
// XXX send the pad title here...? or get it from the recipient's drive
var myData = Messaging.createData(store.proxy);
delete myData.channel;
store.mailbox.sendTo('REQUEST_PAD_ACCESS', {
channel: data.channel,
user: myData
}, {
channel: owner.notifications,
curvePublic: owner.curvePublic
}, function () {
cb({state: true});
});
return;
}
return void cb({state: true});
}
}
}
cb({sent: false});
};
// GET_FULL_HISTORY from sframe-common-outer // GET_FULL_HISTORY from sframe-common-outer
Store.getFullHistory = function (clientId, data, cb) { Store.getFullHistory = function (clientId, data, cb) {
var network = store.network; var network = store.network;

@ -201,6 +201,34 @@ define([
} }
}; };
// Incoming edit rights request: add data before sending it to inner
handlers['REQUEST_PAD_ACCESS'] = function (ctx, box, data, hash) {
var msg = data.msg;
var hash = data.hash;
var content = msg.content;
if (msg.author !== content.user.curvePublic) { return void cb(true); }
var channel = content.channel;
var res = ctx.store.manager.findChannel(channel);
if (!res.length) { return void cb(true); }
var edPublic = store.proxy.edPublic;
var title;
if (!res.some(functon (obj) {
if (obj.data &&
Array.isArray(obj.data.owners) && obj.data.owners.indexOf(edPublic) !== -1 &&
obj.data.href) {
title = obj.data.filename || obj.data.title;
return true;
}
})) { return void cb(true); }
content.title = title;
});
return { return {
add: function (ctx, box, data, cb) { add: function (ctx, box, data, cb) {
/** /**

@ -339,10 +339,10 @@ proxy.mailboxes = {
var txid = parsed[1]; var txid = parsed[1];
var req = ctx.req[txid]; var req = ctx.req[txid];
if (!req) { return; }
var type = parsed[0]; var type = parsed[0];
var _msg = parsed[2]; var _msg = parsed[2];
var box = req.box; var box = req.box;
if (!req) { return; }
if (type === 'HISTORY_RANGE') { if (type === 'HISTORY_RANGE') {
if (!Array.isArray(_msg)) { return; } if (!Array.isArray(_msg)) { return; }

@ -78,6 +78,7 @@ define([
GET_FULL_HISTORY: Store.getFullHistory, GET_FULL_HISTORY: Store.getFullHistory,
GET_HISTORY_RANGE: Store.getHistoryRange, GET_HISTORY_RANGE: Store.getHistoryRange,
IS_NEW_CHANNEL: Store.isNewChannel, IS_NEW_CHANNEL: Store.isNewChannel,
REQUEST_PAD_ACCESS: Store.requestPadAccess,
// Drive // Drive
DRIVE_USEROBJECT: Store.userObjectCommand, DRIVE_USEROBJECT: Store.userObjectCommand,
// Settings, // Settings,

@ -603,6 +603,7 @@ define([
'newpad', 'newpad',
'share', 'share',
'limit', 'limit',
'request',
'unpinnedWarning', 'unpinnedWarning',
'notifications' 'notifications'
], ],

@ -941,6 +941,13 @@ define([
sframeChan.event('EV_WORKER_TIMEOUT'); sframeChan.event('EV_WORKER_TIMEOUT');
}); });
sframeChan.on('Q_REQUEST_ACCESS', function (data, cb) {
Cryptpad.padRpc.requestAccess({
send: data,
channel: secret.channel
}, cb);
});
if (cfg.messaging) { if (cfg.messaging) {
Notifier.getPermission(); Notifier.getPermission();

@ -574,6 +574,43 @@ MessengerUI, Messages) {
return $shareBlock; return $shareBlock;
}; };
var createRequest = function (toolbar, config) {
console.error('test');
if (!config.metadataMgr) {
throw new Error("You must provide a `metadataMgr` to display the request access button");
}
// We can only requets more access if we're in read-only mode
if (config.readOnly !== 1) { return; }
var $requestBlock = $('<button>', {
'class': 'fa fa-lock cp-toolbar-share-button',
title: 'REQUEST ACCESS' // XXX
}).hide();
// If we have access to the owner's mailbox, display the button and enable it
// XXX the data sent to outer is false if we want to check if we can contact the owner
// and it is true if we change to contact it (action)
// XXX get pad title here??
Common.getSframeChannel().query('Q_REQUEST_ACCESS', false, function (err, obj) {
if (obj && obj.state) {
$requestBlock.show().click(function () {
Common.getSframeChannel().query('Q_REQUEST_ACCESS', true, function (err, obj) {
if (obj && obj.state) {
UI.log('sent'); // XXX
}
});
});
}
});
toolbar.$leftside.append($requestBlock);
toolbar.request = $requestBlock;
return $requestBlock;
};
var createTitle = function (toolbar, config) { var createTitle = function (toolbar, config) {
var $titleContainer = $('<span>', { var $titleContainer = $('<span>', {
'class': TITLE_CLS 'class': TITLE_CLS
@ -1178,6 +1215,7 @@ MessengerUI, Messages) {
tb['fileshare'] = createFileShare; tb['fileshare'] = createFileShare;
tb['title'] = createTitle; tb['title'] = createTitle;
tb['pageTitle'] = createPageTitle; tb['pageTitle'] = createPageTitle;
tb['request'] = createRequest;
tb['lag'] = $.noop; tb['lag'] = $.noop;
tb['spinner'] = createSpinner; tb['spinner'] = createSpinner;
tb['state'] = $.noop; tb['state'] = $.noop;

Loading…
Cancel
Save