mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge branch 'github-sync'
Conflicts: package.json
This commit is contained in:
commit
128c672edd
19 changed files with 268 additions and 41 deletions
2
services/web/.gitignore
vendored
2
services/web/.gitignore
vendored
|
@ -67,3 +67,5 @@ Gemfile.lock
|
|||
.DS_Store
|
||||
|
||||
app/views/external
|
||||
|
||||
modules
|
||||
|
|
|
@ -10,7 +10,7 @@ module.exports = (grunt) ->
|
|||
grunt.loadNpmTasks 'grunt-execute'
|
||||
grunt.loadNpmTasks 'grunt-bunyan'
|
||||
|
||||
grunt.initConfig
|
||||
config =
|
||||
execute:
|
||||
app:
|
||||
src: "app.js"
|
||||
|
@ -28,10 +28,6 @@ module.exports = (grunt) ->
|
|||
src: 'app.coffee'
|
||||
dest: 'app.js'
|
||||
|
||||
BackgroundJobsWorker:
|
||||
src: 'BackgroundJobsWorker.coffee'
|
||||
dest: 'BackgroundJobsWorker.js'
|
||||
|
||||
sharejs:
|
||||
options:
|
||||
join: true
|
||||
|
@ -163,6 +159,75 @@ module.exports = (grunt) ->
|
|||
"help"
|
||||
]
|
||||
|
||||
moduleCompileServerTasks = []
|
||||
moduleCompileUnitTestTasks = []
|
||||
moduleUnitTestTasks = []
|
||||
moduleCompileClientTasks = []
|
||||
moduleIdeClientSideIncludes = []
|
||||
moduleMainClientSideIncludes = []
|
||||
if fs.existsSync "./modules"
|
||||
for module in fs.readdirSync "./modules"
|
||||
if fs.existsSync "./modules/#{module}/index.coffee"
|
||||
config.coffee["module_#{module}_server"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/app/coffee",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "modules/#{module}/app/js",
|
||||
ext: '.js'
|
||||
}
|
||||
config.coffee["module_#{module}_index"] = {
|
||||
src: "modules/#{module}/index.coffee",
|
||||
dest: "modules/#{module}/index.js"
|
||||
}
|
||||
|
||||
moduleCompileServerTasks.push "coffee:module_#{module}_server"
|
||||
moduleCompileServerTasks.push "coffee:module_#{module}_index"
|
||||
|
||||
config.coffee["module_#{module}_unit_tests"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/test/unit/coffee",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "modules/#{module}/test/unit/js",
|
||||
ext: '.js'
|
||||
}
|
||||
config.mochaTest["module_#{module}_unit"] = {
|
||||
src: ["modules/#{module}/test/unit/js/*.js"]
|
||||
options:
|
||||
reporter: grunt.option('reporter') or 'spec'
|
||||
grep: grunt.option("grep")
|
||||
}
|
||||
|
||||
moduleCompileUnitTestTasks.push "coffee:module_#{module}_unit_tests"
|
||||
moduleUnitTestTasks.push "mochaTest:module_#{module}_unit"
|
||||
|
||||
if fs.existsSync "./modules/#{module}/public/coffee/ide/index.coffee"
|
||||
config.coffee["module_#{module}_client_ide"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/public/coffee/ide",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "public/js/ide/#{module}",
|
||||
ext: '.js'
|
||||
}
|
||||
moduleCompileClientTasks.push "coffee:module_#{module}_client_ide"
|
||||
moduleIdeClientSideIncludes.push "ide/#{module}/index"
|
||||
|
||||
if fs.existsSync "./modules/#{module}/public/coffee/main/index.coffee"
|
||||
config.coffee["module_#{module}_client_main"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/public/coffee/main",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "public/js/main/#{module}",
|
||||
ext: '.js'
|
||||
}
|
||||
moduleCompileClientTasks.push "coffee:module_#{module}_client_main"
|
||||
moduleMainClientSideIncludes.push "main/#{module}/index"
|
||||
|
||||
grunt.initConfig config
|
||||
|
||||
grunt.registerTask 'wrap_sharejs', 'Wrap the compiled ShareJS code for AMD module loading', () ->
|
||||
content = fs.readFileSync "public/js/libs/sharejs.js"
|
||||
fs.writeFileSync "public/js/libs/sharejs.js", """
|
||||
|
@ -174,8 +239,20 @@ module.exports = (grunt) ->
|
|||
|
||||
grunt.registerTask 'help', 'Display this help list', 'availabletasks'
|
||||
|
||||
grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir']
|
||||
grunt.registerTask 'compile:client', 'Compile the client side coffee script', ['coffee:client', 'coffee:sharejs', 'wrap_sharejs']
|
||||
grunt.registerTask 'compile:modules:server', 'Compile all the modules', moduleCompileServerTasks
|
||||
grunt.registerTask 'compile:modules:unit_tests', 'Compile all the modules unit tests', moduleCompileUnitTestTasks
|
||||
grunt.registerTask 'compile:modules:client', 'Compile all the module client side code', moduleCompileClientTasks
|
||||
grunt.registerTask 'compile:modules:inject_clientside_includes', () ->
|
||||
content = fs.readFileSync("public/js/ide.js").toString()
|
||||
content = content.replace(/"__IDE_CLIENTSIDE_INCLUDES__"/g, moduleIdeClientSideIncludes.map((i) -> "\"#{i}\"").join(", "))
|
||||
fs.writeFileSync "public/js/ide.js", content
|
||||
|
||||
content = fs.readFileSync("public/js/main.js").toString()
|
||||
content = content.replace(/"__MAIN_CLIENTSIDE_INCLUDES__"/g, moduleMainClientSideIncludes.map((i) -> "\"#{i}\"").join(", "))
|
||||
fs.writeFileSync "public/js/main.js", content
|
||||
|
||||
grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir', 'compile:modules:server']
|
||||
grunt.registerTask 'compile:client', 'Compile the client side coffee script', ['coffee:client', 'coffee:sharejs', 'wrap_sharejs', "compile:modules:client", 'compile:modules:inject_clientside_includes']
|
||||
grunt.registerTask 'compile:css', 'Compile the less files to css', ['less']
|
||||
grunt.registerTask 'compile:minify', 'Concat and minify the client side js', ['requirejs']
|
||||
grunt.registerTask 'compile:unit_tests', 'Compile the unit tests', ['clean:unit_tests', 'coffee:unit_tests']
|
||||
|
@ -188,6 +265,8 @@ module.exports = (grunt) ->
|
|||
grunt.registerTask 'test:unit', 'Run the unit tests (use --grep=<regex> or --feature=<feature> for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit']
|
||||
grunt.registerTask 'test:smoke', 'Run the smoke tests', ['compile:smoke_tests', 'mochaTest:smoke']
|
||||
|
||||
grunt.registerTask 'test:modules:unit', 'Run the unit tests for the modules', ['compile:modules:server', 'compile:modules:unit_tests'].concat(moduleUnitTestTasks)
|
||||
|
||||
grunt.registerTask 'run', "Compile and run the web-sharelatex server", ['compile', 'bunyan', 'execute']
|
||||
grunt.registerTask 'default', 'run'
|
||||
|
||||
|
|
|
@ -50,6 +50,10 @@ module.exports = AuthenticationController =
|
|||
callback null, null
|
||||
|
||||
getLoggedInUser: (req, options = {allow_auth_token: false}, callback = (error, user) ->) ->
|
||||
if typeof(options) == "function"
|
||||
callback = options
|
||||
options = {allow_auth_token: false}
|
||||
|
||||
if req.session?.user?._id?
|
||||
query = req.session.user._id
|
||||
else if req.query?.auth_token? and options.allow_auth_token
|
||||
|
|
|
@ -128,6 +128,8 @@ module.exports = ProjectController =
|
|||
Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref', cb
|
||||
hasSubscription: (cb)->
|
||||
LimitationsManager.userHasSubscriptionOrIsGroupMember req.session.user, cb
|
||||
user: (cb) ->
|
||||
User.findById user_id, "featureSwitches", cb
|
||||
}, (err, results)->
|
||||
if err?
|
||||
logger.err err:err, "error getting data for project list page"
|
||||
|
@ -135,6 +137,7 @@ module.exports = ProjectController =
|
|||
logger.log results:results, user_id:user_id, "rendering project list"
|
||||
tags = results.tags[0]
|
||||
projects = ProjectController._buildProjectList results.projects[0], results.projects[1], results.projects[2]
|
||||
user = results.user
|
||||
ProjectController._injectProjectOwners projects, (error, projects) ->
|
||||
return next(error) if error?
|
||||
|
||||
|
@ -143,6 +146,7 @@ module.exports = ProjectController =
|
|||
priority_title: true
|
||||
projects: projects
|
||||
tags: tags
|
||||
user: user
|
||||
hasSubscription: results.hasSubscription
|
||||
}
|
||||
|
||||
|
@ -212,6 +216,7 @@ module.exports = ProjectController =
|
|||
referal_id : user.referal_id
|
||||
subscription :
|
||||
freeTrial: {allowed: allowedFreeTrial}
|
||||
featureSwitches: user.featureSwitches
|
||||
}
|
||||
userSettings: {
|
||||
mode : user.ace.mode
|
||||
|
@ -283,8 +288,7 @@ defaultSettingsForAnonymousUser = (user_id)->
|
|||
freeTrial:
|
||||
allowed: true
|
||||
featureSwitches:
|
||||
dropbox: false
|
||||
trackChanges: false
|
||||
github: false
|
||||
|
||||
THEME_LIST = []
|
||||
do generateThemeList = () ->
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
tpdsUpdateHandler = require('./TpdsUpdateHandler')
|
||||
UpdateMerger = require "./UpdateMerger"
|
||||
logger = require('logger-sharelatex')
|
||||
Path = require('path')
|
||||
metrics = require("../../infrastructure/Metrics")
|
||||
|
@ -32,6 +33,24 @@ module.exports =
|
|||
res.send 200
|
||||
req.session.destroy()
|
||||
|
||||
updateProjectContents: (req, res, next = (error) ->) ->
|
||||
{project_id} = req.params
|
||||
path = "/" + req.params[0] # UpdateMerger expects leading slash
|
||||
logger.log project_id: project_id, path: path, "received project contents update"
|
||||
UpdateMerger.mergeUpdate project_id, path, req, (error) ->
|
||||
return next(error) if error?
|
||||
res.send(200)
|
||||
req.session.destroy()
|
||||
|
||||
deleteProjectContents: (req, res, next = (error) ->) ->
|
||||
{project_id} = req.params
|
||||
path = "/" + req.params[0] # UpdateMerger expects leading slash
|
||||
logger.log project_id: project_id, path: path, "received project contents delete request"
|
||||
UpdateMerger.deleteUpdate project_id, path, (error) ->
|
||||
return next(error) if error?
|
||||
res.send(200)
|
||||
req.session.destroy()
|
||||
|
||||
parseParams: parseParams = (req)->
|
||||
path = req.params[0]
|
||||
user_id = req.params.user_id
|
||||
|
|
|
@ -33,8 +33,7 @@ module.exports =
|
|||
dropboxHandler.getUserRegistrationStatus user._id, (err, status)->
|
||||
userIsRegisteredWithDropbox = !err? and status.registered
|
||||
res.render 'user/settings',
|
||||
title:'account_settings',
|
||||
userHasDropboxFeature: user.features.dropbox
|
||||
title:'account_settings'
|
||||
userIsRegisteredWithDropbox: userIsRegisteredWithDropbox
|
||||
user: user,
|
||||
languages: Settings.languages,
|
||||
|
|
|
@ -6,6 +6,7 @@ SubscriptionFormatters = require('../Features/Subscription/SubscriptionFormatter
|
|||
querystring = require('querystring')
|
||||
SystemMessageManager = require("../Features/SystemMessages/SystemMessageManager")
|
||||
_ = require("underscore")
|
||||
Modules = require "./Modules"
|
||||
|
||||
fingerprints = {}
|
||||
Path = require 'path'
|
||||
|
@ -146,3 +147,9 @@ module.exports = (app)->
|
|||
res.locals.currentLngCode = req.lng
|
||||
next()
|
||||
|
||||
app.use (req, res, next) ->
|
||||
if !Settings.cacheModuleViewIncludes
|
||||
Modules.loadViewIncludes()
|
||||
res.locals.moduleIncludes = Modules.moduleIncludes
|
||||
next()
|
||||
|
||||
|
|
36
services/web/app/coffee/infrastructure/Modules.coffee
Normal file
36
services/web/app/coffee/infrastructure/Modules.coffee
Normal file
|
@ -0,0 +1,36 @@
|
|||
fs = require "fs"
|
||||
Path = require "path"
|
||||
jade = require "jade"
|
||||
|
||||
MODULE_BASE_PATH = Path.resolve(__dirname + "/../../../modules")
|
||||
|
||||
module.exports = Modules =
|
||||
modules: []
|
||||
loadModules: () ->
|
||||
for moduleName in fs.readdirSync(MODULE_BASE_PATH)
|
||||
if fs.existsSync(Path.join(MODULE_BASE_PATH, moduleName, "index.js"))
|
||||
loadedModule = require(Path.join(MODULE_BASE_PATH, moduleName, "index"))
|
||||
loadedModule.name = moduleName
|
||||
@modules.push loadedModule
|
||||
|
||||
applyRouter: (app) ->
|
||||
for module in @modules
|
||||
module.router?.apply(app)
|
||||
|
||||
viewIncludes: {}
|
||||
loadViewIncludes: (app) ->
|
||||
@viewIncludes = {}
|
||||
for module in @modules
|
||||
for view, partial of module.viewIncludes or {}
|
||||
@viewIncludes[view] ||= []
|
||||
@viewIncludes[view].push fs.readFileSync(Path.join(MODULE_BASE_PATH, module.name, "app/views", partial + ".jade"))
|
||||
|
||||
moduleIncludes: (view, locals) ->
|
||||
partials = Modules.viewIncludes[view] or []
|
||||
html = ""
|
||||
for partial in partials
|
||||
compiler = jade.compile(partial, doctype: "html")
|
||||
html += compiler(locals)
|
||||
return html
|
||||
|
||||
Modules.loadModules()
|
|
@ -24,6 +24,7 @@ ReferalConnect = require('../Features/Referal/ReferalConnect')
|
|||
RedirectManager = require("./RedirectManager")
|
||||
OldAssetProxy = require("./OldAssetProxy")
|
||||
translations = require("translations-sharelatex").setup(Settings.i18n)
|
||||
Modules = require "./Modules"
|
||||
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongojs/node_modules/mongodb"), logger)
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongoose/node_modules/mongodb"), logger)
|
||||
|
@ -46,13 +47,13 @@ app.ignoreCsrf = (method, route) ->
|
|||
ignoreCsrfRoutes.push new express.Route(method, route)
|
||||
|
||||
|
||||
|
||||
app.configure () ->
|
||||
if Settings.behindProxy
|
||||
app.enable('trust proxy')
|
||||
app.use express.static(__dirname + '/../../../public', {maxAge: staticCacheAge })
|
||||
app.set 'views', __dirname + '/../../views'
|
||||
app.set 'view engine', 'jade'
|
||||
Modules.loadViewIncludes app
|
||||
app.use express.bodyParser(uploadDir: Settings.path.uploadFolder)
|
||||
app.use express.bodyParser(uploadDir: __dirname + "/../../../data/uploads")
|
||||
app.use translations.expressMiddlewear
|
||||
|
|
|
@ -33,8 +33,7 @@ UserSchema = new Schema
|
|||
dropbox: { type:Boolean, default: Settings.defaultFeatures.dropbox }
|
||||
}
|
||||
featureSwitches : {
|
||||
dropbox: {type:Boolean, default:true},
|
||||
oldHistory: {type:Boolean}
|
||||
github: {type: Boolean}
|
||||
}
|
||||
referal_id : {type:String, default:() -> uuid.v4().split("-")[0]}
|
||||
refered_users: [ type:ObjectId, ref:'User' ]
|
||||
|
|
|
@ -39,6 +39,7 @@ WikiController = require("./Features/Wiki/WikiController")
|
|||
ConnectedUsersController = require("./Features/ConnectedUsers/ConnectedUsersController")
|
||||
DropboxRouter = require "./Features/Dropbox/DropboxRouter"
|
||||
dropboxHandler = require "./Features/Dropbox/DropboxHandler"
|
||||
Modules = require "./infrastructure/Modules"
|
||||
|
||||
logger = require("logger-sharelatex")
|
||||
_ = require("underscore")
|
||||
|
@ -68,6 +69,8 @@ module.exports = class Router
|
|||
TemplatesRouter.apply(app)
|
||||
DropboxRouter.apply(app)
|
||||
|
||||
Modules.applyRouter(app)
|
||||
|
||||
app.get '/blog', BlogController.getIndexPage
|
||||
app.get '/blog/*', BlogController.getPage
|
||||
|
||||
|
@ -155,6 +158,11 @@ module.exports = class Router
|
|||
app.ignoreCsrf('post', '/user/:user_id/update/*')
|
||||
app.ignoreCsrf('delete', '/user/:user_id/update/*')
|
||||
|
||||
app.post '/project/:project_id/contents/*', httpAuth, TpdsController.updateProjectContents
|
||||
app.del '/project/:project_id/contents/*', httpAuth, TpdsController.deleteProjectContents
|
||||
app.ignoreCsrf('post', '/project/:project_id/contents/*')
|
||||
app.ignoreCsrf('delete', '/project/:project_id/contents/*')
|
||||
|
||||
app.post "/spelling/check", AuthenticationController.requireLogin(), SpellingController.proxyRequestToSpellingApi
|
||||
app.post "/spelling/learn", AuthenticationController.requireLogin(), SpellingController.proxyRequestToSpellingApi
|
||||
|
||||
|
|
|
@ -46,15 +46,16 @@ aside#left-menu.full-size(
|
|||
i.fa.fa-external-link.fa-fw
|
||||
| #{translate("publish_as_template")}
|
||||
|
||||
|
||||
span(ng-controller="DropboxController", ng-show="permissions.admin")
|
||||
h4() #{translate("sync")}
|
||||
span(ng-controller="DropboxController", ng-show="permissions.admin")
|
||||
ul.list-unstyled.nav()
|
||||
li
|
||||
a(ng-click="openDropboxModal()")
|
||||
i.fa.fa-dropbox.fa-fw
|
||||
| Dropbox
|
||||
|
||||
!{moduleIncludes("editorLeftMenu", locals)}
|
||||
|
||||
h4(ng-show="!anonymous") #{translate("settings")}
|
||||
form.settings(ng-controller="SettingsController", ng-show="!anonymous")
|
||||
.containter-fluid
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
href,
|
||||
ng-click="openUploadProjectModal()"
|
||||
) #{translate("upload_project")}
|
||||
!{moduleIncludes("newProjectMenu", locals)}
|
||||
if (templates)
|
||||
li.divider
|
||||
li.dropdown-header #{translate("templates")}
|
||||
|
|
|
@ -96,22 +96,29 @@ block content
|
|||
ng-disabled="changePasswordForm.$invalid"
|
||||
) #{translate("change")}
|
||||
|
||||
hr.soften
|
||||
hr
|
||||
|
||||
h3 #{translate("dropbox_integration")}
|
||||
span.small
|
||||
a(href='/help/kb/dropbox-2') (#{translate("learn_more")})
|
||||
- if(!userHasDropboxFeature)
|
||||
.alert.alert-info #{translate("dropbox_is_premium")}
|
||||
- if(!user.features.dropbox)
|
||||
p.small #{translate("dropbox_sync_description")}
|
||||
.alert.alert-info
|
||||
p #{translate("dropbox_is_premium")}
|
||||
p
|
||||
a.btn.btn-info(href='/user/subscription/plans') #{translate("upgrade")}
|
||||
- else if(userIsRegisteredWithDropbox)
|
||||
.alert.alert-success #{translate("account_is_linked")}
|
||||
row
|
||||
a(href='/dropbox/unlink').btn #{translate("unlink_dropbox")}
|
||||
- else
|
||||
p.small #{translate("dropbox_sync_description")}
|
||||
p
|
||||
a.btn.btn-info(href='/dropbox/beginAuth') #{translate("link_to_dropbox")}
|
||||
|
||||
hr.soften
|
||||
| !{moduleIncludes("userSettings", locals)}
|
||||
|
||||
hr
|
||||
|
||||
p.small
|
||||
| #{translate("newsletter_info_and_unsubscribe")}
|
||||
|
|
|
@ -88,6 +88,8 @@ module.exports =
|
|||
url: "http://localhost:3013"
|
||||
templates:
|
||||
url: "http://localhost:3007"
|
||||
githubSync:
|
||||
url: "http://localhost:3022"
|
||||
recurly:
|
||||
privateKey: ""
|
||||
apiKey: ""
|
||||
|
|
|
@ -17,6 +17,7 @@ define [
|
|||
"ide/hotkeys/index"
|
||||
"ide/directives/layout"
|
||||
"ide/services/ide"
|
||||
"__IDE_CLIENTSIDE_INCLUDES__"
|
||||
"analytics/AbTestingManager"
|
||||
"directives/focus"
|
||||
"directives/fineUpload"
|
||||
|
|
|
@ -22,5 +22,6 @@ define [
|
|||
"directives/selectAll"
|
||||
"directives/maxHeight"
|
||||
"filters/formatDate"
|
||||
"__MAIN_CLIENTSIDE_INCLUDES__"
|
||||
], () ->
|
||||
angular.bootstrap(document.body, ["SharelatexApp"])
|
||||
|
|
|
@ -198,8 +198,8 @@ describe "ProjectController", ->
|
|||
first_name: 'James'
|
||||
'user-2':
|
||||
first_name: 'Henry'
|
||||
@users[@user._id] = @user # Owner
|
||||
@UserModel.findById = (id, fields, callback) =>
|
||||
fields.should.equal 'first_name last_name'
|
||||
callback null, @users[id]
|
||||
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, false)
|
||||
|
@ -224,6 +224,12 @@ describe "ProjectController", ->
|
|||
done()
|
||||
@ProjectController.projectListPage @req, @res
|
||||
|
||||
it "should send the user", (done)->
|
||||
@res.render = (pageName, opts)=>
|
||||
opts.user.should.deep.equal @user
|
||||
done()
|
||||
@ProjectController.projectListPage @req, @res
|
||||
|
||||
it "should inject the users", (done) ->
|
||||
@res.render = (pageName, opts)=>
|
||||
opts.projects[0].owner.should.equal (@users[@projects[0].owner_ref])
|
||||
|
|
|
@ -5,11 +5,12 @@ modulePath = require('path').join __dirname, '../../../../app/js/Features/ThirdP
|
|||
|
||||
|
||||
|
||||
describe 'third party data store', ->
|
||||
describe 'TpdsController', ->
|
||||
beforeEach ->
|
||||
@updateHandler = {}
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
'./TpdsUpdateHandler':@updateHandler
|
||||
@TpdsUpdateHandler = {}
|
||||
@TpdsController = SandboxedModule.require modulePath, requires:
|
||||
'./TpdsUpdateHandler':@TpdsUpdateHandler
|
||||
'./UpdateMerger': @UpdateMerger = {}
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
err:->
|
||||
|
@ -24,11 +25,11 @@ describe 'third party data store', ->
|
|||
params:{0:path, "user_id":@user_id}
|
||||
session:
|
||||
destroy:->
|
||||
@updateHandler.newUpdate = sinon.stub().callsArg(5)
|
||||
@TpdsUpdateHandler.newUpdate = sinon.stub().callsArg(5)
|
||||
res = send: =>
|
||||
@updateHandler.newUpdate.calledWith(@user_id, "projectName","/here.txt", req).should.equal true
|
||||
@TpdsUpdateHandler.newUpdate.calledWith(@user_id, "projectName","/here.txt", req).should.equal true
|
||||
done()
|
||||
@controller.mergeUpdate req, res
|
||||
@TpdsController.mergeUpdate req, res
|
||||
|
||||
describe 'getting a delete update', ->
|
||||
it 'should process the delete with the update reciver', (done)->
|
||||
|
@ -37,18 +38,18 @@ describe 'third party data store', ->
|
|||
params:{0:path, "user_id":@user_id}
|
||||
session:
|
||||
destroy:->
|
||||
@updateHandler.deleteUpdate = sinon.stub().callsArg(4)
|
||||
@TpdsUpdateHandler.deleteUpdate = sinon.stub().callsArg(4)
|
||||
res = send: =>
|
||||
@updateHandler.deleteUpdate.calledWith(@user_id, "projectName", "/here.txt").should.equal true
|
||||
@TpdsUpdateHandler.deleteUpdate.calledWith(@user_id, "projectName", "/here.txt").should.equal true
|
||||
done()
|
||||
@controller.deleteUpdate req, res
|
||||
@TpdsController.deleteUpdate req, res
|
||||
|
||||
describe 'parseParams', ->
|
||||
|
||||
it 'should take the project name off the start and replace with slash', ->
|
||||
path = "noSlashHere"
|
||||
req = params:{0:path, user_id:@user_id}
|
||||
result = @controller.parseParams(req)
|
||||
result = @TpdsController.parseParams(req)
|
||||
result.user_id.should.equal @user_id
|
||||
result.filePath.should.equal "/"
|
||||
result.projectName.should.equal path
|
||||
|
@ -57,7 +58,7 @@ describe 'third party data store', ->
|
|||
it 'should take the project name off the start and return it with no slashes in', ->
|
||||
path = "/project/file.tex"
|
||||
req = params:{0:path, user_id:@user_id}
|
||||
result = @controller.parseParams(req)
|
||||
result = @TpdsController.parseParams(req)
|
||||
result.user_id.should.equal @user_id
|
||||
result.filePath.should.equal "/file.tex"
|
||||
result.projectName.should.equal "project"
|
||||
|
@ -65,8 +66,57 @@ describe 'third party data store', ->
|
|||
it 'should take the project name of and return a slash for the file path', ->
|
||||
path = "/project_name"
|
||||
req = params:{0:path, user_id:@user_id}
|
||||
result = @controller.parseParams(req)
|
||||
result = @TpdsController.parseParams(req)
|
||||
result.projectName.should.equal "project_name"
|
||||
result.filePath.should.equal "/"
|
||||
|
||||
describe 'updateProjectContents', ->
|
||||
beforeEach ->
|
||||
@UpdateMerger.mergeUpdate = sinon.stub().callsArg(3)
|
||||
@req =
|
||||
params:
|
||||
0: @path = "chapters/main.tex"
|
||||
project_id: @project_id = "project-id-123"
|
||||
session:
|
||||
destroy: sinon.stub()
|
||||
@res =
|
||||
send: sinon.stub()
|
||||
|
||||
@TpdsController.updateProjectContents @req, @res
|
||||
|
||||
it "should merge the update", ->
|
||||
@UpdateMerger.mergeUpdate
|
||||
.calledWith(@project_id, "/" + @path, @req)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success", ->
|
||||
@res.send.calledWith(200).should.equal true
|
||||
|
||||
it "should clear the session", ->
|
||||
@req.session.destroy.called.should.equal true
|
||||
|
||||
describe 'deleteProjectContents', ->
|
||||
beforeEach ->
|
||||
@UpdateMerger.deleteUpdate = sinon.stub().callsArg(2)
|
||||
@req =
|
||||
params:
|
||||
0: @path = "chapters/main.tex"
|
||||
project_id: @project_id = "project-id-123"
|
||||
session:
|
||||
destroy: sinon.stub()
|
||||
@res =
|
||||
send: sinon.stub()
|
||||
|
||||
@TpdsController.deleteProjectContents @req, @res
|
||||
|
||||
it "should delete the file", ->
|
||||
@UpdateMerger.deleteUpdate
|
||||
.calledWith(@project_id, "/" + @path)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success", ->
|
||||
@res.send.calledWith(200).should.equal true
|
||||
|
||||
it "should clear the session", ->
|
||||
@req.session.destroy.called.should.equal true
|
||||
|
||||
|
|
Loading…
Reference in a new issue