diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index 0d919fbd75..8db4ee9251 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -6,6 +6,7 @@ logger = require "logger-sharelatex" request = require "request" Settings = require "settings-sharelatex" AuthenticationController = require "../Authentication/AuthenticationController" +UserGetter = require "../User/UserGetter" module.exports = CompileController = compile: (req, res, next = (error) ->) -> @@ -15,13 +16,16 @@ module.exports = CompileController = logger.log "root doc overriden" if settingsOverride.rootDoc_id? AuthenticationController.getLoggedInUserId req, (error, user_id) -> return next(error) if error? - CompileManager.compile project_id, user_id, { isAutoCompile, settingsOverride }, (error, status, outputFiles) -> - return next(error) if error? - res.contentType("application/json") - res.send 200, JSON.stringify { - status: status - outputFiles: outputFiles - } + UserGetter.getUser user_id, {"features.compileGroup":1, "features.compileTimeout":1}, (err, user)-> + settingsOverride.timeout = user.features.compileTimeout + settingsOverride.compiler = user.features.compileGroup + CompileManager.compile project_id, user_id, { isAutoCompile, settingsOverride }, (error, status, outputFiles) -> + return next(error) if error? + res.contentType("application/json") + res.send 200, JSON.stringify { + status: status + outputFiles: outputFiles + } downloadPdf: (req, res, next = (error) ->)-> Metrics.inc "pdf-downloads" diff --git a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee index d75b14faf4..020d084c71 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee @@ -1,6 +1,7 @@ sinon = require('sinon') chai = require('chai') should = chai.should() +assert = require("chai").assert expect = chai.expect modulePath = "../../../../app/js/Features/Compile/CompileController.js" SandboxedModule = require('sandboxed-module') @@ -12,6 +13,8 @@ describe "CompileController", -> @CompileManager = compile: sinon.stub() @ClsiManager = {} + @UserGetter = + getUser:sinon.stub() @CompileController = SandboxedModule.require modulePath, requires: "settings-sharelatex": @settings = apis: @@ -22,9 +25,14 @@ describe "CompileController", -> "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() } "../../infrastructure/Metrics": @Metrics = { inc: sinon.stub() } "./CompileManager":@CompileManager + "../User/UserGetter":@UserGetter "./ClsiManager": @ClsiManager "../Authentication/AuthenticationController": @AuthenticationController = {} @project_id = "project-id" + @user = + features: + compileGroup: "premium" + compileTimeout: 100 @next = sinon.stub() @req = new MockRequest() @res = new MockResponse() @@ -36,6 +44,7 @@ describe "CompileController", -> Project_id: @project_id @AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id") @CompileManager.compile = sinon.stub().callsArgWith(3, null, @status = "success", @outputFiles = ["mock-output-files"]) + @UserGetter.getUser.callsArgWith(2, null, @user) @CompileController.compile @req, @res, @next it "should look up the user id", -> @@ -45,7 +54,7 @@ describe "CompileController", -> it "should do the compile without the auto compile flag", -> @CompileManager.compile - .calledWith(@project_id, @user_id, { isAutoCompile: false, settingsOverride:{} }) + .calledWith(@project_id, @user_id, { isAutoCompile: false, settingsOverride:{timeout:@user.features.compileTimeout, compiler:@user.features.compileGroup} }) .should.equal true it "should set the content-type of the response to application/json", -> @@ -60,6 +69,11 @@ describe "CompileController", -> outputFiles: @outputFiles }) + it "should get the compile timeout from the users features",-> + @UserGetter.getUser.args[0][0].should.equal @user_id + assert.deepEqual @UserGetter.getUser.args[0][1], {"features.compileGroup":1, "features.compileTimeout":1} + + describe "when an auto compile", -> beforeEach -> @req.params = @@ -68,12 +82,11 @@ describe "CompileController", -> auto_compile: "true" @AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id") @CompileManager.compile = sinon.stub().callsArgWith(3, null, @status = "success", @outputFiles = ["mock-output-files"]) + @UserGetter.getUser.callsArgWith(2, null, @user) @CompileController.compile @req, @res, @next it "should do the compile with the auto compile flag", -> - @CompileManager.compile - .calledWith(@project_id, @user_id, { isAutoCompile: true, settingsOverride:{} }) - .should.equal true + @CompileManager.compile.calledWith(@project_id, @user_id, { isAutoCompile: true, settingsOverride:{timeout:@user.features.compileTimeout, compiler:@user.features.compileGroup} }).should.equal true describe "downloadPdf", -> beforeEach ->