mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-30 12:24:25 +02:00
Merge pull request #9794 from overleaf/ab-endpoint-add-remove-tag-multiple-projects
[web] Handle adding/removing multiple projects from a tag at once GitOrigin-RevId: 7d052fa9930035286f8ce41433d6c3959817148a
This commit is contained in:
@@ -35,6 +35,14 @@ async function addProjectToTag(req, res) {
|
||||
res.status(204).end()
|
||||
}
|
||||
|
||||
async function addProjectsToTag(req, res) {
|
||||
const userId = SessionManager.getLoggedInUserId(req.session)
|
||||
const { tagId } = req.params
|
||||
const { projectIds } = req.body
|
||||
await TagsHandler.promises.addProjectsToTag(userId, tagId, projectIds)
|
||||
res.status(204).end()
|
||||
}
|
||||
|
||||
async function removeProjectFromTag(req, res, next) {
|
||||
const userId = SessionManager.getLoggedInUserId(req.session)
|
||||
const { tagId, projectId } = req.params
|
||||
@@ -42,6 +50,14 @@ async function removeProjectFromTag(req, res, next) {
|
||||
res.status(204).end()
|
||||
}
|
||||
|
||||
async function removeProjectsFromTag(req, res, next) {
|
||||
const userId = SessionManager.getLoggedInUserId(req.session)
|
||||
const { tagId } = req.params
|
||||
const { projectIds } = req.body
|
||||
await TagsHandler.promises.removeProjectsFromTag(userId, tagId, projectIds)
|
||||
res.status(204).end()
|
||||
}
|
||||
|
||||
async function deleteTag(req, res) {
|
||||
const userId = SessionManager.getLoggedInUserId(req.session)
|
||||
const { tagId } = req.params
|
||||
@@ -65,7 +81,9 @@ module.exports = {
|
||||
getAllTags: expressify(getAllTags),
|
||||
createTag: expressify(createTag),
|
||||
addProjectToTag: expressify(addProjectToTag),
|
||||
addProjectsToTag: expressify(addProjectsToTag),
|
||||
removeProjectFromTag: expressify(removeProjectFromTag),
|
||||
removeProjectsFromTag: expressify(removeProjectsFromTag),
|
||||
deleteTag: expressify(deleteTag),
|
||||
renameTag: expressify(renameTag),
|
||||
}
|
||||
|
||||
@@ -79,6 +79,18 @@ function removeProjectFromTag(userId, tagId, projectId, callback) {
|
||||
Tag.updateOne(searchOps, deleteOperation, callback)
|
||||
}
|
||||
|
||||
function removeProjectsFromTag(userId, tagId, projectIds, callback) {
|
||||
if (!callback) {
|
||||
callback = function () {}
|
||||
}
|
||||
const searchOps = {
|
||||
_id: tagId,
|
||||
user_id: userId,
|
||||
}
|
||||
const deleteOperation = { $pullAll: { project_ids: projectIds } }
|
||||
Tag.updateOne(searchOps, deleteOperation, callback)
|
||||
}
|
||||
|
||||
function addProjectToTag(userId, tagId, projectId, callback) {
|
||||
if (!callback) {
|
||||
callback = function () {}
|
||||
@@ -91,6 +103,18 @@ function addProjectToTag(userId, tagId, projectId, callback) {
|
||||
Tag.findOneAndUpdate(searchOps, insertOperation, callback)
|
||||
}
|
||||
|
||||
function addProjectsToTag(userId, tagId, projectIds, callback) {
|
||||
if (!callback) {
|
||||
callback = function () {}
|
||||
}
|
||||
const searchOps = {
|
||||
_id: tagId,
|
||||
user_id: userId,
|
||||
}
|
||||
const insertOperation = { $addToSet: { project_ids: { $each: projectIds } } }
|
||||
Tag.findOneAndUpdate(searchOps, insertOperation, callback)
|
||||
}
|
||||
|
||||
function addProjectToTagName(userId, name, projectId, callback) {
|
||||
if (!callback) {
|
||||
callback = function () {}
|
||||
@@ -115,8 +139,10 @@ const TagsHandler = {
|
||||
renameTag,
|
||||
deleteTag,
|
||||
updateTagUserIds,
|
||||
removeProjectFromTag,
|
||||
addProjectToTag,
|
||||
addProjectsToTag,
|
||||
removeProjectFromTag,
|
||||
removeProjectsFromTag,
|
||||
addProjectToTagName,
|
||||
removeProjectFromAllTags,
|
||||
}
|
||||
|
||||
@@ -791,6 +791,11 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||
maxRequests: 30,
|
||||
timeInterval: 60,
|
||||
}),
|
||||
validate({
|
||||
body: Joi.object({
|
||||
name: Joi.string().required(),
|
||||
}),
|
||||
}),
|
||||
TagsController.createTag
|
||||
)
|
||||
webRouter.post(
|
||||
@@ -801,6 +806,11 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||
maxRequests: 30,
|
||||
timeInterval: 60,
|
||||
}),
|
||||
validate({
|
||||
body: Joi.object({
|
||||
name: Joi.string().required(),
|
||||
}),
|
||||
}),
|
||||
TagsController.renameTag
|
||||
)
|
||||
webRouter.delete(
|
||||
@@ -823,6 +833,21 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||
}),
|
||||
TagsController.addProjectToTag
|
||||
)
|
||||
webRouter.post(
|
||||
'/tag/:tagId/projects',
|
||||
AuthenticationController.requireLogin(),
|
||||
RateLimiterMiddleware.rateLimit({
|
||||
endpointName: 'add-projects-to-tag',
|
||||
maxRequests: 30,
|
||||
timeInterval: 60,
|
||||
}),
|
||||
validate({
|
||||
body: Joi.object({
|
||||
projectIds: Joi.array().items(Joi.string()).required(),
|
||||
}),
|
||||
}),
|
||||
TagsController.addProjectsToTag
|
||||
)
|
||||
webRouter.delete(
|
||||
'/tag/:tagId/project/:projectId',
|
||||
AuthenticationController.requireLogin(),
|
||||
@@ -833,6 +858,21 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||
}),
|
||||
TagsController.removeProjectFromTag
|
||||
)
|
||||
webRouter.delete(
|
||||
'/tag/:tagId/projects',
|
||||
AuthenticationController.requireLogin(),
|
||||
RateLimiterMiddleware.rateLimit({
|
||||
endpointName: 'remove-projects-from-tag',
|
||||
maxRequests: 30,
|
||||
timeInterval: 60,
|
||||
}),
|
||||
validate({
|
||||
body: Joi.object({
|
||||
projectIds: Joi.array().items(Joi.string()).required(),
|
||||
}),
|
||||
}),
|
||||
TagsController.removeProjectsFromTag
|
||||
)
|
||||
|
||||
webRouter.get(
|
||||
'/notifications',
|
||||
|
||||
Reference in New Issue
Block a user