mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Remove expiresAt
, use mongo TTL instead.
This commit is contained in:
parent
b201f1a37a
commit
9e0c44573a
5 changed files with 12 additions and 35 deletions
|
@ -47,7 +47,7 @@ module.exports = CollaboratorsInviteController =
|
|||
if err?
|
||||
logger.err {projectId, token}, "error getting invite by token"
|
||||
return next(err)
|
||||
# TODO: should we render an expired view instead?
|
||||
# TODO: render a not-valid view instead
|
||||
if !invite
|
||||
logger.log {projectId, token}, "no invite found for token"
|
||||
return res.sendStatus(404)
|
||||
|
|
|
@ -47,13 +47,7 @@ module.exports = CollaboratorsInviteHandler =
|
|||
logger.err {err, projectId}, "error fetching invite"
|
||||
return callback(err)
|
||||
if !invite
|
||||
err = new Errors.NotFoundError("no invite found for token")
|
||||
logger.err {err, projectId, token: tokenString}, "no invite found"
|
||||
return callback(err)
|
||||
now = new Date()
|
||||
# TODO: re-assess whether we should return null or a notfounderror
|
||||
if invite.expiresAt < now
|
||||
logger.log {projectId, inviteId: invite._id, expiresAt: invite.expiresAt}, "invite expired"
|
||||
return callback(null, null)
|
||||
callback(null, invite)
|
||||
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
mongoose = require 'mongoose'
|
||||
Settings = require 'settings-sharelatex'
|
||||
|
||||
|
||||
Schema = mongoose.Schema
|
||||
ObjectId = Schema.ObjectId
|
||||
|
||||
THIRTY_DAYS_IN_SECONDS = 60 * 60 * 24 * 30
|
||||
|
||||
makeExpirationDate = () ->
|
||||
nowInMillis = Date.now()
|
||||
new Date(nowInMillis + (1000 * THIRTY_DAYS_IN_SECONDS))
|
||||
THIRTY_DAYS_IN_SECONDS = 60 * 60 * 24 * 30
|
||||
|
||||
|
||||
ProjectInviteSchema = new Schema
|
||||
|
@ -17,13 +15,15 @@ ProjectInviteSchema = new Schema
|
|||
sendingUserId: ObjectId
|
||||
projectId: ObjectId
|
||||
privileges: String
|
||||
createdAt: {type: Date, default: Date.now}
|
||||
expiresAt: {type: Date, default: makeExpirationDate}
|
||||
createdAt: {type: Date, default: Date.now, index: {expiresAfterSeconds: THIRTY_DAYS_IN_SECONDS}}
|
||||
|
||||
|
||||
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10)
|
||||
|
||||
|
||||
ProjectInvite = conn.model('ProjectInvite', ProjectInviteSchema)
|
||||
|
||||
|
||||
mongoose.model 'ProjectInvite', ProjectInviteSchema
|
||||
exports.ProjectInvite = ProjectInvite
|
||||
exports.ProjectInviteSchema = ProjectInviteSchema
|
||||
|
|
|
@ -45,7 +45,6 @@ describe "CollaboratorsInviteController", ->
|
|||
projectId: @targetEmail,
|
||||
targetEmail: 'user@example.com'
|
||||
createdAt: new Date(),
|
||||
expiresAt: new Date()
|
||||
}
|
||||
@LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, null, true)
|
||||
@CollaboratorsInviteHandler.inviteToProject = sinon.stub().callsArgWith(4, null, @invite)
|
||||
|
@ -133,7 +132,6 @@ describe "CollaboratorsInviteController", ->
|
|||
projectId: @projectId,
|
||||
targetEmail: 'user@example.com'
|
||||
createdAt: new Date(),
|
||||
expiresAt: new Date()
|
||||
}
|
||||
@CollaboratorsInviteHandler.getInviteByToken = sinon.stub().callsArgWith(2, null, @invite)
|
||||
@callback = sinon.stub()
|
||||
|
|
|
@ -130,8 +130,6 @@ describe "CollaboratorsInviteHandler", ->
|
|||
describe 'getInviteByToken', ->
|
||||
|
||||
beforeEach ->
|
||||
@theDarkFuture = new Date()
|
||||
@theDarkFuture.setYear(40000)
|
||||
@fakeInvite =
|
||||
_id: @inviteId
|
||||
email: @email
|
||||
|
@ -140,7 +138,6 @@ describe "CollaboratorsInviteHandler", ->
|
|||
projectId: @projectId
|
||||
privileges: @privileges
|
||||
createdAt: new Date()
|
||||
expiresAt: @theDarkFuture
|
||||
@ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
||||
@call = (callback) =>
|
||||
@CollaboratorsInviteHandler.getInviteByToken @projectId, @token, callback
|
||||
|
@ -150,7 +147,7 @@ describe "CollaboratorsInviteHandler", ->
|
|||
beforeEach ->
|
||||
|
||||
it 'should not produce an error', (done) ->
|
||||
@call (err) =>
|
||||
@call (err, invite) =>
|
||||
expect(err).to.not.be.instanceof Error
|
||||
expect(err).to.be.oneOf [null, undefined]
|
||||
done()
|
||||
|
@ -161,7 +158,7 @@ describe "CollaboratorsInviteHandler", ->
|
|||
done()
|
||||
|
||||
it 'should call ProjectInvite.findOne', (done) ->
|
||||
@call (err) =>
|
||||
@call (err, invite) =>
|
||||
@ProjectInvite.findOne.callCount.should.equal 1
|
||||
@ProjectInvite.findOne.calledWith({projectId: @projectId, token: @token}).should.equal true
|
||||
done()
|
||||
|
@ -172,7 +169,7 @@ describe "CollaboratorsInviteHandler", ->
|
|||
@ProjectInvite.findOne.callsArgWith(1, new Error('woops'))
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
@call (err) =>
|
||||
@call (err, invite) =>
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
|
||||
|
@ -181,26 +178,14 @@ describe "CollaboratorsInviteHandler", ->
|
|||
beforeEach ->
|
||||
@ProjectInvite.findOne.callsArgWith(1, null, null)
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
@call (err) =>
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
|
||||
describe 'when the invite is expired', ->
|
||||
|
||||
beforeEach ->
|
||||
@theDeepPast = new Date()
|
||||
@theDeepPast.setYear(1977)
|
||||
@fakeInvite.expiresAt = @theDeepPast
|
||||
@ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
||||
|
||||
it 'should not produce an error', (done) ->
|
||||
@call (err) =>
|
||||
@call (err, invite) =>
|
||||
expect(err).to.not.be.instanceof Error
|
||||
expect(err).to.be.oneOf [null, undefined]
|
||||
done()
|
||||
|
||||
it 'should not produce an invite object', (done) ->
|
||||
@call (err, invite) =>
|
||||
expect(invite).to.not.be.instanceof Error
|
||||
expect(invite).to.be.oneOf [null, undefined]
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue