Bug 1729235 - Don't clear read-only status of CalDAV calendars even if it is writeable. r=mschroeder a=wsmwk
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 20 Sep 2021 14:56:26 +1200
changeset 43971 386347826e410ee9a8ed4fe9170e2fa26d779fee
parent 43970 08443b6b12269b8a30ddd7b4efa05692427b8dff
child 43972 7a88728e6cb474089b6f22fb86c6a4f1c8be02af
push id3313
push userthunderbird@calypsoblue.org
push dateMon, 27 Sep 2021 19:05:56 +0000
treeherdercomm-beta@5ee0f2f00dcb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmschroeder, wsmwk
bugs1729235, 1665203
Bug 1729235 - Don't clear read-only status of CalDAV calendars even if it is writeable. r=mschroeder a=wsmwk Bug 1665203 set the read-only status to match the user's privileges on the server, but this clears a user-set read-only status if the user can write to the calendar but doesn't want to. Also, gets rid of mReadOnly as it does nothing, and renames mDisabled to make it more obvious what it is. Differential Revision: https://phabricator.services.mozilla.com/D126061
calendar/providers/caldav/CalDavCalendar.jsm
calendar/providers/caldav/modules/CalDavRequestHandlers.jsm
--- a/calendar/providers/caldav/CalDavCalendar.jsm
+++ b/calendar/providers/caldav/CalDavCalendar.jsm
@@ -30,17 +30,17 @@ var MIME_TEXT_XML = "text/xml; charset=u
 
 var cIOL = Ci.calIOperationListener;
 
 function CalDavCalendar() {
   this.initProviderBase();
   this.unmappedProperties = [];
   this.mUriParams = null;
   this.mItemInfoCache = {};
-  this.mDisabled = false;
+  this.mDisabledByDavError = false;
   this.mCalHomeSet = null;
   this.mInboxUrl = null;
   this.mOutboxUrl = null;
   this.mCalendarUserAddress = null;
   this.mCheckedServerInfo = null;
   this.mPrincipalUrl = null;
   this.mSenderAddress = null;
   this.mHrefIndex = {};
@@ -323,17 +323,17 @@ CalDavCalendar.prototype = {
   // calICalendar interface
   //
 
   // readonly attribute AUTF8String type;
   get type() {
     return "caldav";
   },
 
-  mDisabled: true,
+  mDisabledByDavError: true,
 
   mCalendarUserAddress: null,
   get calendarUserAddress() {
     return this.mCalendarUserAddress;
   },
 
   mPrincipalUrl: null,
   get principalUrl() {
@@ -1246,17 +1246,17 @@ CalDavCalendar.prototype = {
 
       if (response.status == -1) {
         notifyListener(Cr.NS_OK);
         return;
       } else if (response.notFound) {
         cal.LOG(`CalDAV: Disabling calendar ${this.name} due to 404`);
         notifyListener(Cr.NS_ERROR_FAILURE);
         return;
-      } else if (response.ok && this.mDisabled) {
+      } else if (response.ok && this.mDisabledByDavError) {
         // Looks like the calendar is there again, check its resource
         // type first.
         this.checkDavResourceType(aChangeLogListener);
         return;
       } else if (!response.ok) {
         cal.LOG("CalDAV: Failed to get ctag from server for calendar " + this.name);
         notifyListener(Cr.NS_OK);
         return;
@@ -1317,17 +1317,17 @@ CalDavCalendar.prototype = {
    *
    * @param {nsIURI} aUri - The uri to request the items from.
    *                        NOTE: This must be the uri without any uri
    *                        params. They will be appended in this function.
    * @param aChangeLogListener - (optional) The listener to notify for cached
    *                             calendars.
    */
   getUpdatedItems(aUri, aChangeLogListener) {
-    if (this.mDisabled) {
+    if (this.mDisabledByDavError) {
       // check if maybe our calendar has become available
       this.checkDavResourceType(aChangeLogListener);
       return;
     }
 
     if (this.mHasWebdavSyncSupport) {
       let webDavSync = new CalDavWebDavSyncHandler(this, aUri, aChangeLogListener);
       webDavSync.doWebDAVSync();
@@ -1583,23 +1583,24 @@ CalDavCalendar.prototype = {
         } else if (owner) {
           this.mPrincipalUrl = owner;
           cal.LOG("CalDAV: Found principal url from DAV:owner " + this.mPrincipalUrl);
         }
 
         let resourceType = response.firstProps["D:resourcetype"] || new Set();
         if (resourceType.has("C:calendar")) {
           // This is a valid calendar resource
-          if (this.mDisabled) {
-            this.mDisabled = false;
-            this.mReadOnly = false;
+          if (this.mDisabledByDavError) {
+            this.mDisabledByDavError = false;
           }
 
           let privs = response.firstProps["D:current-user-privilege-set"];
-          if (privs && privs instanceof Set) {
+          // Don't clear this.readOnly, only set it. The user may have write
+          // privileges but not want to use them.
+          if (!this.readOnly && privs && privs instanceof Set) {
             this.readOnly = ![
               "D:write",
               "D:write-content",
               "D:write-properties",
               "D:all",
             ].some(priv => privs.has(priv));
           }
 
@@ -1931,18 +1932,17 @@ CalDavCalendar.prototype = {
     let localizedMessage;
     let modificationError = mapModification[aErrNo];
 
     if (!message) {
       // Only notify if there is a message for this error
       return;
     }
     localizedMessage = cal.l10n.getCalString(message, [this.mUri.spec]);
-    this.mReadOnly = true;
-    this.mDisabled = true;
+    this.mDisabledByDavError = true;
     this.notifyError(aErrNo, localizedMessage);
     this.notifyError(
       modificationError ? Ci.calIErrors.MODIFICATION_FAILED : Ci.calIErrors.READ_FAILED,
       this.buildDetailedMessage(status, extraInfo)
     );
   },
 
   buildDetailedMessage(status, extraInfo) {
--- a/calendar/providers/caldav/modules/CalDavRequestHandlers.jsm
+++ b/calendar/providers/caldav/modules/CalDavRequestHandlers.jsm
@@ -380,17 +380,17 @@ class CalDavWebDavSyncHandler extends XM
   unhandledErrors = 0;
   itemsReported = null;
   itemsNeedFetching = null;
   additionalSyncNeeded = false;
 
   QueryInterface = ChromeUtils.generateQI(["nsIRequestObserver", "nsIStreamListener"]);
 
   async doWebDAVSync() {
-    if (this.calendar.mDisabled) {
+    if (this.calendar.mDisabledByDavError) {
       // check if maybe our calendar has become available
       this.calendar.checkDavResourceType(this.changeLogListener);
       return;
     }
 
     let syncTokenString = "<sync-token/>";
     if (this.calendar.mWebdavSyncToken && this.calendar.mWebdavSyncToken.length > 0) {
       let syncToken = cal.xml.escapeString(this.calendar.mWebdavSyncToken);
@@ -758,17 +758,17 @@ class CalDavMultigetSyncHandler extends 
   unhandledErrors = 0;
   itemsNeedFetching = null;
   additionalSyncNeeded = false;
   timer = null;
 
   QueryInterface = ChromeUtils.generateQI(["nsIRequestObserver", "nsIStreamListener"]);
 
   doMultiGet() {
-    if (this.calendar.mDisabled) {
+    if (this.calendar.mDisabledByDavError) {
       // check if maybe our calendar has become available
       this.calendar.checkDavResourceType(this.changeLogListener);
       return;
     }
 
     let batchSize = Services.prefs.getIntPref("calendar.caldav.multigetBatchSize", 100);
     let hrefString = "";
     while (this.itemsNeedFetching.length && batchSize > 0) {