From 87352610225949792dd400d5f0fefd1694886c94 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Wed, 1 Nov 2017 14:01:06 +0000 Subject: [PATCH] Extract V1 projects fetch to integration module OlProjectGetter now just detects if integration module is loaded and proxies to integration module. If module not loaded, it just bails --- .../Features/Project/OlProjectGetter.coffee | 36 +++++++++---------- .../Features/Project/ProjectController.coffee | 5 +-- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/services/web/app/coffee/Features/Project/OlProjectGetter.coffee b/services/web/app/coffee/Features/Project/OlProjectGetter.coffee index 3f47c0dac4..ab3187a636 100644 --- a/services/web/app/coffee/Features/Project/OlProjectGetter.coffee +++ b/services/web/app/coffee/Features/Project/OlProjectGetter.coffee @@ -1,24 +1,22 @@ -request = require 'request' -settings = require 'settings-sharelatex' +fs = require 'fs' +path = require 'path' logger = require 'logger-sharelatex' -Errors = require '../Errors/Errors' -oAuthRequest = require '../../../../modules/overleaf-integration-web-module/app/coffee/oauth/OAuthRequest' -makeRequest = (opts, callback) -> - if settings.apis?.olProjects?.url? - urlPath = opts.url - opts.url = "#{settings.apis.olProjects.url}#{urlPath}" - request opts, callback - else - callback(new Errors.ServiceNotConfiguredError('OL Projects service not configured')) +INTEGRATION_MODULE_PATH = path.resolve(__dirname, '../../../../modules/overleaf-integration-web-module') module.exports = OlProjectGetter = + integrationModuleExists: (callback = (error, stats) ->) -> + fs.stat INTEGRATION_MODULE_PATH, (error, stats) -> + if error? or !stats.isDirectory() + return callback(false) + return callback(true) + findAllUsersProjects: (userId, callback = (error, projects) ->) -> - oAuthRequest userId, { - url: "#{settings.overleaf.host}/api/v1/sharelatex/docs" - method: 'GET' - json: true - }, (error, docs) -> - return callback(error) if error? - logger.log {userId, docs}, "got projects from OL" - callback(null, docs) \ No newline at end of file + OlProjectGetter.integrationModuleExists (exists) -> + if exists + logger.log {exists}, "integration module does exist, loading V1 projects" + V1ProjectListGetter = require(path.join(INTEGRATION_MODULE_PATH, 'app/coffee/ProjectList/ProjectListGetter')) + V1ProjectListGetter.findAllUsersProjects(userId, callback) + else + logger.log {exists}, "integration modules doesn't exists, not loading V1 projects" + return callback() diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 2aeddd1ab6..e067d7f9e7 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -153,10 +153,7 @@ module.exports = ProjectController = projects: (cb)-> ProjectGetter.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref tokens', cb v1Projects: (cb) -> - if isV1 - OlProjectGetter.findAllUsersProjects user_id, cb - else - cb() + OlProjectGetter.findAllUsersProjects user_id, cb hasSubscription: (cb)-> LimitationsManager.userHasSubscriptionOrIsGroupMember currentUser, cb user: (cb) ->