Encrypt calendars edit URL in teams

pull/1/head
yflory 4 years ago
parent 91f6d329d5
commit 905b339492

@ -859,6 +859,7 @@ Messages.calendar_import = "Import to my calendars";
// No calendar yet, create one // No calendar yet, create one
newCalendar({ newCalendar({
teamId: 1, teamId: 1,
initialCalendar: true,
color: user.color, color: user.color,
title: Messages.calendar_default title: Messages.calendar_default
}, function (err, obj) { }, function (err, obj) {

@ -324,6 +324,24 @@ ctx.calendars[channel] = {
}); });
}); });
}; };
var decryptTeamCalendarHref = function (store, calData) {
if (!calData.href) { return; }
// Already decrypted? nothing to do
if (calData.href.indexOf('#') !== -1) { return; }
// href exists and is encrypted: decrypt if we can or ignore the href
if (store.secondaryKey) {
try {
calData.href = store.userObject.cryptor.decrypt(calData.href);
} catch (e) {
console.error(e);
delete calData.href;
}
} else {
delete calData.href;
}
};
var initializeStore = function (ctx, store) { var initializeStore = function (ctx, store) {
var c = store.proxy.calendars; var c = store.proxy.calendars;
var storeId = store.id || 1; var storeId = store.id || 1;
@ -358,11 +376,13 @@ ctx.calendars[channel] = {
if (!o && n) { if (!o && n) {
(function () { (function () {
var id = p[1]; var id = p[1];
var cal = store.proxy.calendars[id]; var _cal = store.proxy.calendars[id];
if (!cal) { return; } if (!_cal) { return; }
var cal = Util.clone(_cal);
decryptTeamCalendarHref(store, cal);
openChannel(ctx, { openChannel(ctx, {
storeId: storeId, storeId: storeId,
data: Util.clone(cal) data: cal
}); });
})(); })();
} }
@ -378,9 +398,11 @@ ctx.calendars[channel] = {
// If this store contains existing calendars, open them // If this store contains existing calendars, open them
Object.keys(c || {}).forEach(function (channel) { Object.keys(c || {}).forEach(function (channel) {
var cal = Util.clone(c[channel]);
decryptTeamCalendarHref(store, cal);
openChannel(ctx, { openChannel(ctx, {
storeId: storeId, storeId: storeId,
data: c[channel] data: cal
}); });
}); });
}; };
@ -426,9 +448,7 @@ ctx.calendars[channel] = {
}; };
openChannel(ctx, { openChannel(ctx, {
storeId: 0, storeId: 0,
data: cal, data: cal
noStore: true,
isNew: true
}, cb); }, cb);
}; };
var importCalendar = function (ctx, data, cId, cb) { var importCalendar = function (ctx, data, cId, cb) {
@ -477,8 +497,9 @@ ctx.calendars[channel] = {
var hash = Hash.getEditHashFromKeys(secret); var hash = Hash.getEditHashFromKeys(secret);
var roHash = Hash.getViewHashFromKeys(secret); var roHash = Hash.getViewHashFromKeys(secret);
var href = hash && Hash.hashToHref(hash, 'calendar');
var cal = { var cal = {
href: hash && Hash.hashToHref(hash, 'calendar'), href: href,
roHref: roHash && Hash.hashToHref(roHash, 'calendar'), roHref: roHash && Hash.hashToHref(roHash, 'calendar'),
color: data.color, color: data.color,
title: data.title, title: data.title,
@ -492,13 +513,22 @@ ctx.calendars[channel] = {
cal.title = data.title; cal.title = data.title;
openChannel(ctx, { openChannel(ctx, {
storeId: store.id || 1, storeId: store.id || 1,
data: cal data: Util.clone(cal)
}, function (err) { }, function (err) {
if (err) { if (err) {
// Can't open this channel, don't store it // Can't open this channel, don't store it
console.error(err); console.error(err);
return void cb({error: err.error}) return void cb({error: err.error})
} }
if (href && store.id && store.secondaryKey) {
try {
cal.href = store.userObject.cryptor.encrypt(href);
} catch (e) {
console.error(e);
}
}
// Add the calendar and call back // Add the calendar and call back
// If it already existed it means this is an upgrade // If it already existed it means this is an upgrade
c[cal.channel] = cal; c[cal.channel] = cal;
@ -682,6 +712,24 @@ ctx.calendars[channel] = {
if (!store) { return; } if (!store) { return; }
initializeStore(ctx, store); initializeStore(ctx, store);
}; };
calendar.upgradeTeam = function (teamId) {
if (!teamId) { return; }
var store = getStore(ctx, teamId);
if (!store) { return; }
Object.keys(ctx.calendars).forEach(function (id) {
var ctxCal = ctx.calendars[id];
var idx = ctxCal.stores.indexOf(teamId);
if (idx === -1) { return; }
var _cal = store.proxy.calendars[id];
var cal = Util.clone(_cal);
decryptTeamCalendarHref(store, cal);
openChannel(ctx, {
storeId: teamId,
data: cal
});
sendUpdate(ctx, ctxCal);
});
};
calendar.removeClient = function (clientId) { calendar.removeClient = function (clientId) {
removeClient(ctx, clientId); removeClient(ctx, clientId);
@ -707,6 +755,11 @@ ctx.calendars[channel] = {
return void addCalendar(ctx, data, clientId, cb); return void addCalendar(ctx, data, clientId, cb);
} }
if (cmd === 'CREATE') { if (cmd === 'CREATE') {
if (data.initialCalendar) {
return void ctx.Store.onReadyEvt.reg(function () {
createCalendar(ctx, data, clientId, cb);
});
}
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
return void createCalendar(ctx, data, clientId, cb); return void createCalendar(ctx, data, clientId, cb);
} }

@ -1260,6 +1260,13 @@ define([
team.userObject.setReadOnly(!secret.keys.secondaryKey, secret.keys.secondaryKey); team.userObject.setReadOnly(!secret.keys.secondaryKey, secret.keys.secondaryKey);
} }
// Upgrade? update calendar rights
if (secret.keys.secondaryKey) {
try {
ctx.store.modules.calendar.upgradeTeam(teamId);
} catch (e) { console.error(e); }
}
if (!secret.keys.secondaryKey && team.rpc) { if (!secret.keys.secondaryKey && team.rpc) {
team.rpc.destroy(); team.rpc.destroy();
} }

Loading…
Cancel
Save