URL calendars for anonymous users

pull/1/head
yflory 4 years ago
parent 8701443f0f
commit f2b63639c6

@ -375,7 +375,7 @@ define([
} }
}); });
} }
if (data.teams.indexOf(1) === -1 || teamId === 0) { if (APP.loggedIn && (data.teams.indexOf(1) === -1 || teamId === 0)) {
options.push({ options.push({
tag: 'a', tag: 'a',
attributes: { attributes: {
@ -387,10 +387,10 @@ define([
importCalendar({ importCalendar({
id: id, id: id,
teamId: teamId teamId: teamId
}, function (obj) { }, function (err) {
if (obj && obj.error) { if (err) {
console.error(obj.error); console.error(err);
return void UI.warn(obj.error); return void UI.warn(Messages.error);
} }
}); });
return true; return true;
@ -677,14 +677,16 @@ define([
importCalendar({ importCalendar({
id: tempCalendars[0], id: tempCalendars[0],
teamId: 0 teamId: 0
}, function (obj) { }, function (err) {
if (obj && obj.error) { if (err) {
console.error(obj.error); console.error(err);
return void UI.warn(obj.error); return void UI.warn(Messages.error);
} }
}); });
}); });
if (APP.loggedIn) {
APP.$calendars.append(h('div.cp-calendar-entry.cp-ghost', importTemp)); APP.$calendars.append(h('div.cp-calendar-entry.cp-ghost', importTemp));
}
return; return;
} }
var myCalendars = filter(1); var myCalendars = filter(1);
@ -1111,6 +1113,8 @@ define([
var privateData = metadataMgr.getPrivateData(); var privateData = metadataMgr.getPrivateData();
var user = metadataMgr.getUserData(); var user = metadataMgr.getUserData();
APP.loggedIn = common.isLoggedIn();
common.setTabTitle(Messages.calendar); common.setTabTitle(Messages.calendar);
// Fix flatpickr selection // Fix flatpickr selection
@ -1248,6 +1252,11 @@ define([
var store = window.cryptpadStore; var store = window.cryptpadStore;
APP.module.execCommand('SUBSCRIBE', null, function (obj) { APP.module.execCommand('SUBSCRIBE', null, function (obj) {
if (obj.empty && !privateData.calendarHash) { if (obj.empty && !privateData.calendarHash) {
if (!privateData.loggedIn) {
return void UI.errorLoadingScreen(Messages.mustLogin, false, function () {
common.setLoginRedirect('login');
});
}
// No calendar yet, create one // No calendar yet, create one
newCalendar({ newCalendar({
teamId: 1, teamId: 1,

@ -20,7 +20,7 @@ define(function() {
* users and these users will be redirected to the login page if they still try to access * users and these users will be redirected to the login page if they still try to access
* the app * the app
*/ */
config.registeredOnlyTypes = ['file', 'contacts', 'notifications', 'support', 'calendar']; config.registeredOnlyTypes = ['file', 'contacts', 'notifications', 'support'];
/* CryptPad is available is multiple languages, but only English and French are maintained /* CryptPad is available is multiple languages, but only English and French are maintained
* by the developers. The other languages may be outdated, and any missing string for a langauge * by the developers. The other languages may be outdated, and any missing string for a langauge

@ -114,8 +114,8 @@ define([
} }
} }
// XXX add a limit to make sure we don't go too far in the past? ==> 1 week var oneWeekAgo = now - (7 * 24 * 3600 * 1000);
var missed = useLastVisit && ev.start > last && ev.end <= now; var missed = useLastVisit && ev.start > last && ev.end <= now && ev.end > oneWeekAgo;
if (ev.end <= now && !missed) { if (ev.end <= now && !missed) {
// No reminder for past events // No reminder for past events
delete reminders[uid]; delete reminders[uid];
@ -543,6 +543,8 @@ define([
var hash = Hash.getEditHashFromKeys(secret); var hash = Hash.getEditHashFromKeys(secret);
var roHash = Hash.getViewHashFromKeys(secret); var roHash = Hash.getViewHashFromKeys(secret);
if (!ctx.loggedIn) { hash = undefined; }
var cal = { var cal = {
href: hash && Hash.hashToHref(hash, 'calendar'), href: hash && Hash.hashToHref(hash, 'calendar'),
roHref: roHash && Hash.hashToHref(roHash, 'calendar'), roHref: roHash && Hash.hashToHref(roHash, 'calendar'),
@ -846,8 +848,9 @@ define([
Calendar.init = function (cfg, waitFor, emit) { Calendar.init = function (cfg, waitFor, emit) {
var calendar = {}; var calendar = {};
var store = cfg.store; var store = cfg.store;
if (!store.loggedIn || !store.proxy.edPublic) { return; } // XXX logged in only? we should al least allow read-only for URL calendars //if (!store.loggedIn || !store.proxy.edPublic) { return; } // XXX logged in only? we should al least allow read-only for URL calendars
var ctx = { var ctx = {
loggedIn: store.loggedIn && store.proxy.edPublic,
store: store, store: store,
Store: cfg.Store, Store: cfg.Store,
pinPads: cfg.pinPads, pinPads: cfg.pinPads,
@ -918,17 +921,21 @@ define([
} }
if (cmd === 'IMPORT') { if (cmd === 'IMPORT') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void importCalendar(ctx, data, clientId, cb); return void importCalendar(ctx, data, clientId, cb);
} }
if (cmd === 'IMPORT_ICS') { if (cmd === 'IMPORT_ICS') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void importICSCalendar(ctx, data, clientId, cb); return void importICSCalendar(ctx, data, clientId, cb);
} }
if (cmd === 'ADD') { if (cmd === 'ADD') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void addCalendar(ctx, data, clientId, cb); return void addCalendar(ctx, data, clientId, cb);
} }
if (cmd === 'CREATE') { if (cmd === 'CREATE') {
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
if (data.initialCalendar) { if (data.initialCalendar) {
return void ctx.Store.onReadyEvt.reg(function () { return void ctx.Store.onReadyEvt.reg(function () {
createCalendar(ctx, data, clientId, cb); createCalendar(ctx, data, clientId, cb);
@ -939,22 +946,27 @@ define([
} }
if (cmd === 'UPDATE') { if (cmd === 'UPDATE') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void updateCalendar(ctx, data, clientId, cb); return void updateCalendar(ctx, data, clientId, cb);
} }
if (cmd === 'DELETE') { if (cmd === 'DELETE') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void deleteCalendar(ctx, data, clientId, cb); return void deleteCalendar(ctx, data, clientId, cb);
} }
if (cmd === 'CREATE_EVENT') { if (cmd === 'CREATE_EVENT') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void createEvent(ctx, data, clientId, cb); return void createEvent(ctx, data, clientId, cb);
} }
if (cmd === 'UPDATE_EVENT') { if (cmd === 'UPDATE_EVENT') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void updateEvent(ctx, data, clientId, cb); return void updateEvent(ctx, data, clientId, cb);
} }
if (cmd === 'DELETE_EVENT') { if (cmd === 'DELETE_EVENT') {
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); } if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
if (!ctx.loggedIn) { return void cb({error: 'NOT_LOGGED_IN'}); }
return void deleteEvent(ctx, data, clientId, cb); return void deleteEvent(ctx, data, clientId, cb);
} }
}; };

Loading…
Cancel
Save