mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #1908 from overleaf/as-remove-tags-on-leave
Remove tags when leaving project GitOrigin-RevId: 833412264d09348b02f57fb60cd0f07d81cfc037
This commit is contained in:
committed by
sharelatex
parent
dc54a261e3
commit
0e52453931
@@ -1,87 +1,75 @@
|
||||
/* eslint-disable
|
||||
camelcase,
|
||||
handle-callback-err,
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS103: Rewrite code to no longer use __guard__
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let CollaboratorsController
|
||||
const ProjectGetter = require('../Project/ProjectGetter')
|
||||
const async = require('async')
|
||||
const CollaboratorsHandler = require('./CollaboratorsHandler')
|
||||
const ProjectEditorHandler = require('../Project/ProjectEditorHandler')
|
||||
const EditorRealTimeController = require('../Editor/EditorRealTimeController')
|
||||
const LimitationsManager = require('../Subscription/LimitationsManager')
|
||||
const UserGetter = require('../User/UserGetter')
|
||||
const EmailHelper = require('../Helpers/EmailHelper')
|
||||
const TagsHandler = require('../Tags/TagsHandler')
|
||||
const logger = require('logger-sharelatex')
|
||||
|
||||
module.exports = CollaboratorsController = {
|
||||
const CollaboratorsController = {
|
||||
removeUserFromProject(req, res, next) {
|
||||
const project_id = req.params.Project_id
|
||||
const { user_id } = req.params
|
||||
return CollaboratorsController._removeUserIdFromProject(
|
||||
project_id,
|
||||
user_id,
|
||||
const projectId = req.params.Project_id
|
||||
const userId = req.params.user_id
|
||||
CollaboratorsController._removeUserIdFromProject(
|
||||
projectId,
|
||||
userId,
|
||||
function(error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
EditorRealTimeController.emitToRoom(
|
||||
project_id,
|
||||
projectId,
|
||||
'project:membership:changed',
|
||||
{ members: true }
|
||||
)
|
||||
return res.sendStatus(204)
|
||||
res.sendStatus(204)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
removeSelfFromProject(req, res, next) {
|
||||
if (next == null) {
|
||||
next = function(error) {}
|
||||
}
|
||||
const project_id = req.params.Project_id
|
||||
const user_id = __guard__(
|
||||
req.session != null ? req.session.user : undefined,
|
||||
x => x._id
|
||||
)
|
||||
return CollaboratorsController._removeUserIdFromProject(
|
||||
project_id,
|
||||
user_id,
|
||||
const projectId = req.params.Project_id
|
||||
const userId = req.session.user ? req.session.user._id : undefined
|
||||
CollaboratorsController._removeUserIdFromProject(
|
||||
projectId,
|
||||
userId,
|
||||
function(error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return res.sendStatus(204)
|
||||
res.sendStatus(204)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
_removeUserIdFromProject(project_id, user_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
}
|
||||
return CollaboratorsHandler.removeUserFromProject(
|
||||
project_id,
|
||||
user_id,
|
||||
_removeUserIdFromProject(projectId, userId, callback) {
|
||||
async.series(
|
||||
[
|
||||
cb => {
|
||||
CollaboratorsHandler.removeUserFromProject(projectId, userId, cb)
|
||||
},
|
||||
cb => {
|
||||
EditorRealTimeController.emitToRoom(
|
||||
projectId,
|
||||
'userRemovedFromProject',
|
||||
userId
|
||||
)
|
||||
cb()
|
||||
},
|
||||
cb => {
|
||||
TagsHandler.removeProjectFromAllTags(userId, projectId, cb)
|
||||
}
|
||||
],
|
||||
function(error) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
EditorRealTimeController.emitToRoom(
|
||||
project_id,
|
||||
'userRemovedFromProject',
|
||||
user_id
|
||||
)
|
||||
return callback()
|
||||
callback()
|
||||
}
|
||||
)
|
||||
},
|
||||
@@ -89,7 +77,7 @@ module.exports = CollaboratorsController = {
|
||||
getAllMembers(req, res, next) {
|
||||
const projectId = req.params.Project_id
|
||||
logger.log({ projectId }, 'getting all active members for project')
|
||||
return CollaboratorsHandler.getAllInvitedMembers(projectId, function(
|
||||
CollaboratorsHandler.getAllInvitedMembers(projectId, function(
|
||||
err,
|
||||
members
|
||||
) {
|
||||
@@ -97,13 +85,9 @@ module.exports = CollaboratorsController = {
|
||||
logger.err({ projectId }, 'error getting members for project')
|
||||
return next(err)
|
||||
}
|
||||
return res.json({ members })
|
||||
res.json({ members })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function __guard__(value, transform) {
|
||||
return typeof value !== 'undefined' && value !== null
|
||||
? transform(value)
|
||||
: undefined
|
||||
}
|
||||
module.exports = CollaboratorsController
|
||||
|
||||
@@ -589,6 +589,10 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
|
||||
} else {
|
||||
$scope._removeProjectFromList(project)
|
||||
|
||||
for (let tag of project.tags) {
|
||||
$scope._removeProjectIdsFromTagArray(tag, [project._id])
|
||||
}
|
||||
|
||||
queuedHttp({
|
||||
method: 'POST',
|
||||
url: `/project/${project.id}/leave`,
|
||||
|
||||
@@ -26,12 +26,9 @@ describe('CollaboratorsController', function() {
|
||||
beforeEach(function() {
|
||||
this.CollaboratorsController = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'../Project/ProjectGetter': (this.ProjectGetter = {}),
|
||||
'./CollaboratorsHandler': (this.CollaboratorsHandler = {}),
|
||||
'../Editor/EditorRealTimeController': (this.EditorRealTimeController = {}),
|
||||
'../Subscription/LimitationsManager': (this.LimitationsManager = {}),
|
||||
'../Project/ProjectEditorHandler': (this.ProjectEditorHandler = {}),
|
||||
'../User/UserGetter': (this.UserGetter = {}),
|
||||
'../Tags/TagsHandler': (this.TagsHandler = {}),
|
||||
'logger-sharelatex': (this.logger = {
|
||||
err: sinon.stub(),
|
||||
erro: sinon.stub(),
|
||||
@@ -53,8 +50,9 @@ describe('CollaboratorsController', function() {
|
||||
user_id: (this.user_id = 'user-id-123')
|
||||
}
|
||||
this.res.sendStatus = sinon.stub()
|
||||
this.EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
this.CollaboratorsHandler.removeUserFromProject = sinon.stub().callsArg(2)
|
||||
this.EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
this.TagsHandler.removeProjectFromAllTags = sinon.stub().callsArg(2)
|
||||
return this.CollaboratorsController.removeUserFromProject(
|
||||
this.req,
|
||||
this.res
|
||||
@@ -89,8 +87,9 @@ describe('CollaboratorsController', function() {
|
||||
this.req.session = { user: { _id: (this.user_id = 'user-id-123') } }
|
||||
this.req.params = { Project_id: this.project_id }
|
||||
this.res.sendStatus = sinon.stub()
|
||||
this.EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
this.CollaboratorsHandler.removeUserFromProject = sinon.stub().callsArg(2)
|
||||
this.EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
this.TagsHandler.removeProjectFromAllTags = sinon.stub().callsArg(2)
|
||||
return this.CollaboratorsController.removeSelfFromProject(
|
||||
this.req,
|
||||
this.res
|
||||
@@ -109,6 +108,14 @@ describe('CollaboratorsController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should remove the project from all tags', function() {
|
||||
sinon.assert.calledWith(
|
||||
this.TagsHandler.removeProjectFromAllTags,
|
||||
this.user_id,
|
||||
this.project_id
|
||||
)
|
||||
})
|
||||
|
||||
it('should return a success code', function() {
|
||||
return this.res.sendStatus.calledWith(204).should.equal(true)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user