Merge branch 'master' of github.com:sharelatex/web-sharelatex

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
This commit is contained in:
Brian Gough 2015-03-06 15:03:52 +00:00
commit b41cdb424b
11 changed files with 105 additions and 26 deletions

View file

@ -59,11 +59,16 @@ module.exports = EditorHttpController =
doc_id: doc._id
}
_nameIsAcceptableLength: (name)->
return name? and name.length < 150 and name.length != 0
addDoc: (req, res, next) ->
project_id = req.params.Project_id
name = req.body.name
parent_folder_id = req.body.parent_folder_id
if !EditorHttpController._nameIsAcceptableLength(name)
return res.send 400
EditorController.addDoc project_id, parent_folder_id, name, [], "editor", (error, doc) ->
return next(error) if error?
res.json doc
@ -72,6 +77,8 @@ module.exports = EditorHttpController =
project_id = req.params.Project_id
name = req.body.name
parent_folder_id = req.body.parent_folder_id
if !EditorHttpController._nameIsAcceptableLength(name)
return res.send 400
EditorController.addFolder project_id, parent_folder_id, name, "editor", (error, doc) ->
return next(error) if error?
res.json doc
@ -81,7 +88,7 @@ module.exports = EditorHttpController =
entity_id = req.params.entity_id
entity_type = req.params.entity_type
name = req.body.name
if name.length > 150
if !EditorHttpController._nameIsAcceptableLength(name)
return res.send 400
EditorController.renameEntity project_id, entity_id, entity_type, name, (error) ->
return next(error) if error?

View file

@ -13,6 +13,7 @@ module.exports = RecurlyWrapper =
<subscription>
<plan_code>#{subscriptionDetails.plan_code}</plan_code>
<currency>#{subscriptionDetails.currencyCode}</currency>
<coupon_code>#{subscriptionDetails.coupon_code}</coupon_code>
<account>
<account_code>#{user._id}</account_code>
<email>#{user.email}</email>

View file

@ -63,6 +63,7 @@ module.exports = SubscriptionController =
currency: currency
subdomain: Settings.apis.recurly.subdomain
showCouponField: req.query.scf
showVatField: req.query.svf
couponCode: req.query.cc or ""
subscriptionFormOptions: JSON.stringify
acceptedCards: ['discover', 'mastercard', 'visa']

View file

@ -30,6 +30,9 @@ module.exports = ProjectUploadController =
{name, path} = req.files.qqfile
project_id = req.params.Project_id
folder_id = req.query.folder_id
if !name? or name.length == 0 or name.length > 150
logger.err project_id:project_id, name:name, "bad name when trying to upload file"
return res.send success: false
FileSystemImportManager.addEntity project_id, folder_id, name, path, true, (error, entity) ->
fs.unlink path, ->
timer.done()

View file

@ -6,8 +6,6 @@ ObjectId = Schema.ObjectId
DocSchema = new Schema
name : {type:String, default:'new doc'}
lines : [{}]
rev : {type:Number, default:0}
mongoose.model 'Doc', DocSchema

View file

@ -152,7 +152,11 @@ block content
if (showCouponField)
.form-group
input.form-control(type='text', ng-blur="applyCoupon()", ng-model="data.coupon", placeholder="#{translate('coupon')}")
.row
.col-md-8
if (showVatField)
.form-group
input.form-control(type='text', ng-blur="applyVatNumber()", ng-model="data.vat_number", placeholder="#{translate('vat_number')}")
.row
.col-xs-7
.form-group

View file

