Bug 1432142 - Move acl related functions into calACLUtils.jsm - manual changes. r=MakeMyDay
authorPhilipp Kewisch <mozilla@kewis.ch>
Sat, 14 Oct 2017 23:10:52 +0200
changeset 30967 3058d4ba1627fd31e1e7c448d3d80f4a3064306e
parent 30966 cde38eb25eba56a89cbd4afd4d757db567065f92
child 30968 d57095f7ae224940b661be89bfbbd94f485b364e
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersMakeMyDay
bugs1432142
Bug 1432142 - Move acl related functions into calACLUtils.jsm - manual changes. r=MakeMyDay MozReview-Commit-ID: 6XE3oIWomvU
calendar/base/modules/calACLUtils.jsm
calendar/base/modules/calUtils.jsm
calendar/base/modules/calUtilsCompat.jsm
calendar/base/modules/moz.build
calendar/base/src/calUtils.js
new file mode 100644
--- /dev/null
+++ b/calendar/base/modules/calACLUtils.jsm
@@ -0,0 +1,80 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://calendar/modules/calUtils.jsm");
+
+this.EXPORTED_SYMBOLS = ["calacl"]; /* exported calacl */
+
+var calacl = {
+    /**
+     * Check if the specified calendar is writable. This is the case when it is
+     * not marked readOnly, we are not offline, or we are offline and the
+     * calendar is local.
+     *
+     * @param aCalendar     The calendar to check
+     * @return              True if the calendar is writable
+     */
+    isCalendarWritable: function(aCalendar) {
+        return !aCalendar.getProperty("disabled") &&
+                !aCalendar.readOnly &&
+                (!Services.io.offline ||
+                 aCalendar.getProperty("cache.enabled") ||
+                 aCalendar.getProperty("cache.always") ||
+                 aCalendar.getProperty("requiresNetwork") === false);
+    },
+
+    /**
+     * Check if the specified calendar is writable from an ACL point of view.
+     *
+     * @param aCalendar     The calendar to check
+     * @return              True if the calendar is writable
+     */
+    userCanAddItemsToCalendar: function(aCalendar) {
+        let aclEntry = aCalendar.aclEntry;
+        return !aclEntry || !aclEntry.hasAccessControl ||
+               aclEntry.userIsOwner || aclEntry.userCanAddItems;
+    },
+
+    /**
+     * Check if the user can delete items from the specified calendar, from an
+     * ACL point of view.
+     *
+     * @param aCalendar     The calendar to check
+     * @return              True if the calendar is writable
+     */
+    userCanDeleteItemsFromCalendar: function(aCalendar) {
+        let aclEntry = aCalendar.aclEntry;
+        return !aclEntry || !aclEntry.hasAccessControl ||
+               aclEntry.userIsOwner || aclEntry.userCanDeleteItems;
+    },
+
+    /**
+     * Check if the user can fully modify the specified item, from an ACL point
+     * of view.  Note to be confused with the right to respond to an
+     * invitation, which is handled instead by userCanRespondToInvitation.
+     *
+     * @param aItem         The calendar item to check
+     * @return              True if the item is modifiable
+     */
+    userCanModifyItem: function(aItem) {
+        let aclEntry = aItem.aclEntry;
+        return !aclEntry || !aclEntry.calendarEntry.hasAccessControl ||
+               aclEntry.calendarEntry.userIsOwner || aclEntry.userCanModify;
+    },
+
+    /**
+     * Checks if the user can modify the item and has the right to respond to
+     * invitations for the item.
+     *
+     * @param aItem         The calendar item to check
+     * @return              True if the invitation w.r.t. the item can be
+     *                        responded to.
+     */
+    userCanRespondToInvitation: function(aItem) {
+        let aclEntry = aItem.aclEntry;
+        // TODO check if || is really wanted here
+        return aclUtils.userCanModifyItem(aItem) || aclEntry.userCanRespond;
+    }
+};
--- a/calendar/base/modules/calUtils.jsm
+++ b/calendar/base/modules/calUtils.jsm
@@ -941,16 +941,17 @@ var cal = {
      * @param prop   property to be deleted on shutdown
      *               (if null, |object| will be deleted)
      */
     registerForShutdownCleanup: shutdownCleanup
 };
 
 // Sub-modules for calUtils
 XPCOMUtils.defineLazyModuleGetter(cal, "dtz", "resource://calendar/modules/calDateTimeUtils.jsm", "caldtz");
+XPCOMUtils.defineLazyModuleGetter(cal, "acl", "resource://calendar/modules/calACLUtils.jsm", "calacl");
 
 /**
  * Returns a function that provides access to the given service.
  *
  * @param cid           The contract id to create
  * @param iid           The interface id to create with
  * @return {function}   A function that returns the given service
  */
