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

This commit is contained in:
Shane Kilkelly 2016-06-06 13:12:31 +01:00
commit fdacf13782
5 changed files with 72 additions and 5 deletions

View file

@ -5,6 +5,12 @@ _ = require("underscore")
ErrorController = require "../Errors/ErrorController"
StaticPageHelpers = require("./StaticPageHelpers")
sanitize = require('sanitizer')
Settings = require("settings-sharelatex")
contentful = require('contentful')
marked = require("marked")
module.exports = UniversityController =
@ -17,7 +23,7 @@ module.exports = UniversityController =
logger.log url:url, "proxying request to university api"
request.get universityUrl, (err, r, data)->
if r?.statusCode == 404
return ErrorController.notFound(req, res, next)
return UniversityController.getContentfulPage(req, res, next)
if err?
return res.send 500
data = data.trim()
@ -37,4 +43,28 @@ module.exports = UniversityController =
upstream = request.get(originUrl)
upstream.on "error", (error) ->
logger.error err: error, "university proxy error"
upstream.pipe res
upstream.pipe res
getContentfulPage: (req, res, next)->
console.log Settings.contentful
if !Settings.contentful?.uni?.space? and !Settings.contentful?.uni?.accessToken?
return ErrorController.notFound(req, res, next)
client = contentful.createClient({
space: Settings.contentful?.uni?.space
accessToken: Settings.contentful?.uni?.accessToken
})
url = req.url?.toLowerCase().replace("/university/","")
client.getEntries({content_type: 'caseStudy', 'fields.slug':url})
.catch (e)->
return res.send 500
.then (entry)->
if !entry? or !entry.items? or entry.items.length == 0
return ErrorController.notFound(req, res, next)
viewData = entry.items[0].fields
viewData.html = marked(viewData.content)
res.render "university/case_study", viewData:viewData

View file

@ -72,6 +72,7 @@ module.exports = UserController =
if err?
logger.err err:err, user_id:user_id, "error getting user for email update"
return res.send 500
req.session.user.email = user.email
UserHandler.populateGroupLicenceInvite user, (err)-> #need to refresh this in the background
if err?
logger.err err:err, "error populateGroupLicenceInvite"
@ -127,6 +128,5 @@ module.exports = UserController =
type:'error'
text:'Your old password is wrong'
changeEmailAddress: (req, res)->

View file

@ -0,0 +1,19 @@
extends ../layout
block content
.masthead
.container
.row
.col-md-12
h1 !{viewData.title}
.row.row-spaced
.pattern-container
.content
.container
.row
.col-md-10.col-md-offset-1
.card
.row
| !{viewData.html}

View file

@ -18,6 +18,7 @@
"body-parser": "^1.13.1",
"bufferedstream": "1.6.0",
"connect-redis": "2.3.0",
"contentful": "^3.3.14",
"cookie": "^0.2.3",
"cookie-parser": "1.3.5",
"csurf": "^1.8.3",
@ -31,7 +32,7 @@
"ldapjs": "^1.0.0",
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.3.1",
"lynx": "0.1.1",
"marked": "^0.3.3",
"marked": "^0.3.5",
"method-override": "^2.3.3",
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.3.0",
"mimelib": "0.2.14",

View file

@ -57,7 +57,9 @@ describe "UserController", ->
"../Subscription/SubscriptionDomainHandler":@SubscriptionDomainHandler
"./UserHandler":@UserHandler
"settings-sharelatex": @settings
"logger-sharelatex": {log:->}
"logger-sharelatex":
log:->
err:->
"../../infrastructure/Metrics": inc:->
@req =
@ -65,6 +67,7 @@ describe "UserController", ->
destroy:->
user :
_id : @user_id
email:"old@something.com"
body:{}
@res =
send: sinon.stub()
@ -154,6 +157,20 @@ describe "UserController", ->
done()
@UserController.updateUserSettings @req, @res
it "should update the email on the session", (done)->
@req.body.email = @newEmail.toUpperCase()
@UserUpdater.changeEmailAddress.callsArgWith(2)
callcount = 0
@User.findById = (id, cb)=>
if ++callcount == 2
@user.email = @newEmail
cb(null, @user)
@res.sendStatus = (code)=>
code.should.equal 200
@req.session.user.email.should.equal @newEmail
done()
@UserController.updateUserSettings @req, @res
it "should call populateGroupLicenceInvite", (done)->
@req.body.email = @newEmail.toUpperCase()
@UserUpdater.changeEmailAddress.callsArgWith(2)