1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-17 05:37:40 +00:00

Merge branch 'sk-smarter-percentage-rollout'

This commit is contained in:
Shane Kilkelly 2017-11-13 09:24:11 +00:00
commit e63f452807
2 changed files with 90 additions and 4 deletions
services/web
app/coffee/Features/Project
test/UnitTests/coffee/Project

View file

@ -24,13 +24,16 @@ AnalyticsManager = require "../Analytics/AnalyticsManager"
Sources = require "../Authorization/Sources"
TokenAccessHandler = require '../TokenAccess/TokenAccessHandler'
CollaboratorsHandler = require '../Collaborators/CollaboratorsHandler'
crypto = require 'crypto'
module.exports = ProjectController =
_isInPercentageRollout: (objectId, percentage) ->
_isInPercentageRollout: (rolloutName, objectId, percentage) ->
if Settings.bypassPercentageRollouts == true
return true
counter = parseInt(objectId.toString().substring(18, 24), 16)
data = "#{rolloutName}:#{objectId.toString()}"
md5hash = crypto.createHash('md5').update(data).digest('hex')
counter = parseInt(md5hash.slice(26, 32), 16)
return (counter % 100) < percentage
updateProjectSettings: (req, res, next) ->
@ -274,7 +277,7 @@ module.exports = ProjectController =
timestamp = parseInt(user_id.toString().substring(0, 8), 16)
rolloutPercentage = 60 # Percentage of users to roll out to
if !ProjectController._isInPercentageRollout(user_id, rolloutPercentage)
if !ProjectController._isInPercentageRollout('autocompile', user_id, rolloutPercentage)
# Don't show if user is not part of roll out
return cb(null, { enabled: false, showOnboarding: false })
userSignupDate = new Date(timestamp * 1000)
@ -305,7 +308,11 @@ module.exports = ProjectController =
token = TokenAccessHandler.getRequestToken(req, project_id)
isTokenMember = results.isTokenMember
enableTokenAccessUI = ProjectController._isInPercentageRollout(project.owner_ref, 0)
enableTokenAccessUI = ProjectController._isInPercentageRollout(
'linksharing',
project.owner_ref,
0
)
AuthorizationManager.getPrivilegeLevelForProject user_id, project_id, token, (error, privilegeLevel)->
return next(error) if error?
if !privilegeLevel? or privilegeLevel == PrivilegeLevels.NONE

View file

@ -468,3 +468,82 @@ describe "ProjectController", ->
opts.showTrackChangesOnboarding.should.equal false
done()
@ProjectController.loadEditor @req, @res
describe '_isInPercentageRollout', ->
before ->
@ids = [
'5a05cd7621f9fe22be131740',
'5a05cd7821f9fe22be131741',
'5a05cd7921f9fe22be131742',
'5a05cd7a21f9fe22be131743',
'5a05cd7b21f9fe22be131744',
'5a05cd7c21f9fe22be131745',
'5a05cd7d21f9fe22be131746',
'5a05cd7e21f9fe22be131747',
'5a05cd7f21f9fe22be131748',
'5a05cd8021f9fe22be131749',
'5a05cd8021f9fe22be13174a',
'5a05cd8121f9fe22be13174b',
'5a05cd8221f9fe22be13174c',
'5a05cd8221f9fe22be13174d',
'5a05cd8321f9fe22be13174e',
'5a05cd8321f9fe22be13174f',
'5a05cd8421f9fe22be131750',
'5a05cd8421f9fe22be131751',
'5a05cd8421f9fe22be131752',
'5a05cd8521f9fe22be131753'
]
it 'should produce the expected results', ->
expect(
@ids.map (i) =>
@ProjectController._isInPercentageRollout('abcd', i, 50)
).to.deep.equal [
false,
false,
false,
false,
false,
false,
true,
false,
true,
true,
true,
true,
true,
true,
false,
false,
false,
true,
false,
true
]
expect(
@ids.map (i) =>
@ProjectController._isInPercentageRollout('efgh', i, 50)
).to.deep.equal [
false,
false,
false,
false,
true,
false,
false,
true,
false,
false,
true,
true,
true,
false,
true,
false,
true,
true,
false,
false
]