Commit de07e863 authored by Tomas Vik's avatar Tomas Vik Committed by Eric Eastwood

Generating context with group for the org page

- extending basic context with serialized group
- using `troupeContext.group` in the renderer instead of serializing it again
parent 16264d89
......@@ -111,7 +111,7 @@ function getRoomsWithMembership(groupId, user, currentPage) {
function renderOrgPage(req, res, next) {
return Promise.try(function() {
var group = req.group || req.uriContext.group;
var group = req.uriContext.group;
if (!group) throw new StatusError(404);
var groupId = group._id;
var user = req.user;
......@@ -120,12 +120,11 @@ function renderOrgPage(req, res, next) {
var currentPage = Math.max(parseInt(req.query.page, 10) || 1, 1);
return Promise.join(
serializeGroup(group, user),
getRoomsWithMembership(groupId, user, currentPage),
contextGenerator.generateBasicContext(req),
contextGenerator.generateOrgContext(req),
policy.canAdmin(),
generateUserThemeSnapshot(req),
function(serializedGroup, roomBrowseResult, troupeContext, isOrgAdmin, userThemeSnapshot) {
function(roomBrowseResult, troupeContext, isOrgAdmin, userThemeSnapshot) {
var isStaff = req.user && req.user.staff;
var editAccess = isOrgAdmin || isStaff;
var orgUserCount = roomBrowseResult.totalUsers;
......@@ -145,10 +144,7 @@ function renderOrgPage(req, res, next) {
return result;
});
// This is used to track pageViews in mixpanel
troupeContext.isCommunityPage = true;
var fullUrl = clientEnv.basePath + '/' + serializedGroup.homeUri;
var fullUrl = clientEnv.basePath + '/' + troupeContext.group.homeUri;
var text = encodeURIComponent('Explore our chat community on Gitter:');
var url =
'https://twitter.com/share?' +
......@@ -169,7 +165,7 @@ function renderOrgPage(req, res, next) {
orgDirectoryUrl: fullUrl,
roomCount: roomCount,
orgUserCount: orgUserCount,
group: serializedGroup,
group: troupeContext.group,
rooms: rooms,
troupeContext: troupeContext,
pagination: {
......
......@@ -58,6 +58,25 @@ function generateMainMenuContext(req, leftMenu) {
});
}
async function generateOrgContext(req) {
const { user } = req;
const { uriContext } = req;
assert(uriContext);
const { group } = uriContext;
assert(group);
const [basicContext, serializedGroup] = await Promise.all([
generateBasicContext(req),
serializeGroup(group, user)
]);
return _.extend({}, basicContext, {
group: serializedGroup,
// This is used to track pageViews in mixpanel
isCommunityPage: true
});
}
function generateBasicContext(req) {
var user = req.user;
......@@ -188,8 +207,9 @@ function serializeTroupe(troupe, user) {
}
module.exports = {
generateBasicContext: generateBasicContext,
generateMainMenuContext: generateMainMenuContext,
generateSocketContext: generateSocketContext,
generateTroupeContext: generateTroupeContext
generateBasicContext,
generateMainMenuContext,
generateSocketContext,
generateTroupeContext,
generateOrgContext
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment