Exemplo n.º 1
0
var _transformGroupDocuments = function(ctx, docs, callback) {
    var transformedDocs = {};
    var docIds = _.keys(docs);
    for (var i = 0; i < docIds.length; i++) {
        var docId = docIds[i];
        var doc = docs[docId];
        var result = _.extend({}, doc.fields, {'id': doc['_id']});

        // Augment it with a downloadable thumbnail url if it has a thumbnail uri.
        // The thumbnail should not be hidden, even if the group is private.
        if (doc.fields.thumbnailUrl) {
            result.thumbnailUrl = PrincipalsUtil.getSignedPictureUrl(ctx, ctx.tenant().alias, doc.fields.thumbnailUrl);
        }

        if (doc.fields._extra && doc.fields._extra.alias) {
            result.alias = doc.fields._extra.alias;
        }

        // Attach the group tenant information
        result.tenant = TenantsAPI.getCachedTenantByAlias(result.tenantAlias);

        transformedDocs[docId] = result;
    }

    return callback(null, transformedDocs);
};
Exemplo n.º 2
0
var _transformUserDocuments = function(ctx, docs, callback) {
    var transformedDocs = {};
    var docIds = _.keys(docs);
    for (var i = 0; i < docIds.length; i++) {
        var docId = docIds[i];
        var doc = docs[docId];
        var fields = doc.fields;

        // First we need to convert the data in this document back into the source user object so that we may use PrincipalsUtil.hideUserData
        // to hide its information. We will then after convert the user *back* to a search document once the user information has been
        // scrubbed.
        var user = new User(fields.tenantAlias, docId, fields.displayName, {
            'visibility': fields.visibility,
            'publicAlias': fields._extra.publicAlias,
            'mediumPictureUri': fields.thumbnailUrl
        });
        user.extra = fields._extra.userExtra;

        // Hide information that is sensitive to the current session
        PrincipalsUtil.hideUserData(ctx, user);

        // Convert the user object back to a search document using the producer. We use this simply to re-use the logic of turning a user
        // object into a search document.
        var result = _produceUserSearchDocument(user);
        result.profilePath = user.profilePath;

        // Attach the compact tenant object on the search result.
        result.tenant = user.tenant;

        // The UI search model expects the 'extra' parameter if it was not scrubbed
        if (user.extra) {
            result.extra = user.extra;
        }

        // If the mediumPictureUri wasn't scrubbed from the user object that means the current user can see it.
        // Generate a downloadable url for it.
        if (user.picture.mediumUri) {
            result.thumbnailUrl = PrincipalsUtil.getSignedPictureUrl(ctx, user.picture.mediumUri);
        }

        // We need to delete these fields which are added by the producer but aren't supposed to be included in the UI.
        delete result.q_high;
        delete result.sort;

        transformedDocs[docId] = result;
    }

    return callback(null, transformedDocs);
};