@ -55,9 +55,12 @@ define [
, 200
$scope.create = () ->
name = $scope.inputs.name
if !name? or name.length == 0
return
$scope.state.inflight = true
ide.fileTreeManager
.createDoc($scope.inputs.name, parent_folder)
.createDoc(name, parent_folder)
.success () ->
$scope.state.inflight = false
$modalInstance.close()
@ -80,9 +83,13 @@ define [
, 200
$scope.create = () ->
name = $scope.inputs.name
if !name? or name.length == 0
return
$scope.state.inflight = true
$scope.state.inflight = true
ide.fileTreeManager
.createFolder($scope.inputs.name, parent_folder)
.createFolder(name, parent_folder)
.success () ->
$scope.state.inflight = false
$modalInstance.close()

View file

@ -14,7 +14,11 @@ define [
$scope.finishRenaming = () ->
delete $scope.entity.renaming
ide.fileTreeManager.renameEntity($scope.entity, $scope.inputs.name)
name = $scope.inputs.name
if !name? or name.length == 0
$scope.inputs.name = $scope.entity.name
return
ide.fileTreeManager.renameEntity($scope.entity, name)
$scope.$on "rename:selected", () ->
$scope.startRenaming() if $scope.entity.selected

View file

@ -60,6 +60,10 @@ define [
$scope.applyCoupon = ->
pricing.coupon($scope.data.coupon).done()
$scope.applyVatNumber = ->
pricing.tax({tax_code: 'digital', vat_number: $scope.data.vat_number}).done()
$scope.changeCurrency = (newCurrency)->
$scope.currencyCode = newCurrency
pricing.currency(newCurrency).done()
@ -101,6 +105,7 @@ define [
subscriptionDetails:
currencyCode:pricing.items.currency
plan_code:pricing.items.plan.code
coupon_code:pricing.items?.coupon?.code || ""
$http.post("/user/subscription/create", postData)
.success (data, status, headers)->
window.location.href = "/user/subscription/thank-you"

View file

@ -169,17 +169,28 @@ describe "EditorHttpController", ->
name: @name = "doc-name"
parent_folder_id: @parent_folder_id
@EditorController.addDoc = sinon.stub().callsArgWith(5, null, @doc)
@EditorHttpController.addDoc @req, @res
it "should call EditorController.addDoc", ->
@EditorController.addDoc
.calledWith(@project_id, @parent_folder_id, @name, [], "editor")
.should.equal true
describe "successfully", ->
beforeEach ->
@EditorHttpController.addDoc @req, @res
it "should send the doc back as JSON", ->
@res.json
.calledWith(@doc)
.should.equal true
it "should call EditorController.addDoc", ->
@EditorController.addDoc
.calledWith(@project_id, @parent_folder_id, @name, [], "editor")
.should.equal true
it "should send the doc back as JSON", ->
@res.json
.calledWith(@doc)
.should.equal true
describe "unsuccesfully", ->
beforeEach ->
@req.body.name = ""
@EditorHttpController.addDoc @req, @res
it "should send back a bad request status code", ->
@res.send.calledWith(400).should.equal true
describe "addFolder", ->
beforeEach ->
@ -190,17 +201,30 @@ describe "EditorHttpController", ->
name: @name = "folder-name"
parent_folder_id: @parent_folder_id
@EditorController.addFolder = sinon.stub().callsArgWith(4, null, @folder)
@EditorHttpController.addFolder @req, @res
it "should call EditorController.addFolder", ->
@EditorController.addFolder
.calledWith(@project_id, @parent_folder_id, @name, "editor")
.should.equal true
describe "successfully", ->
beforeEach ->
@EditorHttpController.addFolder @req, @res
it "should call EditorController.addFolder", ->
@EditorController.addFolder
.calledWith(@project_id, @parent_folder_id, @name, "editor")
.should.equal true
it "should send the folder back as JSON", ->
@res.json
.calledWith(@folder)
.should.equal true
describe "unsuccesfully", ->
beforeEach ->
@req.body.name = ""
@EditorHttpController.addFolder @req, @res
it "should send back a bad request status code", ->
@res.send.calledWith(400).should.equal true
it "should send the folder back as JSON", ->
@res.json
.calledWith(@folder)
.should.equal true
describe "renameEntity", ->
beforeEach ->
@ -235,6 +259,22 @@ describe "EditorHttpController", ->
it "should send back a bad request status code", ->
@res.send.calledWith(400).should.equal true
describe "rename entity with 0 length name", ->
beforeEach ->
@req.params =
Project_id: @project_id
entity_id: @entity_id = "entity-id-123"
entity_type: @entity_type = "entity-type"
@req.body =
name: @name = ""
@EditorController.renameEntity = sinon.stub().callsArg(4)
@EditorHttpController.renameEntity @req, @res
it "should send back a bad request status code", ->
@res.send.calledWith(400).should.equal true
describe "moveEntity", ->
beforeEach ->
@req.params =

View file

@ -18,7 +18,7 @@ describe "ProjectUploadController", ->
@ProjectUploadController = SandboxedModule.require modulePath, requires:
"./ProjectUploadManager" : @ProjectUploadManager = {}
"./FileSystemImportManager" : @FileSystemImportManager = {}
"logger-sharelatex" : @logger = {log: sinon.stub(), error: sinon.stub()}
"logger-sharelatex" : @logger = {log: sinon.stub(), error: sinon.stub(), err:->}
"../../infrastructure/Metrics": @metrics
"fs" : @fs = {}
@ -170,3 +170,12 @@ describe "ProjectUploadController", ->
.calledWith(sinon.match.any, "error uploading file")
.should.equal true
describe "with a bad request", ->
beforeEach ->
@req.files.qqfile.name = ""
@ProjectUploadController.uploadFile @req, @res
it "should return a a non success response", ->
expect(@res.body).to.deep.equal
success: false