# HG changeset patch # User Philipp Kewisch # Date 1508015695 -7200 # Sa Okt 14 23:14:55 2017 +0200 # Node ID d57095f7ae224940b661be89bfbbd94f485b364e # Parent 1619f90fb8f69d5171e0a73fba71d0e771da3a73 Bug 1432142 - Move acl related functions into calACLUtils.jsm - automatic changes. r=MakeMyDay MozReview-Commit-ID: GfoM7HtJvQc diff --git a/calendar/base/content/calendar-clipboard.js b/calendar/base/content/calendar-clipboard.js --- a/calendar/base/content/calendar-clipboard.js +++ b/calendar/base/content/calendar-clipboard.js @@ -13,23 +13,23 @@ Components.utils.import("resource://cale * can be pasted into Calendar. The data must be of type "text/calendar" or * "text/unicode". * * @return If true, pasting is currently possible. */ function canPaste() { if (Preferences.get("calendar.paste.intoSelectedCalendar", false)) { let selectedCal = getSelectedCalendar(); - if (!selectedCal || !cal.isCalendarWritable(selectedCal)) { + if (!selectedCal || !cal.acl.isCalendarWritable(selectedCal)) { return false; } } else { let calendars = cal.getCalendarManager().getCalendars({}) - .filter(cal.isCalendarWritable) - .filter(cal.userCanAddItemsToCalendar); + .filter(cal.acl.isCalendarWritable) + .filter(cal.acl.userCanAddItemsToCalendar); if (!calendars.length) { return false; } } const flavors = ["text/calendar", "text/unicode"]; return Services.clipboard.hasDataMatchingFlavors(flavors, flavors.length, @@ -137,18 +137,18 @@ function pasteFromClipboard() { switch (flavor.value) { case "text/calendar": case "text/unicode": { let destCal = null; if (Preferences.get("calendar.paste.intoSelectedCalendar", false)) { destCal = getSelectedCalendar(); } else { let calendars = cal.getCalendarManager().getCalendars({}) - .filter(cal.isCalendarWritable) - .filter(cal.userCanAddItemsToCalendar); + .filter(cal.acl.isCalendarWritable) + .filter(cal.acl.userCanAddItemsToCalendar); if (calendars.length > 1) { let args = {}; args.calendars = calendars; args.onOk = (aCal) => { destCal = aCal; }; args.promptText = cal.calGetString("calendar", "pastePrompt"); window.openDialog("chrome://calendar/content/chooseCalendarDialog.xul", "_blank", "chrome,titlebar,modal,resizable", args); } else if (calendars.length == 1) { diff --git a/calendar/base/content/calendar-common-sets.js b/calendar/base/content/calendar-common-sets.js --- a/calendar/base/content/calendar-common-sets.js +++ b/calendar/base/content/calendar-common-sets.js @@ -517,17 +517,17 @@ var calendarController = { selected_events_requires_network: false, selected_events_invitation: false, /** * Returns a boolean indicating if its possible to write items to any * calendar. */ get writable() { - return cal.getCalendarManager().getCalendars({}).some(cal.isCalendarWritable); + return cal.getCalendarManager().getCalendars({}).some(cal.acl.isCalendarWritable); }, /** * Returns a boolean indicating if the application is currently in offline * mode. */ get offline() { return Services.io.offline; @@ -583,17 +583,17 @@ var calendarController = { * Returns a boolean indicating that all local calendars are readonly */ get all_local_calendars_readonly() { // We might want to speed this part up by keeping track of this in the // calendar manager. let calendars = cal.getCalendarManager().getCalendars({}); let count = calendars.length; for (let calendar of calendars) { - if (!cal.isCalendarWritable(calendar)) { + if (!cal.acl.isCalendarWritable(calendar)) { count--; } } return (count == 0); }, /** * Returns a boolean indicating that at least one of the items selected @@ -637,17 +637,17 @@ var calendarController = { /** * Returns a boolean indicating that at least one task in the selection is * on a calendar that is writable. */ get todo_items_writable() { let selectedTasks = getSelectedTasks(); for (let task of selectedTasks) { - if (cal.isCalendarWritable(task.calendar)) { + if (cal.acl.isCalendarWritable(task.calendar)) { return true; } } return false; } }; /** @@ -905,17 +905,17 @@ function calendarUpdateNewItemsCommand() "calendar_new_todo_command", "calendar_new_todo_context_command", "calendar_new_todo_todaypane_command" ]; // re-calculate command status CalendarNewEventsCommandEnabled = false; CalendarNewTasksCommandEnabled = false; - let calendars = cal.getCalendarManager().getCalendars({}).filter(cal.isCalendarWritable).filter(cal.userCanAddItemsToCalendar); + let calendars = cal.getCalendarManager().getCalendars({}).filter(cal.acl.isCalendarWritable).filter(cal.acl.userCanAddItemsToCalendar); if (calendars.some(cal.isEventCalendar)) { CalendarNewEventsCommandEnabled = true; } if (calendars.some(cal.isTaskCalendar)) { CalendarNewTasksCommandEnabled = true; } // update command status if required @@ -928,17 +928,17 @@ function calendarUpdateNewItemsCommand() } function calendarUpdateDeleteCommand(selectedItems) { let oldValue = CalendarDeleteCommandEnabled; CalendarDeleteCommandEnabled = (selectedItems.length > 0); /* we must disable "delete" when at least one item cannot be deleted */ for (let item of selectedItems) { - if (!cal.userCanDeleteItemsFromCalendar(item.calendar)) { + if (!cal.acl.userCanDeleteItemsFromCalendar(item.calendar)) { CalendarDeleteCommandEnabled = false; break; } } if (CalendarDeleteCommandEnabled != oldValue) { let commands = [ "calendar_delete_event_command", diff --git a/calendar/base/content/calendar-invitations-manager.js b/calendar/base/content/calendar-invitations-manager.js --- a/calendar/base/content/calendar-invitations-manager.js +++ b/calendar/base/content/calendar-invitations-manager.js @@ -186,17 +186,17 @@ InvitationsManager.prototype = { this.mInvitationsManager.addItem(item); } } } } }; for (let calendar of cals) { - if (!cal.isCalendarWritable(calendar) || calendar.getProperty("disabled")) { + if (!cal.acl.isCalendarWritable(calendar) || calendar.getProperty("disabled")) { opListener.onOperationComplete(); continue; } // temporary hack unless calCachedCalendar supports REQUEST_NEEDS_ACTION filter: calendar = calendar.getProperty("cache.uncachedCalendar"); if (!calendar) { opListener.onOperationComplete(); diff --git a/calendar/base/content/calendar-item-editing.js b/calendar/base/content/calendar-item-editing.js --- a/calendar/base/content/calendar-item-editing.js +++ b/calendar/base/content/calendar-item-editing.js @@ -385,17 +385,17 @@ function openEventDialog(calendarItem, c disposeJob(job); return; } // Set up some defaults mode = mode || "new"; calendar = calendar || getSelectedCalendar(); let calendars = cal.getCalendarManager().getCalendars({}); - calendars = calendars.filter(cal.isCalendarWritable); + calendars = calendars.filter(cal.acl.isCalendarWritable); let isItemSupported; if (cal.isToDo(calendarItem)) { isItemSupported = function(aCalendar) { return (aCalendar.getProperty("capabilities.tasks.supported") !== false); }; } else if (cal.isEvent(calendarItem)) { isItemSupported = function(aCalendar) { @@ -403,36 +403,36 @@ function openEventDialog(calendarItem, c }; } // Filter out calendars that don't support the given calendar item calendars = calendars.filter(isItemSupported); // Filter out calendar/items that we cannot write to/modify if (mode == "new") { - calendars = calendars.filter(cal.userCanAddItemsToCalendar); + calendars = calendars.filter(cal.acl.userCanAddItemsToCalendar); } else { /* modify */ calendars = calendars.filter((aCalendar) => { /* If the calendar is the item calendar, we check that the item * can be modified. If the calendar is NOT the item calendar, we * check that the user can remove items from that calendar and * add items to the current one. */ let isSameCalendar = calendarItem.calendar == aCalendar; - let canModify = cal.userCanModifyItem(calendarItem); - let canMoveItems = cal.userCanDeleteItemsFromCalendar(calendarItem.calendar) && - cal.userCanAddItemsToCalendar(aCalendar); + let canModify = cal.acl.userCanModifyItem(calendarItem); + let canMoveItems = cal.acl.userCanDeleteItemsFromCalendar(calendarItem.calendar) && + cal.acl.userCanAddItemsToCalendar(aCalendar); return isSameCalendar ? canModify : canMoveItems; }); } if (mode == "new" && - (!cal.isCalendarWritable(calendar) || - !cal.userCanAddItemsToCalendar(calendar) || + (!cal.acl.isCalendarWritable(calendar) || + !cal.acl.userCanAddItemsToCalendar(calendar) || !isItemSupported(calendar))) { if (calendars.length < 1) { // There are no writable calendars or no calendar supports the given // item. Don't show the dialog. disposeJob(job); return; } else { // Pick the first calendar that supports the item and is writable @@ -472,18 +472,18 @@ function openEventDialog(calendarItem, c // ask the provide if this item is an invitation. if this is the case // we'll open the summary dialog since the user is not allowed to change // the details of the item. let wrappedCalendar = cal.wrapInstance(calendar, Components.interfaces.calISchedulingSupport); let isInvitation = wrappedCalendar && wrappedCalendar.isInvitation(calendarItem); // open the dialog modeless let url; - let isEditable = mode == "modify" && !isInvitation && cal.userCanModifyItem(calendarItem); - if (cal.isCalendarWritable(calendar) && (mode == "new" || isEditable)) { + let isEditable = mode == "modify" && !isInvitation && cal.acl.userCanModifyItem(calendarItem); + if (cal.acl.isCalendarWritable(calendar) && (mode == "new" || isEditable)) { if (args.inTab) { url = args.useNewItemUI ? "chrome://lightning/content/html-item-editing/lightning-item-iframe.html" : "chrome://lightning/content/lightning-item-iframe.xul"; } else { url = "chrome://calendar/content/calendar-event-dialog.xul"; } } else { url = "chrome://calendar/content/calendar-summary-dialog.xul"; diff --git a/calendar/base/content/calendar-multiday-view.xml b/calendar/base/content/calendar-multiday-view.xml --- a/calendar/base/content/calendar-multiday-view.xml +++ b/calendar/base/content/calendar-multiday-view.xml @@ -1794,18 +1794,18 @@ this.startEditing(), 350); } else { this.select(event); event.stopPropagation(); } @@ -353,17 +353,17 @@ } ]]> diff --git a/calendar/base/content/calendar-views.js b/calendar/base/content/calendar-views.js --- a/calendar/base/content/calendar-views.js +++ b/calendar/base/content/calendar-views.js @@ -115,17 +115,17 @@ var calendarViewController = { }; // Make sure we are modifying a copy of aOccurrences, otherwise we will // run into race conditions when the view's doDeleteItem removes the // array elements while we are iterating through them. While we are at // it, filter out any items that have readonly calendars, so that // checking for one total item below also works out if all but one item // are readonly. - let occurrences = aOccurrences.filter(item => cal.isCalendarWritable(item.calendar)); + let occurrences = aOccurrences.filter(item => cal.acl.isCalendarWritable(item.calendar)); for (let itemToDelete of occurrences) { if (aUseParentItems) { // Usually happens when ctrl-click is used. In that case we // don't need to ask the user if he wants to delete an // occurrence or not. itemToDelete = itemToDelete.parentItem; } else if (!aDoNotConfirm && occurrences.length == 1) { diff --git a/calendar/base/content/dialogs/calendar-alarm-dialog.js b/calendar/base/content/dialogs/calendar-alarm-dialog.js --- a/calendar/base/content/dialogs/calendar-alarm-dialog.js +++ b/calendar/base/content/dialogs/calendar-alarm-dialog.js @@ -171,18 +171,18 @@ function snoozeAllItems(aDurationMinutes let alarmRichlist = document.getElementById("alarm-richlist"); let parentItems = {}; // Make a copy of the child nodes as they get modified live for (let node of alarmRichlist.childNodes) { // Check if the node is a valid alarm and is still part of DOM if (node.parentNode && node.item && node.alarm && - cal.isCalendarWritable(node.item.calendar) && - cal.userCanModifyItem(node.item) && + cal.acl.isCalendarWritable(node.item.calendar) && + cal.acl.userCanModifyItem(node.item) && !(node.item.parentItem.hashId in parentItems)) { // We only need to acknowledge one occurrence for repeating items parentItems[node.item.parentItem.hashId] = node.item.parentItem; getAlarmService().snoozeAlarm(node.item, node.alarm, duration); } } // we need to close the widget here explicitely because the dialog will stay // opened if there a still not snoozable alarms @@ -341,18 +341,18 @@ function removeWidgetFor(aItem, aAlarm) * Enables/disables the 'snooze all' button and displays or removes a r/o * notification based on the readability of the calendars of the alarms visible * in the alarm list */ function doReadOnlyChecks() { let countRO = 0; let alarmRichlist = document.getElementById("alarm-richlist"); for (let node of alarmRichlist.childNodes) { - if (!cal.isCalendarWritable(node.item.calendar) || - !cal.userCanModifyItem(node.item)) { + if (!cal.acl.isCalendarWritable(node.item.calendar) || + !cal.acl.userCanModifyItem(node.item)) { countRO++; } } // we disable the button if there are only alarms for not-writable items let snoozeAllButton = document.getElementById("alarm-snooze-all-button"); snoozeAllButton.disabled = (countRO && countRO == alarmRichlist.childNodes.length); if (snoozeAllButton.disabled) { diff --git a/calendar/base/content/dialogs/calendar-summary-dialog.js b/calendar/base/content/dialogs/calendar-summary-dialog.js --- a/calendar/base/content/dialogs/calendar-summary-dialog.js +++ b/calendar/base/content/dialogs/calendar-summary-dialog.js @@ -47,18 +47,18 @@ function onLoad() { setDialogId(document.documentElement, "calendar-event-summary-dialog"); } else if (cal.isToDo(item)) { setDialogId(document.documentElement, "calendar-task-summary-dialog"); } window.attendees = item.getAttendees({}); let calendar = cal.wrapInstance(item.calendar, Components.interfaces.calISchedulingSupport); - window.readOnly = !(cal.isCalendarWritable(calendar) && - (cal.userCanModifyItem(item) || + window.readOnly = !(cal.acl.isCalendarWritable(calendar) && + (cal.acl.userCanModifyItem(item) || (calendar && item.calendar.isInvitation(item) && cal.userCanRespondToInvitation(item)))); if (!window.readOnly && calendar) { let attendee = calendar.getInvitedAttendee(item); if (attendee) { // if this is an unresponded invitation, preset our default alarm values: if (!item.getAlarms({}).length && diff --git a/calendar/base/content/import-export.js b/calendar/base/content/import-export.js --- a/calendar/base/content/import-export.js +++ b/calendar/base/content/import-export.js @@ -106,17 +106,17 @@ function loadEventsFromFile(aCalendar) { } if (aCalendar) { putItemsIntoCal(aCalendar, items); return; } let calendars = cal.getCalendarManager().getCalendars({}); - calendars = calendars.filter(cal.isCalendarWritable); + calendars = calendars.filter(cal.acl.isCalendarWritable); if (calendars.length == 1) { // There's only one calendar, so it's silly to ask what calendar // the user wants to import into. putItemsIntoCal(calendars[0], items, filePath); } else if (calendars.length > 1) { // Ask what calendar to import into let args = {}; diff --git a/calendar/base/content/widgets/calendar-alarm-widget.xml b/calendar/base/content/widgets/calendar-alarm-widget.xml --- a/calendar/base/content/widgets/calendar-alarm-widget.xml +++ b/calendar/base/content/widgets/calendar-alarm-widget.xml @@ -115,18 +115,18 @@ (locationDescription.textContent.length < 1); // hide snooze button if read-only let snoozeButton = document.getAnonymousElementByAttribute( this, "anonid", "alarm-snooze-button" ); - if (!cal.isCalendarWritable(this.mItem.calendar) || - !cal.userCanModifyItem(this.mItem)) { + if (!cal.acl.isCalendarWritable(this.mItem.calendar) || + !cal.acl.userCanModifyItem(this.mItem)) { let tooltip = "reminderDisabledSnoozeButtonTooltip"; snoozeButton.disabled = true; snoozeButton.setAttribute("tooltiptext", cal.calGetString("calendar-alarms", tooltip)); } else { snoozeButton.disabled = false; snoozeButton.removeAttribute("tooltiptext"); } diff --git a/calendar/base/modules/calItipUtils.jsm b/calendar/base/modules/calItipUtils.jsm --- a/calendar/base/modules/calItipUtils.jsm +++ b/calendar/base/modules/calItipUtils.jsm @@ -137,17 +137,17 @@ cal.itip = { /** * Checks if the given calendar is a scheduling calendar. This means it * needs an organizer id and an itip transport. It should also be writable. * * @param calendar The calendar to check * @return True, if its a scheduling calendar. */ isSchedulingCalendar: function(calendar) { - return cal.isCalendarWritable(calendar) && + return cal.acl.isCalendarWritable(calendar) && calendar.getProperty("organizerId") && calendar.getProperty("itip.transport"); }, /** * Scope: iTIP message receiver * * Given an nsIMsgDBHdr and an imipMethod, set up the given itip item. @@ -176,17 +176,17 @@ cal.itip = { // Fall back to using the one from the itipItem's ICS. imipMethod = itipItem.receivedMethod; } cal.LOG("iTIP method: " + imipMethod); let isWritableCalendar = function(aCalendar) { /* TODO: missing ACL check for existing items (require callback API) */ return cal.itip.isSchedulingCalendar(aCalendar) && - cal.userCanAddItemsToCalendar(aCalendar); + cal.acl.userCanAddItemsToCalendar(aCalendar); }; let writableCalendars = cal.getCalendarManager().getCalendars({}).filter(isWritableCalendar); if (writableCalendars.length > 0) { let compCal = Components.classes["@mozilla.org/calendar/calendar;1?type=composite"] .createInstance(Components.interfaces.calICompositeCalendar); writableCalendars.forEach(compCal.addCalendar, compCal); itipItem.targetCalendar = compCal; diff --git a/calendar/base/src/calAlarmService.js b/calendar/base/src/calAlarmService.js --- a/calendar/base/src/calAlarmService.js +++ b/calendar/base/src/calAlarmService.js @@ -177,18 +177,18 @@ calAlarmService.prototype = { } // calling modifyItem will cause us to get the right callback // and update the alarm properly return newEvent.calendar.modifyItem(newEvent, aItem.parentItem, null); }, dismissAlarm: function(aItem, aAlarm) { let rv; - if (cal.isCalendarWritable(aItem.calendar) && - cal.userCanModifyItem(aItem)) { + if (cal.acl.isCalendarWritable(aItem.calendar) && + cal.acl.userCanModifyItem(aItem)) { let now = nowUTC(); // We want the parent item, otherwise we're going to accidentally // create an exception. We've relnoted (for 0.1) the slightly odd // behavior this can cause if you move an event after dismissing an // alarm let oldParent = aItem.parentItem; let newParent = oldParent.clone(); newParent.alarmLastAck = now; @@ -378,18 +378,18 @@ calAlarmService.prototype = { // our range. let timeUntilRefresh = this.mRangeEnd.subtractDate(now).inSeconds * 1000; if (timeUntilRefresh < timeout) { continue; } this.addTimer(aItem, alarm, timeout); } else if (showMissed && - cal.isCalendarWritable(aItem.calendar) && - cal.userCanModifyItem(aItem)) { + cal.acl.isCalendarWritable(aItem.calendar) && + cal.acl.userCanModifyItem(aItem)) { // This alarm is in the past and the calendar is writable, so we // could snooze or dismiss alarms. See if it has been previously // ack'd. let lastAck = aItem.parentItem.alarmLastAck; if (lastAck && lastAck.compare(alarmDate) >= 0) { // The alarm was previously dismissed or snoozed, no further // action required. continue; diff --git a/calendar/base/src/calTransactionManager.js b/calendar/base/src/calTransactionManager.js --- a/calendar/base/src/calTransactionManager.js +++ b/calendar/base/src/calTransactionManager.js @@ -45,18 +45,18 @@ calTransactionManager.prototype = { endBatch: function() { this.transactionManager.endBatch(false); }, checkWritable: function(transaction) { function checkItem(item) { return item && item.calendar && - cal.isCalendarWritable(item.calendar) && - cal.userCanAddItemsToCalendar(item.calendar); + cal.acl.isCalendarWritable(item.calendar) && + cal.acl.userCanAddItemsToCalendar(item.calendar); } let trans = transaction && transaction.wrappedJSObject; return trans && checkItem(trans.mItem) && checkItem(trans.mOldItem); }, undo: function() { this.transactionManager.undoTransaction(); diff --git a/calendar/lightning/content/lightning-item-iframe.js b/calendar/lightning/content/lightning-item-iframe.js --- a/calendar/lightning/content/lightning-item-iframe.js +++ b/calendar/lightning/content/lightning-item-iframe.js @@ -564,19 +564,19 @@ function loadDialog(aItem) { if (gNewItemUI) { let calendarToUse = aItem.calendar || window.arguments[0].calendar; let unfilteredList = sortCalendarArray(cal.getCalendarManager().getCalendars({})); // filter out calendars that should not be included let calendarList = unfilteredList.filter((calendar) => (calendar.id == calendarToUse.id || (calendar && - cal.isCalendarWritable(calendar) && - (cal.userCanAddItemsToCalendar(calendar) || - (calendar == aItem.calendar && cal.userCanModifyItem(aItem))) && + cal.acl.isCalendarWritable(calendar) && + (cal.acl.userCanAddItemsToCalendar(calendar) || + (calendar == aItem.calendar && cal.acl.userCanModifyItem(aItem))) && cal.isItemSupported(aItem, calendar)))); itemProps.calendarList = calendarList.map(calendar => [calendar.id, calendar.name]); if (calendarToUse && calendarToUse.id) { let index = itemProps.calendarList.findIndex( calendar => (calendar[0] == calendarToUse.id)); if (index != -1) {