mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Update add tag end point to use tag_id
This commit is contained in:
parent
f1e65cc776
commit
77cc6af35e
6 changed files with 57 additions and 36 deletions
|
@ -2,19 +2,18 @@ TagsHandler = require("./TagsHandler")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
processTagsUpdate: (req, res)->
|
|
||||||
user_id = req.session.user._id
|
|
||||||
project_id = req.params.project_id
|
|
||||||
tag = req.body.tag
|
|
||||||
TagsHandler.addTag user_id, project_id, tag, ->
|
|
||||||
res.send()
|
|
||||||
logger.log user_id:user_id, project_id:project_id, body:req.body, "processing tag update"
|
|
||||||
|
|
||||||
getAllTags: (req, res)->
|
getAllTags: (req, res)->
|
||||||
TagsHandler.getAllTags req.session.user._id, (err, allTags)->
|
TagsHandler.getAllTags req.session.user._id, (err, allTags)->
|
||||||
res.send(allTags)
|
res.send(allTags)
|
||||||
|
|
||||||
|
addProjectToTag: (req, res, next) ->
|
||||||
|
user_id = req.session.user._id
|
||||||
|
{tag_id, project_id} = req.params
|
||||||
|
logger.log {user_id, tag_id, project_id}, "adding tag to project"
|
||||||
|
TagsHandler.addProjectToTag user_id, tag_id, project_id, (error) ->
|
||||||
|
return next(error) if error?
|
||||||
|
res.status(204).end()
|
||||||
|
|
||||||
removeProjectFromTag: (req, res, next) ->
|
removeProjectFromTag: (req, res, next) ->
|
||||||
user_id = req.session.user._id
|
user_id = req.session.user._id
|
||||||
{tag_id, project_id} = req.params
|
{tag_id, project_id} = req.params
|
||||||
|
|
|
@ -38,15 +38,10 @@ module.exports = TagsHandler =
|
||||||
request.del {url, timeout: TIMEOUT}, (err, res, body) ->
|
request.del {url, timeout: TIMEOUT}, (err, res, body) ->
|
||||||
TagsHandler._handleResponse res, {url, user_id, tag_id, project_id}, callback
|
TagsHandler._handleResponse res, {url, user_id, tag_id, project_id}, callback
|
||||||
|
|
||||||
addTag: (user_id, project_id, tag, callback)->
|
addProjectToTag: (user_id, tag_id, project_id, callback)->
|
||||||
uri = buildUri(user_id, project_id)
|
url = "#{settings.apis.tags.url}/user/#{user_id}/tag/#{tag_id}/project/#{project_id}"
|
||||||
opts =
|
request.post {url, timeout: TIMEOUT}, (err, res, body) ->
|
||||||
uri:uri
|
TagsHandler._handleResponse res, {url, user_id, tag_id, project_id}, callback
|
||||||
json:
|
|
||||||
name:tag
|
|
||||||
timeout: TIMEOUT
|
|
||||||
logger.log user_id:user_id, project_id:project_id, tag:tag, "send add tag to tags api"
|
|
||||||
request.post opts, callback
|
|
||||||
|
|
||||||
requestTags: (user_id, callback)->
|
requestTags: (user_id, callback)->
|
||||||
opts =
|
opts =
|
||||||
|
|
|
@ -132,7 +132,7 @@ module.exports = class Router
|
||||||
webRouter.get '/project/download/zip', SecurityManager.requestCanAccessMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
webRouter.get '/project/download/zip', SecurityManager.requestCanAccessMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
||||||
|
|
||||||
webRouter.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags
|
webRouter.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags
|
||||||
webRouter.post '/project/:project_id/tag', AuthenticationController.requireLogin(), TagsController.processTagsUpdate
|
webRouter.post '/tag/:tag_id/project/:project_id', AuthenticationController.requireLogin(), TagsController.addProjectToTag
|
||||||
webRouter.delete '/tag/:tag_id/project/:project_id', AuthenticationController.requireLogin(), TagsController.removeProjectFromTag
|
webRouter.delete '/tag/:tag_id/project/:project_id', AuthenticationController.requireLogin(), TagsController.removeProjectFromTag
|
||||||
webRouter.delete '/tag/:tag_id', AuthenticationController.requireLogin(), TagsController.deleteTag
|
webRouter.delete '/tag/:tag_id', AuthenticationController.requireLogin(), TagsController.deleteTag
|
||||||
webRouter.post '/tag/:tag_id/rename', AuthenticationController.requireLogin(), TagsController.renameTag
|
webRouter.post '/tag/:tag_id/rename', AuthenticationController.requireLogin(), TagsController.renameTag
|
||||||
|
|
|
@ -198,8 +198,7 @@ define [
|
||||||
project.tags.push tag
|
project.tags.push tag
|
||||||
|
|
||||||
for project_id in added_project_ids
|
for project_id in added_project_ids
|
||||||
queuedHttp.post "/project/#{project_id}/tag", {
|
queuedHttp.post "/tag/#{tag._id}/project/#{project_id}", {
|
||||||
tag: tag.name
|
|
||||||
_csrf: window.csrfToken
|
_csrf: window.csrfToken
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@ sinon = require('sinon')
|
||||||
modulePath = require('path').join __dirname, '../../../../app/js/Features/Tags/TagsController.js'
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/Tags/TagsController.js'
|
||||||
|
|
||||||
|
|
||||||
describe 'Tags controller', ->
|
describe 'TagsController', ->
|
||||||
user_id = "123nd3ijdks"
|
user_id = "123nd3ijdks"
|
||||||
project_id = "123njdskj9jlk"
|
project_id = "123njdskj9jlk"
|
||||||
tag = "some_class101"
|
tag = "some_class101"
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@handler =
|
@handler =
|
||||||
addTag: sinon.stub().callsArgWith(3)
|
addProjectToTag: sinon.stub().callsArgWith(3)
|
||||||
removeProjectFromTag: sinon.stub().callsArgWith(3)
|
removeProjectFromTag: sinon.stub().callsArgWith(3)
|
||||||
deleteTag: sinon.stub().callsArg(2)
|
deleteTag: sinon.stub().callsArg(2)
|
||||||
renameTag: sinon.stub().callsArg(3)
|
renameTag: sinon.stub().callsArg(3)
|
||||||
|
@ -32,13 +32,6 @@ describe 'Tags controller', ->
|
||||||
@res.status = sinon.stub().returns @res
|
@res.status = sinon.stub().returns @res
|
||||||
@res.end = sinon.stub()
|
@res.end = sinon.stub()
|
||||||
|
|
||||||
describe "processTagsUpdate", ->
|
|
||||||
it 'Should post the request to the tags api with the user id in the url', (done)->
|
|
||||||
@req.body = {tag:tag}
|
|
||||||
@controller.processTagsUpdate @req, send:=>
|
|
||||||
@handler.addTag.calledWith(user_id, project_id, tag).should.equal true
|
|
||||||
done()
|
|
||||||
|
|
||||||
describe "getAllTags", ->
|
describe "getAllTags", ->
|
||||||
it 'should ask the handler for all tags', (done)->
|
it 'should ask the handler for all tags', (done)->
|
||||||
allTags = [{name:"tag", projects:["123423","423423"]}]
|
allTags = [{name:"tag", projects:["123423","423423"]}]
|
||||||
|
@ -93,6 +86,22 @@ describe 'Tags controller', ->
|
||||||
@res.status.calledWith(400).should.equal true
|
@res.status.calledWith(400).should.equal true
|
||||||
@res.end.called.should.equal true
|
@res.end.called.should.equal true
|
||||||
|
|
||||||
|
describe "addProjectToTag", ->
|
||||||
|
beforeEach ->
|
||||||
|
@req.params.tag_id = @tag_id = "tag-id-123"
|
||||||
|
@req.params.project_id = @project_id = "project-id-123"
|
||||||
|
@req.session.user._id = @user_id = "user-id-123"
|
||||||
|
@controller.addProjectToTag @req, @res
|
||||||
|
|
||||||
|
it "should add the tag to the project in the backend", ->
|
||||||
|
@handler.addProjectToTag
|
||||||
|
.calledWith(@user_id, @tag_id, @project_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should return 204 status code", ->
|
||||||
|
@res.status.calledWith(204).should.equal true
|
||||||
|
@res.end.called.should.equal true
|
||||||
|
|
||||||
describe "removeProjectFromTag", ->
|
describe "removeProjectFromTag", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.params.tag_id = @tag_id = "tag-id-123"
|
@req.params.tag_id = @tag_id = "tag-id-123"
|
||||||
|
|
|
@ -26,12 +26,6 @@ describe 'TagsHandler', ->
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
|
|
||||||
describe "addTag", ->
|
|
||||||
it 'Should post the request to the tags api with the user id in the url', (done)->
|
|
||||||
@handler.addTag user_id, project_id, tag, =>
|
|
||||||
@request.post.calledWith({uri:"#{tagsUrl}/user/#{user_id}/project/#{project_id}/tag", timeout:1000, json:{name:tag}}).should.equal true
|
|
||||||
done()
|
|
||||||
|
|
||||||
describe "removeProjectFromAllTags", ->
|
describe "removeProjectFromAllTags", ->
|
||||||
it 'should tell the tags api to remove the project_id from all the users tags', (done)->
|
it 'should tell the tags api to remove the project_id from all the users tags', (done)->
|
||||||
@handler.removeProjectFromAllTags user_id, project_id, =>
|
@handler.removeProjectFromAllTags user_id, project_id, =>
|
||||||
|
@ -175,3 +169,28 @@ describe 'TagsHandler', ->
|
||||||
|
|
||||||
it "should call the callback with an Error", ->
|
it "should call the callback with an Error", ->
|
||||||
@callback.calledWith(new Error()).should.equal true
|
@callback.calledWith(new Error()).should.equal true
|
||||||
|
|
||||||
|
describe "addProjectToTag", ->
|
||||||
|
describe "successfully", ->
|
||||||
|
beforeEach ->
|
||||||
|
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, "")
|
||||||
|
@handler.addProjectToTag user_id, tag_id, project_id, @callback
|
||||||
|
|
||||||
|
it "should send a request to the tag backend", ->
|
||||||
|
@request.post
|
||||||
|
.calledWith({
|
||||||
|
url: "#{tagsUrl}/user/#{user_id}/tag/#{tag_id}/project/#{project_id}"
|
||||||
|
timeout: 1000
|
||||||
|
})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should call the callback with no error", ->
|
||||||
|
@callback.calledWith(null).should.equal true
|
||||||
|
|
||||||
|
describe "with error", ->
|
||||||
|
beforeEach ->
|
||||||
|
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 500}, "")
|
||||||
|
@handler.addProjectToTag user_id, tag_id, project_id, @callback
|
||||||
|
|
||||||
|
it "should call the callback with an Error", ->
|
||||||
|
@callback.calledWith(new Error()).should.equal true
|
Loading…
Reference in a new issue