var filterInteractingTenants = module.exports.filterInteractingTenants = function(tenantAlias) { if (TenantsUtil.isPrivate(tenantAlias)) { // A private tenant can only interact with itself return filterTerm('tenantAlias', tenantAlias); } else { // A public tenant can only interact with public tenants var nonInteractingTenantAliases = _.pluck(TenantsAPI.getNonInteractingTenants(), 'alias'); return filterNot(filterTerms('tenantAlias', nonInteractingTenantAliases)); } };
var getMe = module.exports.getMe = function(ctx, callback) { // Get the compact tenant object for the current tenant var tenant = ctx.tenant().compact(); // Indicate whether the tenant is private or not tenant.isPrivate = TenantsUtil.isPrivate(tenant.alias); // Handle the anonymous user if (!ctx.user()) { var anonMe = { 'anon': true, 'tenant': tenant }; var locale = ctx.locale(); if (locale) { anonMe.locale = locale; } return callback(null, anonMe); } // If the user is authenticated we get their profile getUser(ctx, ctx.user().id, function(err, data) { if (err) { return callback(err); } // Overwrite the `tenant` value with our object that contains whether the tenant is private data.tenant = tenant; // If this user is being impostered, we add the information of the user that is doing the impostering if (ctx.imposter()) { data.imposter = ctx.imposter(); } data.isGlobalAdmin = ctx.user().isGlobalAdmin(); data.isTenantAdmin = ctx.user().isTenantAdmin(ctx.user().tenant.alias); data.locale = ctx.user().locale; // Determine if the current user needs to accept terms and conditions data.needsToAcceptTC = PrincipalsTermsAndConditionsAPI.needsToAcceptTermsAndConditions(ctx); // Generate a signature that can be used to authenticate to one's self for push notifications data.signature = Signature.createExpiringResourceSignature(ctx, ctx.user().id); // Return the name of the strategy that the user used to log into the system data.authenticationStrategy = ctx.authenticationStrategy(); return callback(null, data); }); };