templates/sync-function/authorization-module.js
function getRequiredAuthorizations(doc, oldDoc, authorizationDefinition) {
    var authorizationMap = utils.resolveDocumentConstraint(authorizationDefinition);

    if (utils.isValueNullOrUndefined(authorizationMap)) {
      // This document type does not define any authorizations (channels, roles, users) at all
      return null;
    }

    var requiredAuthorizations = [ ];
    var writeAuthorizationFound = false;
    if (authorizationMap.write) {
      writeAuthorizationFound = true;
      appendToAuthorizationList(requiredAuthorizations, authorizationMap.write);
    }

    if (doc._deleted) {
      if (authorizationMap.remove) {
        writeAuthorizationFound = true;
        appendToAuthorizationList(requiredAuthorizations, authorizationMap.remove);
      }
    } else if (!utils.isDocumentMissingOrDeleted(oldDoc) && authorizationMap.replace) {
      writeAuthorizationFound = true;
      appendToAuthorizationList(requiredAuthorizations, authorizationMap.replace);
    } else if (utils.isDocumentMissingOrDeleted(oldDoc) && authorizationMap.add) {
      writeAuthorizationFound = true;
      appendToAuthorizationList(requiredAuthorizations, authorizationMap.add);
    }

    if (writeAuthorizationFound) {
      return requiredAuthorizations;
    } else {
      // This document type does not define any authorizations (channels, roles, users) that apply to this particular write operation type
      return null;
    }
  }
function getRequiredAuthorizations(doc, oldDoc, authorizationDefinition) {
    var authorizationMap = utils.resolveDocumentConstraint(authorizationDefinition);

    if (utils.isValueNullOrUndefined(authorizationMap)) {
      // This document type does not define any authorizations (channels, roles, users) at all
      return null;
    }

    var requiredAuthorizations = [ ];
    var writeAuthorizationFound = false;
    if (authorizationMap.write) {
      writeAuthorizationFound = true;
      appendToAuthorizationList(requiredAuthorizations, authorizationMap.write);
    }

    if (doc._deleted) {
      if (authorizationMap.remove) {
        writeAuthorizationFound = true;
        appendToAuthorizationList(requiredAuthorizations, authorizationMap.remove);
      }
    } else if (!utils.isDocumentMissingOrDeleted(oldDoc) && authorizationMap.replace) {
      writeAuthorizationFound = true;
      appendToAuthorizationList(requiredAuthorizations, authorizationMap.replace);
    } else if (utils.isDocumentMissingOrDeleted(oldDoc) && authorizationMap.add) {
      writeAuthorizationFound = true;
      appendToAuthorizationList(requiredAuthorizations, authorizationMap.add);
    }

    if (writeAuthorizationFound) {
      return requiredAuthorizations;
    } else {
      // This document type does not define any authorizations (channels, roles, users) that apply to this particular write operation type
      return null;
    }
  }
Retrieves a list of authorizations (e.g. channels, roles, users) for the current document write operation type (add, replace or remove)