diff --git a/calendar/experiments/calendar/ext-calendar-utils.jsm b/calendar/experiments/calendar/ext-calendar-utils.jsm index 139a866..61245f1 100644 --- a/calendar/experiments/calendar/ext-calendar-utils.jsm +++ b/calendar/experiments/calendar/ext-calendar-utils.jsm @@ -79,6 +79,7 @@ function convertCalendar(extension, calendar) { readOnly: calendar.readOnly, enabled: !calendar.getProperty("disabled"), color: calendar.getProperty("color") || "#A8C2E1", + identity: calendar.getProperty("imip.identity.key"), }; if (isOwnCalendar(calendar, extension)) { diff --git a/calendar/experiments/calendar/parent/ext-calendar-calendars.js b/calendar/experiments/calendar/parent/ext-calendar-calendars.js index 79e432e..5bb3817 100644 --- a/calendar/experiments/calendar/parent/ext-calendar-calendars.js +++ b/calendar/experiments/calendar/parent/ext-calendar-calendars.js @@ -80,6 +80,16 @@ this.calendar_calendars = class extends ExtensionAPI { } }, create: async function(createProperties) { + if (createProperties.identity) { + if (!context.extension.hasPermission("accountsRead")) { + throw new ExtensionError('Using identities requires the "accountsRead" permission'); + } + + if (!MailServices.accounts.allIdentities.some(i => i.key == createProperties.identity)) { + throw new ExtensionError(`Identity not found: ${createProperties.identity}`); + } + } + let calendar = calmgr.createCalendar( createProperties.type, Services.io.newURI(createProperties.url) @@ -89,9 +99,12 @@ this.calendar_calendars = class extends ExtensionAPI { } calendar.name = createProperties.name; - if (typeof createProperties.color != "undefined") { + if (createProperties.color != null) { calendar.setProperty("color", createProperties.color); } + if (createProperties.identity != null) { + calendar.setProperty("imip.identity.key", createProperties.identity); + } calmgr.registerCalendar(calendar); @@ -110,6 +123,16 @@ this.calendar_calendars = class extends ExtensionAPI { if (updateProperties.url && !isOwnCalendar(calendar, context.extension)) { throw new ExtensionError("Cannot update url for foreign calendars"); } + if (updateProperties.identity) { + if (!context.extension.hasPermission("accountsRead")) { + throw new ExtensionError('Using identities requires the "accountsRead" permission'); + } + + if (!MailServices.accounts.allIdentities.some(i => i.key == updateProperties.identity)) { + throw new ExtensionError(`Identity not found: ${updateProperties.identity}`); + } + } + if (updateProperties.url) { calendar.uri = Services.io.newURI(updateProperties.url); @@ -125,6 +148,10 @@ this.calendar_calendars = class extends ExtensionAPI { } } + if (updateProperties.identity != null) { + calendar.setProperty("imip.identity.key", updateProperties.identity); + } + // TODO capabilities merging }, remove: async function(id) { @@ -211,6 +238,9 @@ this.calendar_calendars = class extends ExtensionAPI { case "disabled": fire.sync(converted, { enabled: !value }); break; + case "imip.identity.key": + fire.sync(converted, { identity: value }); + break; } }, }); diff --git a/calendar/experiments/calendar/schema/calendar-calendars.json b/calendar/experiments/calendar/schema/calendar-calendars.json index 0967eff..2f68788 100644 --- a/calendar/experiments/calendar/schema/calendar-calendars.json +++ b/calendar/experiments/calendar/schema/calendar-calendars.json @@ -13,6 +13,7 @@ "url": { "type": "string" }, "readOnly": { "type": "boolean" }, "enabled": { "type": "boolean" }, + "identity": { "type": "string", "optional": true }, "color": { "type": "string", "optional": true }, "capabilities": { "$ref": "CalendarCapabilities", "optional": true } } @@ -25,6 +26,7 @@ "url": { "type": "string" }, "readOnly": { "type": "boolean" }, "enabled": { "type": "boolean" }, + "identity": { "type": "string", "optional": true }, "color": { "type": "string", "optional": true } } }, @@ -128,6 +130,7 @@ "url": { "type": "string" }, "readOnly": { "type": "boolean", "optional": true }, "enabled": { "type": "boolean", "optional": true }, + "identity": { "type": "string", "optional": true }, "color": { "type": "string", "optional": true }, "capabilities": { "$ref": "CalendarCapabilities", "optional": true } } @@ -148,6 +151,7 @@ "url": { "type": "string", "optional": true }, "readOnly": { "type": "boolean", "optional": true }, "enabled": { "type": "boolean", "optional": true }, + "identity": { "type": "string", "optional": true }, "color": { "type": "string", "optional": true }, "capabilities": { "$ref": "CalendarCapabilities", "optional": true } }