imports/vx/both/code/vxapp.js
/**
     * Adjust a supplied publishing request object to limit visibility based on the publishing mode.
     *
     * @param {object} request Publishing request object including criteria, options, extra.
     * @param {string} userId User ID requesting that records be published.
     * @param {object} subscriptionParameters Subscription parameters (required on client only).
     */
Adjust a supplied publishing request object to limit visibility based on the publishing mode.
@param {object} request Publishing request object including criteria, options, extra.
@param {string} userId User ID requesting that records be published.
@param {object} subscriptionParameters Subscription parameters (required on client only).
Adjust a supplied publishing request object to limit visibility based on the publishing mode . @param { object } request Publishing request object including criteria options extra . @param { string } userId User ID requesting that records be published . @param { object } subscriptionParameters Subscription parameters ( required on client only ) .
adjustPublishingRequest(request, userId, subscriptionParameters) {
        if (!userId) {
            OLog.error(`vxapp.js adjustPublishingRequest no userId specified, request=${OLog.errorString(request)}`)
            return request
        }
        if (Meteor.isClient && !subscriptionParameters) {
            OLog.error(`vxapp.js adjustPublishingRequest on client subscriptionParameters are required, request=${OLog.errorString(request)}`)
            return request
        }
        if (Meteor.isServer) {
            let result = VXApp.getSubscriptionParameters(userId)
            if (!result.success) {
                OLog.error("vxapp.js adjustPublishingRequest on client unable to get subscription parameters")
                return request
            }
            subscriptionParameters = result.subscriptionParameters
        }
        if (request.extra.subscriptionName === "current_tenants") {
            if (request.extra.mode === "DEFEAT")  {
                request.criteria.dateRetired = { $exists : false }
            }
            else if (request.extra.mode === "DOMAIN") {
                request.criteria = { _id : subscriptionParameters.tenantId }
            }
            else if (request.extra.mode === "TEAM") {
                request.criteria = { _id : subscriptionParameters.tenantId }
            }
            else if (request.extra.mode === "TEXAS") {
                request.criteria = { _id : { $in: subscriptionParameters.tenantIds } }
            }
            else {
                request.criteria = { _id : subscriptionParameters.tenantId }
            }
        }
        else if (request.extra.subscriptionName === "current_domains") {
            if (request.extra.mode === "DEFEAT")  {
                request.criteria.dateRetired = { $exists : false }
            }
            else if (request.extra.mode === "DOMAIN") {
                request.criteria = { _id : subscriptionParameters.domainId }
            }
            else if (request.extra.mode === "TEAM") {
                request.criteria = { tenant : subscriptionParameters.tenantId, dateRetired : { $exists : false } }
            }
            else if (request.extra.mode === "TEXAS") {
                request.criteria = { tenant: { $in: subscriptionParameters.tenantIds }, dateRetired : { $exists : false } }
            }
            else {
                request.criteria = { _id : subscriptionParameters.domainId }
            }
        }
        else if (request.extra.subscriptionName === "current_users") {
            if (request.extra.mode === "DEFEAT")  {
            }
            else if (request.extra.mode === "DOMAIN") {
                request.criteria = { "profile.domains": { $elemMatch : { domainId : subscriptionParameters.domainId } } }
            }
            else if (request.extra.mode === "TEAM") {
                request.criteria = { "profile.tenants": { $elemMatch : { tenantId : subscriptionParameters.tenantId } } }
            }
            else if (request.extra.mode === "TEXAS") {
                request.criteria = { "profile.tenants": { $elemMatch : { tenantId : { $in: subscriptionParameters.tenantIds } } } }
            }
            else {
                request.criteria = { "profile.domains": { $elemMatch : { domainId : subscriptionParameters.domainId } } }
            }
        }
        else {
            request.criteria = request.criteria || {}
            if (request.extra.mode === "DEFEAT")  {
            }
            else if (request.extra.mode === "DOMAIN") {
                request.criteria.domain = subscriptionParameters.domainId
            }
            else if (request.extra.mode === "TEAM") {
                request.criteria.domain = { $in: subscriptionParameters.domainIdsOfCurrentTenant }
            }
            else if (request.extra.mode === "TEXAS") {
                request.criteria.domain = { $in: subscriptionParameters.domainIds }
            }
            else {
                request.criteria.domain = subscriptionParameters.domainId
            }
        }
        return request
    }
