|
|
@@ -21,6 +21,17 @@ module.exports = HistoryController =
|
|
|
req.useProjectHistory = false
|
|
|
next()
|
|
|
|
|
|
+ ensureProjectHistoryEnabled: (req, res, next) ->
|
|
|
+ {project_id} = req.params
|
|
|
+ ProjectDetailsHandler.getDetails project_id, (err, project) ->
|
|
|
+ return next(err) if err?
|
|
|
+ historyEnabled = project.overleaf?.history?.id?
|
|
|
+ if historyEnabled
|
|
|
+ next()
|
|
|
+ else
|
|
|
+ logger.log {project_id}, "project history not enabled"
|
|
|
+ res.sendStatus(404)
|
|
|
+
|
|
|
proxyToHistoryApi: (req, res, next = (error) ->) ->
|
|
|
user_id = AuthenticationController.getLoggedInUserId req
|
|
|
url = HistoryController.buildHistoryServiceUrl(req.useProjectHistory) + req.url
|
|
|
@@ -98,3 +109,48 @@ module.exports = HistoryController =
|
|
|
doc_id: doc._id
|
|
|
}
|
|
|
|
|
|
+ getLabels: (req, res, next) ->
|
|
|
+ {project_id} = req.params
|
|
|
+ user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
+ request.get {
|
|
|
+ url: "#{settings.apis.project_history.url}/project/#{project_id}/labels"
|
|
|
+ json: true
|
|
|
+ }, (error, response, body) ->
|
|
|
+ return next(error) if error?
|
|
|
+ if 200 <= response.statusCode < 300
|
|
|
+ res.json body
|
|
|
+ else
|
|
|
+ error = new Error("history api responded with non-success code: #{response.statusCode}")
|
|
|
+ logger.error err: error, user_id: user_id, "error getting labels from project-history"
|
|
|
+ next(error)
|
|
|
+
|
|
|
+ createLabel: (req, res, next) ->
|
|
|
+ {project_id} = req.params
|
|
|
+ {comment, version} = req.body
|
|
|
+ user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
+ request.post {
|
|
|
+ url: "#{settings.apis.project_history.url}/project/#{project_id}/user/#{user_id}/labels"
|
|
|
+ json: {comment, version}
|
|
|
+ }, (error, response, body) ->
|
|
|
+ return next(error) if error?
|
|
|
+ if 200 <= response.statusCode < 300
|
|
|
+ res.json body
|
|
|
+ else
|
|
|
+ error = new Error("history api responded with non-success code: #{response.statusCode}")
|
|
|
+ logger.error err: error, user_id: user_id, "error creating label in project-history"
|
|
|
+ next(error)
|
|
|
+
|
|
|
+ deleteLabel: (req, res, next) ->
|
|
|
+ {project_id, label_id} = req.params
|
|
|
+ user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
+ console.log "hof-debug DEL #{settings.apis.project_history.url}/project/#{project_id}/user/#{user_id}/labels/#{label_id}"
|
|
|
+ request.del {
|
|
|
+ url: "#{settings.apis.project_history.url}/project/#{project_id}/user/#{user_id}/labels/#{label_id}"
|
|
|
+ }, (error, response, body) ->
|
|
|
+ return next(error) if error?
|
|
|
+ if 200 <= response.statusCode < 300
|
|
|
+ res.sendStatus 204
|
|
|
+ else
|
|
|
+ error = new Error("history api responded with non-success code: #{response.statusCode}")
|
|
|
+ logger.error err: error, user_id: user_id, "error deleting label in project-history"
|
|
|
+ next(error)
|