Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions calendar/experiments/calendar/ext-calendar-utils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
32 changes: 31 additions & 1 deletion calendar/experiments/calendar/parent/ext-calendar-calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -25,6 +26,7 @@
"url": { "type": "string" },
"readOnly": { "type": "boolean" },
"enabled": { "type": "boolean" },
"identity": { "type": "string", "optional": true },
"color": { "type": "string", "optional": true }
}
},
Expand Down Expand Up @@ -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 }
}
Expand All @@ -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 }
}
Expand Down