code: function authorize(newDoc, oldDoc, userContext, securityInfo, docDefinition) {
      if (utils.isValueNullOrUndefined(userContext)) {
        throw unauthorizedResult();
      }
  
      var authorizedRoles = resolveRequiredAuthorizations(newDoc, oldDoc, docDefinition.authorizedRoles);
      var authorizedUsers = resolveRequiredAuthorizations(newDoc, oldDoc, docDefinition.authorizedUsers);
      var grantAllMembersWriteAccess = utils.resolveDocumentConstraint(docDefinition.grantAllMembersWriteAccess);
  
      if (grantAllMembersWriteAccess) {
        // The document definition allows any authenticated DB member to write documents of this type
        return authorizationSuccessResult(authorizedRoles, authorizedUsers);
      } else if (isAdminUser(userContext, securityInfo)) {
        // Database admins have unrestricted access
        return authorizationSuccessResult(authorizedRoles, authorizedUsers);
      } else if (!authorizedRoles && !authorizedUsers) {
        // The document type does not define any authorized roles or users
        throw forbiddenResult();
      }
  
      var roleMatch = hasAuthorizedRole(authorizedRoles, userContext.roles);
      var usernameMatch = hasAuthorizedUsername(authorizedUsers, userContext.name);
      if (!roleMatch && !usernameMatch) {
        // None of the required authorizations were satisfied
        throw forbiddenResult();
      } else {
        return authorizationSuccessResult(authorizedRoles, authorizedUsers);
      }
    }
docs: Ensures the user is authorized to create/replace/delete this document