diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 77aabd8524..c33e62d12d 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -157,7 +157,7 @@ module.exports = ProjectController = hasSubscription: (cb)-> LimitationsManager.userHasSubscriptionOrIsGroupMember currentUser, cb user: (cb) -> - User.findById user_id, "featureSwitches overleaf awareOfV2", cb + User.findById user_id, "featureSwitches overleaf awareOfV2 features", cb }, (err, results)-> if err? logger.err err:err, "error getting data for project list page" @@ -172,6 +172,7 @@ module.exports = ProjectController = user = results.user warnings = ProjectController._buildWarningsList results.v1Projects + ProjectController._injectProjectOwners projects, (error, projects) -> return next(error) if error? viewModel = { @@ -193,6 +194,14 @@ module.exports = ProjectController = else viewModel.showUserDetailsArea = false + paidUser = user.features?.github # use a heuristic for paid account + freeUserProportion = 0.85 + sampleFreeUser = parseInt(user._id.toString().slice(-2), 16) < freeUserProportion * 255 + showFrontWidget = paidUser or sampleFreeUser + logger.log {paidUser, sampleFreeUser, showFrontWidget}, 'deciding whether to show front widget' + if showFrontWidget + viewModel.frontChatWidgetRoomId = Settings.overleaf?.front_chat_widget_room_id + res.render 'project/list', viewModel timer.done() diff --git a/services/web/app/views/project/list/front-chat.pug b/services/web/app/views/project/list/front-chat.pug index 7f0939de29..7e1c9a7123 100644 --- a/services/web/app/views/project/list/front-chat.pug +++ b/services/web/app/views/project/list/front-chat.pug @@ -1,4 +1,4 @@ -- if (settings.overleaf && settings.overleaf.front_chat_widget_room_id != null) +- if (frontChatWidgetRoomId) script. - window.FCSP = '#{settings.overleaf.front_chat_widget_room_id}'; - script(src="https://chat-assets.frontapp.com/v1/chat.bundle.js") \ No newline at end of file + window.FCSP = '#{frontChatWidgetRoomId}'; + script(src="https://chat-assets.frontapp.com/v1/chat.bundle.js") diff --git a/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee b/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee index 4e1402429b..65ca033cab 100644 --- a/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee @@ -15,6 +15,7 @@ describe "ProjectController", -> @user = _id:"588f3ddae8ebc1bac07c9fa4" first_name: "bjkdsjfk" + features: {} @settings = apis: chat: @@ -300,6 +301,32 @@ describe "ProjectController", -> done() @ProjectController.projectListPage @req, @res + describe 'front widget', (done) -> + beforeEach -> + @settings.overleaf = + front_chat_widget_room_id: 'chat-room-id' + + it 'should show for paid users', (done) -> + @user.features.github = true + @res.render = (pageName, opts)=> + opts.frontChatWidgetRoomId.should.equal @settings.overleaf.front_chat_widget_room_id + done() + @ProjectController.projectListPage @req, @res + + it 'should show for sample users', (done) -> + @user._id = '588f3ddae8ebc1bac07c9faa' # last two digits + @res.render = (pageName, opts)=> + opts.frontChatWidgetRoomId.should.equal @settings.overleaf.front_chat_widget_room_id + done() + @ProjectController.projectListPage @req, @res + + it 'should not show for non sample users', (done) -> + @user._id = '588f3ddae8ebc1bac07c9fff' # last two digits + @res.render = (pageName, opts)=> + expect(opts.frontChatWidgetRoomId).to.equal undefined + done() + @ProjectController.projectListPage @req, @res + describe 'with overleaf-integration-web-module hook', -> beforeEach -> @V1Response =