--- a/calendar/base/modules/calUtilsCompat.jsm
+++ b/calendar/base/modules/calUtilsCompat.jsm
@@ -12,16 +12,22 @@ Components.utils.import("resource://gre/
 
 this.EXPORTED_SYMBOLS = ["injectCalUtilsCompat"];
 
 /**
  * Migration data for backwards compatibility, will be used with
  * injectCalUtilsCompat.
  */
 var migrations = {
+    acl: {
+        isCalendarWritable: "isCalendarWritable",
+        userCanAddItemsToCalendar: "userCanAddItemsToCalendar",
+        userCanDeleteItemsFromCalendar: "userCanDeleteItemsFromCalendar",
+        userCanModifyItem: "userCanModifyItem"
+    },
     dtz: {
         now: "now",
         ensureDateTime: "ensureDateTime",
         getRecentTimezones: "getRecentTimezones",
         saveRecentTimezone: "saveRecentTimezone",
         getDefaultStartDate: "getDefaultStartDate",
         setDefaultStartEndHour: "setDefaultStartEndHour",
         calGetStartDateProp: "startDateProp",
--- a/calendar/base/modules/moz.build
+++ b/calendar/base/modules/moz.build
@@ -1,14 +1,15 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_JS_MODULES += [
+    'calACLUtils.jsm',
     'calAlarmUtils.jsm',
     'calAsyncUtils.jsm',
     'calAuthUtils.jsm',
     'calDateTimeUtils.jsm',
     'calExtract.jsm',
     'calHashedArray.jsm',
     'calItemUtils.jsm',
     'calIteratorUtils.jsm',
--- a/calendar/base/src/calUtils.js
+++ b/calendar/base/src/calUtils.js
@@ -2,19 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* This file contains commonly used functions in a centralized place so that
  * various components (and other js scopes) don't need to replicate them. Note
  * that loading this file twice in the same scope will throw errors.
  */
 
-/* exported getCalendarDirectory, isCalendarWritable,
- *          userCanAddItemsToCalendar, userCanDeleteItemsFromCalendar,
- *          attendeeMatchesAddresses, userCanRespondToInvitation,
+/* exported getCalendarDirectory, attendeeMatchesAddresses,
  *          openCalendarWizard, openCalendarProperties, calPrint,
  *          calRadioGroupSelectItem, isItemSupported, getPrefCategoriesArray,
  *          setPrefCategoriesFromArray, compareItems, calTryWrappedJSObject,
  *          compareArrays, LOG, WARN, ERROR, showError,
  *          getContrastingTextColor, checkIfInRange, getProgressAtom,
  *          sendMailTo, calSetProdidVersion, applyAttributeToMenuChildren,
  *          isPropertyValueSame, getParentNodeOrThis,
  *          getParentNodeOrThisByAttribute, setItemProperty,
@@ -84,68 +82,16 @@ function getCalendarDirectory() {
             }
         }
         getCalendarDirectory.mDir = dir;
     }
     return getCalendarDirectory.mDir.clone();
 }
 
 /**
- * Check if the specified calendar is writable. This is the case when it is not
- * marked readOnly, we are not offline, or we are offline and the calendar is
- * local.
- *
- * @param aCalendar     The calendar to check
- * @return              True if the calendar is writable
- */
-function isCalendarWritable(aCalendar) {
-    return !aCalendar.getProperty("disabled") &&
-            !aCalendar.readOnly &&
-            (!Services.io.offline ||
-             aCalendar.getProperty("cache.enabled") ||
-             aCalendar.getProperty("cache.always") ||
-             aCalendar.getProperty("requiresNetwork") === false);
-}
-
-/**
- * Check if the specified calendar is writable from an ACL point of view.
- *
- * @param aCalendar     The calendar to check
- * @return              True if the calendar is writable
- */
-function userCanAddItemsToCalendar(aCalendar) {
-    let aclEntry = aCalendar.aclEntry;
-    return !aclEntry || !aclEntry.hasAccessControl || aclEntry.userIsOwner || aclEntry.userCanAddItems;
-}
-
-/**
- * Check if the user can delete items from the specified calendar, from an ACL point of view.
- *
- * @param aCalendar     The calendar to check
- * @return              True if the calendar is writable
- */
-function userCanDeleteItemsFromCalendar(aCalendar) {
-    let aclEntry = aCalendar.aclEntry;
-    return !aclEntry || !aclEntry.hasAccessControl || aclEntry.userIsOwner || aclEntry.userCanDeleteItems;
-}
-
-/**
- * Check if the user can fully modify the specified item, from an ACL point of view.
- * Note to be confused with the right to respond to an invitation, which is
- * handled instead by userCanRespondToInvitation.
- *
- * @param aItem         The calendar item to check
- * @return              True if the item is modifiable
- */
-function userCanModifyItem(aItem) {
-    let aclEntry = aItem.aclEntry;
-    return !aclEntry || !aclEntry.calendarEntry.hasAccessControl || aclEntry.calendarEntry.userIsOwner || aclEntry.userCanModify;
-}
-
-/**
  * Check if the attendee object matches one of the addresses in the list. This
  * is useful to determine whether the current user acts as a delegate.
  *
  * @param aAttendee     The reference attendee object
  * @param addresses     The list of addresses
  * @return              True if there is a match
  */
 function attendeeMatchesAddresses(anAttendee, addresses) {
@@ -165,29 +111,16 @@ function attendeeMatchesAddresses(anAtte
             return true;
         }
     }
 
     return false;
 }
 
 /**
- * Check if the user can fully modify the specified item, from an ACL point of view.
- * Note to be confused with the right to respond to an invitation, which is
- * handled instead by userCanRespondToInvitation.
- *
- * @param aItem         The calendar item to check
- * @return              True if the item is modifiable
- */
-function userCanRespondToInvitation(aItem) {
-    let aclEntry = aItem.aclEntry;
-    return userCanModifyItem(aItem) || aclEntry.userCanRespond;
-}
-
-/**
  * Opens the Create Calendar wizard
  *
  * @param aWindow The window to show the dialog in.
  * @param aCallback  a function to be performed after calendar creation
  */
 function openCalendarWizard(aWindow, aCallback) {
     aWindow.openDialog("chrome://calendar/content/calendarCreation.xul", "caEditServer",
                        // Workaround for Bug 1151440 - the HTML color picker won't work