mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Show front widget for paid and sampled free users
This commit is contained in:
parent
5a580b6ef9
commit
6399621d1f
3 changed files with 40 additions and 4 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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")
|
||||
window.FCSP = '#{frontChatWidgetRoomId}';
|
||||
script(src="https://chat-assets.frontapp.com/v1/chat.bundle.js")
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue