Преглед изворни кода

Merge pull request #23259 from overleaf/kh-rm-dead-manager-code

[web] remove unused functions to support legacy read/write link sharing

GitOrigin-RevId: 504c1eb721caa7131ed685b1e0fa5e0d0b460888
Kristina пре 1 година
родитељ
комит
229cae771e

+ 0 - 12
services/web/app/src/Features/Collaborators/CollaboratorsGetter.js

@@ -22,7 +22,6 @@ module.exports = {
     getInvitedMembersWithPrivilegeLevelsFromFields
   ),
   getMemberIdPrivilegeLevel: callbackify(getMemberIdPrivilegeLevel),
-  getInvitedCollaboratorCount: callbackify(getInvitedCollaboratorCount),
   getProjectsUserIsMemberOf: callbackify(getProjectsUserIsMemberOf),
   dangerouslyGetAllProjectsUserIsMemberOf: callbackify(
     dangerouslyGetAllProjectsUserIsMemberOf
@@ -38,7 +37,6 @@ module.exports = {
     getInvitedMembersWithPrivilegeLevels,
     getInvitedMembersWithPrivilegeLevelsFromFields,
     getMemberIdPrivilegeLevel,
-    getInvitedCollaboratorCount,
     getInvitedEditCollaboratorCount,
     getInvitedPendingEditorCount,
     getProjectsUserIsMemberOf,
@@ -126,11 +124,6 @@ async function getMemberIdPrivilegeLevel(userId, projectId) {
   return PrivilegeLevels.NONE
 }
 
-async function getInvitedCollaboratorCount(projectId) {
-  const count = await _getInvitedMemberCount(projectId)
-  return count - 1 // Don't count project owner
-}
-
 async function getInvitedEditCollaboratorCount(projectId) {
   // Only counts invited members with readAndWrite privilege
   const members = await getMemberIdsWithPrivilegeLevels(projectId)
@@ -315,11 +308,6 @@ async function userIsReadWriteTokenMember(userId, projectId) {
   return project != null
 }
 
-async function _getInvitedMemberCount(projectId) {
-  const members = await getMemberIdsWithPrivilegeLevels(projectId)
-  return members.filter(m => m.source !== Sources.TOKEN).length
-}
-
 function _getMemberIdsWithPrivilegeLevelsFromFields(
   ownerId,
   collaboratorIds,

+ 0 - 7
services/web/app/src/Features/Collaborators/CollaboratorsInviteGetter.js

@@ -15,12 +15,6 @@ async function getAllInvites(projectId) {
   return invites
 }
 
-async function getInviteCount(projectId) {
-  logger.debug({ projectId }, 'counting invites for project')
-  const count = await ProjectInvite.countDocuments({ projectId }).exec()
-  return count
-}
-
 async function getEditInviteCount(projectId) {
   logger.debug({ projectId }, 'counting edit invites for project')
   const count = await ProjectInvite.countDocuments({
@@ -48,7 +42,6 @@ async function getInviteByToken(projectId, tokenString) {
 module.exports = {
   promises: {
     getAllInvites,
-    getInviteCount,
     getEditInviteCount,
     getInviteByToken,
   },

+ 0 - 14
services/web/app/src/Features/Subscription/LimitationsManager.js

@@ -38,18 +38,6 @@ async function canAcceptEditCollaboratorInvite(projectId) {
   return currentEditors + 1 <= allowedNumber
 }
 
-async function canAddXCollaborators(projectId, numberOfNewCollaborators) {
-  const allowedNumber = await allowedNumberOfCollaboratorsInProject(projectId)
-  if (allowedNumber < 0) {
-    return true // -1 means unlimited
-  }
-  const currentNumber =
-    await CollaboratorsGetter.promises.getInvitedCollaboratorCount(projectId)
-  const inviteCount =
-    await CollaboratorsInvitesGetter.promises.getInviteCount(projectId)
-  return currentNumber + inviteCount + numberOfNewCollaborators <= allowedNumber
-}
-
 async function canAddXEditCollaborators(
   projectId,
   numberOfNewEditCollaborators
@@ -133,7 +121,6 @@ const LimitationsManager = {
   allowedNumberOfCollaboratorsForUser: callbackify(
     allowedNumberOfCollaboratorsForUser
   ),
-  canAddXCollaborators: callbackify(canAddXCollaborators),
   canAddXEditCollaborators: callbackify(canAddXEditCollaborators),
   hasPaidSubscription: callbackifyMultiResult(hasPaidSubscription, [
     'hasPaidSubscription',
@@ -162,7 +149,6 @@ const LimitationsManager = {
     allowedNumberOfCollaboratorsInProject,
     allowedNumberOfCollaboratorsForUser,
     canAcceptEditCollaboratorInvite,
-    canAddXCollaborators,
     canAddXEditCollaborators,
     hasPaidSubscription,
     userHasSubscriptionOrIsGroupMember,

+ 0 - 18
services/web/app/src/Features/TokenAccess/TokenAccessHandler.js

@@ -169,24 +169,6 @@ const TokenAccessHandler = {
     ).exec()
   },
 
-  async addReadAndWriteUserToProject(userId, projectId) {
-    userId = new ObjectId(userId.toString())
-    projectId = new ObjectId(projectId.toString())
-    Analytics.recordEventForUserInBackground(userId, 'project-joined', {
-      mode: 'read-write',
-      projectId: projectId.toString(),
-    })
-
-    return await Project.updateOne(
-      {
-        _id: projectId,
-      },
-      {
-        $addToSet: { tokenAccessReadAndWrite_refs: userId },
-      }
-    ).exec()
-  },
-
   async removeReadAndWriteUserFromProject(userId, projectId) {
     userId = new ObjectId(userId.toString())
     projectId = new ObjectId(projectId.toString())

+ 2 - 3
services/web/test/unit/src/Collaborators/CollaboratorsInviteControllerTests.mjs

@@ -59,7 +59,6 @@ describe('CollaboratorsInviteController', function () {
     this.LimitationsManager = {
       promises: {
         allowedNumberOfCollaboratorsForUser: sinon.stub(),
-        canAddXCollaborators: sinon.stub().resolves(true),
         canAddXEditCollaborators: sinon.stub().resolves(true),
       },
     }
@@ -589,8 +588,8 @@ describe('CollaboratorsInviteController', function () {
         })
       })
 
-      it('should not have called canAddXCollaborators', function () {
-        this.LimitationsManager.promises.canAddXCollaborators.callCount.should.equal(
+      it('should not have called canAddXEditCollaborators', function () {
+        this.LimitationsManager.promises.canAddXEditCollaborators.callCount.should.equal(
           0
         )
       })

+ 0 - 30
services/web/test/unit/src/Collaborators/CollaboratorsInviteGetterTests.js

@@ -63,36 +63,6 @@ describe('CollaboratorsInviteGetter', function () {
     }
   })
 
-  describe('getInviteCount', function () {
-    beforeEach(function () {
-      this.ProjectInvite.countDocuments.returns({
-        exec: sinon.stub().resolves(2),
-      })
-      this.call = async () => {
-        return await this.CollaboratorsInviteGetter.promises.getInviteCount(
-          this.projectId
-        )
-      }
-    })
-
-    it('should produce the count of documents', async function () {
-      const count = await this.call()
-      expect(count).to.equal(2)
-    })
-
-    describe('when model.countDocuments produces an error', function () {
-      beforeEach(function () {
-        this.ProjectInvite.countDocuments.returns({
-          exec: sinon.stub().rejects(new Error('woops')),
-        })
-      })
-
-      it('should produce an error', async function () {
-        await expect(this.call()).to.be.rejectedWith(Error)
-      })
-    })
-  })
-
   describe('getEditInviteCount', function () {
     beforeEach(function () {
       this.ProjectInvite.countDocuments.returns({

+ 0 - 171
services/web/test/unit/src/Subscription/LimitationsManagerTests.js

@@ -50,14 +50,12 @@ describe('LimitationsManager', function () {
 
     this.CollaboratorsGetter = {
       promises: {
-        getInvitedCollaboratorCount: sinon.stub().resolves(),
         getInvitedEditCollaboratorCount: sinon.stub().resolves(),
       },
     }
 
     this.CollaboratorsInviteGetter = {
       promises: {
-        getInviteCount: sinon.stub().resolves(),
         getEditInviteCount: sinon.stub().resolves(),
       },
     }
@@ -222,175 +220,6 @@ describe('LimitationsManager', function () {
     })
   })
 
-  describe('canAddXCollaborators', function () {
-    describe('when the project has fewer collaborators than allowed', function () {
-      beforeEach(function (done) {
-        this.current_number = 1
-        this.user.features.collaborators = 2
-        this.invite_count = 0
-        this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
-          .stub()
-          .resolves(this.current_number)
-        this.CollaboratorsInviteGetter.promises.getInviteCount = sinon
-          .stub()
-          .resolves(this.invite_count)
-        this.callback = sinon.stub().callsFake(() => done())
-        this.LimitationsManager.canAddXCollaborators(
-          this.projectId,
-          1,
-          this.callback
-        )
-      })
-
-      it('should return true', function () {
-        this.callback.calledWith(null, true).should.equal(true)
-      })
-    })
-
-    describe('when the project has fewer collaborators and invites than allowed', function () {
-      beforeEach(function (done) {
-        this.current_number = 1
-        this.user.features.collaborators = 4
-        this.invite_count = 1
-        this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
-          .stub()
-          .resolves(this.current_number)
-        this.CollaboratorsInviteGetter.promises.getInviteCount = sinon
-          .stub()
-          .resolves(this.invite_count)
-        this.callback = sinon.stub().callsFake(() => done())
-        this.LimitationsManager.canAddXCollaborators(
-          this.projectId,
-          1,
-          this.callback
-        )
-      })
-
-      it('should return true', function () {
-        this.callback.calledWith(null, true).should.equal(true)
-      })
-    })
-
-    describe('when the project has fewer collaborators than allowed but I want to add more than allowed', function () {
-      beforeEach(function (done) {
-        this.current_number = 1
-        this.user.features.collaborators = 2
-        this.invite_count = 0
-        this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
-          .stub()
-          .resolves(this.current_number)
-        this.CollaboratorsInviteGetter.promises.getInviteCount = sinon
-          .stub()
-          .resolves(this.invite_count)
-        this.callback = sinon.stub().callsFake(() => done())
-        this.LimitationsManager.canAddXCollaborators(
-          this.projectId,
-          2,
-          this.callback
-        )
-      })
-
-      it('should return false', function () {
-        this.callback.calledWith(null, false).should.equal(true)
-      })
-    })
-
-    describe('when the project has more collaborators than allowed', function () {
-      beforeEach(function (done) {
-        this.current_number = 3
-        this.user.features.collaborators = 2
-        this.invite_count = 0
-        this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
-          .stub()
-          .resolves(this.current_number)
-        this.CollaboratorsInviteGetter.promises.getInviteCount = sinon
-          .stub()
-          .resolves(this.invite_count)
-        this.callback = sinon.stub().callsFake(() => done())
-        this.LimitationsManager.canAddXCollaborators(
-          this.projectId,
-          1,
-          this.callback
-        )
-      })
-
-      it('should return false', function () {
-        this.callback.calledWith(null, false).should.equal(true)
-      })
-    })
-
-    describe('when the project has infinite collaborators', function () {
-      beforeEach(function (done) {
-        this.current_number = 100
-        this.user.features.collaborators = -1
-        this.invite_count = 0
-        this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
-          .stub()
-          .resolves(this.current_number)
-        this.CollaboratorsInviteGetter.promises.getInviteCount = sinon
-          .stub()
-          .resolves(this.invite_count)
-        this.callback = sinon.stub().callsFake(() => done())
-        this.LimitationsManager.canAddXCollaborators(
-          this.projectId,
-          1,
-          this.callback
-        )
-      })
-
-      it('should return true', function () {
-        this.callback.calledWith(null, true).should.equal(true)
-      })
-    })
-
-    describe('when the project has more invites than allowed', function () {
-      beforeEach(function (done) {
-        this.current_number = 0
-        this.user.features.collaborators = 2
-        this.invite_count = 2
-        this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
-          .stub()
-          .resolves(this.current_number)
-        this.CollaboratorsInviteGetter.promises.getInviteCount = sinon
-          .stub()
-          .resolves(this.invite_count)
-        this.callback = sinon.stub().callsFake(() => done())
-        this.LimitationsManager.canAddXCollaborators(
-          this.projectId,
-          1,
-          this.callback
-        )
-      })
-
-      it('should return false', function () {
-        this.callback.calledWith(null, false).should.equal(true)
-      })
-    })
-
-    describe('when the project has more invites and collaborators than allowed', function () {
-      beforeEach(function (done) {
-        this.current_number = 1
-        this.user.features.collaborators = 2
-        this.invite_count = 1
-        this.CollaboratorsGetter.promises.getInvitedCollaboratorCount = sinon
-          .stub()
-          .resolves(this.current_number)
-        this.CollaboratorsInviteGetter.promises.getInviteCount = sinon
-          .stub()
-          .resolves(this.invite_count)
-        this.callback = sinon.stub().callsFake(() => done())
-        this.LimitationsManager.canAddXCollaborators(
-          this.projectId,
-          1,
-          this.callback
-        )
-      })
-
-      it('should return false', function () {
-        this.callback.calledWith(null, false).should.equal(true)
-      })
-    })
-  })
   describe('canAddXEditCollaborators', function () {
     describe('when the project has fewer collaborators than allowed', function () {
       beforeEach(function (done) {

+ 0 - 1
services/web/test/unit/src/TokenAccess/TokenAccessControllerTests.mjs

@@ -44,7 +44,6 @@ describe('TokenAccessController', function () {
       makeTokenUrl: sinon.stub().returns('/'),
       grantSessionTokenAccess: sinon.stub(),
       promises: {
-        addReadAndWriteUserToProject: sinon.stub().resolves(),
         addReadOnlyUserToProject: sinon.stub().resolves(),
         getProjectByToken: sinon.stub().resolves(this.project),
         getV1DocPublishedInfo: sinon.stub().resolves({ allow: true }),

+ 0 - 48
services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js

@@ -152,54 +152,6 @@ describe('TokenAccessHandler', function () {
     })
   })
 
-  describe('addReadAndWriteUserToProject', function () {
-    beforeEach(function () {
-      this.Project.updateOne = sinon
-        .stub()
-        .returns({ exec: sinon.stub().resolves(null) })
-    })
-
-    it('should call Project.updateOne', async function () {
-      await this.TokenAccessHandler.promises.addReadAndWriteUserToProject(
-        this.userId,
-        this.projectId
-      )
-
-      expect(this.Project.updateOne.callCount).to.equal(1)
-      expect(
-        this.Project.updateOne.calledWith({
-          _id: this.projectId,
-        })
-      ).to.equal(true)
-      expect(this.Project.updateOne.lastCall.args[1].$addToSet).to.have.keys(
-        'tokenAccessReadAndWrite_refs'
-      )
-      sinon.assert.calledWith(
-        this.Analytics.recordEventForUserInBackground,
-        this.userId,
-        'project-joined',
-        { mode: 'read-write', projectId: this.projectId.toString() }
-      )
-    })
-
-    describe('when Project.updateOne produces an error', function () {
-      beforeEach(function () {
-        this.Project.updateOne = sinon
-          .stub()
-          .returns({ exec: sinon.stub().rejects(new Error('woops')) })
-      })
-
-      it('should produce an error', async function () {
-        await expect(
-          this.TokenAccessHandler.promises.addReadAndWriteUserToProject(
-            this.userId,
-            this.projectId
-          )
-        ).to.be.rejected
-      })
-    })
-  })
-
   describe('removeReadAndWriteUserFromProject', function () {
     beforeEach(function () {
       this.Project.updateOne = sinon