Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-5037

Sync Function example: blocking new doc writes on user port

    XMLWordPrintable

Details

    Description

      Scenario: you would like to reject all attempts to create a document on the public port - from mobile/web clients (i.e only allow document to be created through the Admin port.)

      • The oldDoc value is undefined for new document writes.
      • requireAdmin() can detect if the write operation is performed on the user or the admin port.

      function isAdmin() {
        try {
          requireAdmin();
          console.log("document was edited by an Admin");
        } catch (err) {
          console.log("document was edited by an regular user " + err);
          return false;
        }
      }
       
      admin=isAdmin();
      if (admin === false) {
        if (oldDoc == undefined) {
          throw ({
            forbidden: "Document "+ doc._id +" cannot create documents from client, rejecting "
          })
        }
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              jamiltz James Nocentini
              roi.katz Roi Katz
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty