imports/vx/both/code/util.js
/**
     * Determine whether the specified user has a role within a specified tenant or domain.
     *
     * @param {string} userId User ID.
     * @param {string} tenantOrDomainId Tenant or domain ID.
     * @param {string} roleName Role name.
     * @return {boolean} True if role name is enabled.
     */
Determine whether the specified user has a role within a specified tenant or domain.
@param {string} userId User ID.
@param {string} tenantOrDomainId Tenant or domain ID.
@param {string} roleName Role name.
@return {boolean} True if role name is enabled.
Determine whether the specified user has a role within a specified tenant or domain . @param { string } userId User ID . @param { string } tenantOrDomainId Tenant or domain ID . @param { string } roleName Role name . @return { boolean } True if role name is enabled .
doesUserHaveRole(userId, tenantOrDomainId, roleName) {
        if (!userId || !tenantOrDomainId || !roleName) {
            return false
        }
        let checkTenant = Util.isTenantRole(roleName)
        let fieldList = {}
        fieldList.fields = {}
        fieldList.fields["profile." + (checkTenant ? "tenants" : "domains")] = 1
        let user = Meteor.users.findOne(userId, fieldList)
        if (!user) {
            return false
        }
        let tenantsOrDomains = user.profile && (checkTenant ? user.profile.tenants : user.profile.domains)
        if (!tenantsOrDomains) {
            return false
        }
        let tenantOrDomain = _.findWhere(tenantsOrDomains, (checkTenant ? { tenantId: tenantOrDomainId } : { domainId: tenantOrDomainId }))
        if (!tenantOrDomain) {
            return false
        }
        if (!tenantOrDomain.roles) {
            return false
        }
        return _.contains(tenantOrDomain.roles, roleName)
    }
doesUserHaveRole ( userId , tenantOrDomainId , roleName ) { if ( ! userId || ! tenantOrDomainId || ! roleName ) { return false } let checkTenant = Util . isTenantRole ( roleName ) let fieldList = { } fieldList . fields = { } fieldList . fields [ "profile." + ( checkTenant ? "tenants" : "domains" ) ] = 1 let user = Meteor . users . findOne ( userId , fieldList ) if ( ! user ) { return false } let tenantsOrDomains = user . profile && ( checkTenant ? user . profile . tenants : user . profile . domains ) if ( ! tenantsOrDomains ) { return false } let tenantOrDomain = _ . findWhere ( tenantsOrDomains , ( checkTenant ? { tenantId : tenantOrDomainId } : { domainId : tenantOrDomainId } ) ) if ( ! tenantOrDomain ) { return false } if ( ! tenantOrDomain . roles ) { return false } return _ . contains ( tenantOrDomain . roles , roleName ) }
Determine whether the specified user has a role within a specified tenant or domain.
Determine whether the specified user has a role within a specified tenant or domain .