adjustPublishingRequest ( request , userId , subscriptionParameters ) { if ( ! userId ) { OLog . error ( ` ${ OLog . errorString ( request ) } ` ) return request } if ( Meteor . isClient && ! subscriptionParameters ) { OLog . error ( ` ${ OLog . errorString ( request ) } ` ) return request } if ( Meteor . isServer ) { let result = VXApp . getSubscriptionParameters ( userId ) if ( ! result . success ) { OLog . error ( "vxapp.js adjustPublishingRequest on client unable to get subscription parameters" ) return request } subscriptionParameters = result . subscriptionParameters } if ( request . extra . subscriptionName === "current_tenants" ) { if ( request . extra . mode === "DEFEAT" ) { request . criteria . dateRetired = { $exists : false } } else if ( request . extra . mode === "DOMAIN" ) { request . criteria = { _id : subscriptionParameters . tenantId } } else if ( request . extra . mode === "TEAM" ) { request . criteria = { _id : subscriptionParameters . tenantId } } else if ( request . extra . mode === "TEXAS" ) { request . criteria = { _id : { $in : subscriptionParameters . tenantIds } } } else { request . criteria = { _id : subscriptionParameters . tenantId } } } else if ( request . extra . subscriptionName === "current_domains" ) { if ( request . extra . mode === "DEFEAT" ) { request . criteria . dateRetired = { $exists : false } } else if ( request . extra . mode === "DOMAIN" ) { request . criteria = { _id : subscriptionParameters . domainId } } else if ( request . extra . mode === "TEAM" ) { request . criteria = { tenant : subscriptionParameters . tenantId , dateRetired : { $exists : false } } } else if ( request . extra . mode === "TEXAS" ) { request . criteria = { tenant : { $in : subscriptionParameters . tenantIds } , dateRetired : { $exists : false } } } else { request . criteria = { _id : subscriptionParameters . domainId } } } else if ( request . extra . subscriptionName === "current_users" ) { if ( request . extra . mode === "DEFEAT" ) { } else if ( request . extra . mode === "DOMAIN" ) { request . criteria = { "profile.domains" : { $elemMatch : { domainId : subscriptionParameters . domainId } } } } else if ( request . extra . mode === "TEAM" ) { request . criteria = { "profile.tenants" : { $elemMatch : { tenantId : subscriptionParameters . tenantId } } } } else if ( request . extra . mode === "TEXAS" ) { request . criteria = { "profile.tenants" : { $elemMatch : { tenantId : { $in : subscriptionParameters . tenantIds } } } } } else { request . criteria = { "profile.domains" : { $elemMatch : { domainId : subscriptionParameters . domainId } } } } } else { request . criteria = request . criteria || { } if ( request . extra . mode === "DEFEAT" ) { } else if ( request . extra . mode === "DOMAIN" ) { request . criteria . domain = subscriptionParameters . domainId } else if ( request . extra . mode === "TEAM" ) { request . criteria . domain = { $in : subscriptionParameters . domainIdsOfCurrentTenant } } else if ( request . extra . mode === "TEXAS" ) { request . criteria . domain = { $in : subscriptionParameters . domainIds } } else { request . criteria . domain = subscriptionParameters . domainId } } return request }
Adjust a supplied publishing request object to limit visibility based on the publishing mode.
Adjust a supplied publishing request object to limit visibility based on the publishing mode .
// Simply leave criteria alone. // Standard is to limit based on a field "domain" which is commonly used in most record types. // WARNING: default behavior is really to adjust and not replace the criteria: // Simply leave criteria alone.