diff --git a/services/web/app/coffee/Features/User/UserPagesController.coffee b/services/web/app/coffee/Features/User/UserPagesController.coffee index 7619b436db..a79bb1df06 100644 --- a/services/web/app/coffee/Features/User/UserPagesController.coffee +++ b/services/web/app/coffee/Features/User/UserPagesController.coffee @@ -1,4 +1,8 @@ - +UserLocator = require("./UserLocator") +dropboxHandler = require('../Dropbox/DropboxHandler') +logger = require("logger-sharelatex") +Settings = require("settings-sharelatex") +fs = require('fs') module.exports = @@ -27,3 +31,28 @@ module.exports = res.render 'user/passwordReset', title: 'Password Reset' + + + settingsPage : (req, res)-> + logger.log user: req.session.user, "loading settings page" + UserLocator.findById req.session.user._id, (err, user)-> + dropboxHandler.getUserRegistrationStatus user._id, (err, status)-> + userIsRegisteredWithDropbox = !err? and status.registered + res.render 'user/settings', + title:'Your settings', + userHasDropboxFeature: user.features.dropbox + userIsRegisteredWithDropbox: userIsRegisteredWithDropbox + user: user, + themes: THEME_LIST, + editors: ['default','vim','emacs'], + fontSizes: ['10','11','12','13','14','16','20','24'] + languages: Settings.languages, + accountSettingsTabActive: true + +THEME_LIST = [] +do generateThemeList = () -> + files = fs.readdirSync __dirname + '/../../../../public/js/ace/theme' + for file in files + if file.slice(-2) == "js" + cleanName = file.slice(0,-3) + THEME_LIST.push name: cleanName \ No newline at end of file diff --git a/services/web/app/coffee/controllers/UserController.coffee b/services/web/app/coffee/controllers/UserController.coffee index 1ef6706ba4..fc60379cab 100644 --- a/services/web/app/coffee/controllers/UserController.coffee +++ b/services/web/app/coffee/controllers/UserController.coffee @@ -105,22 +105,6 @@ module.exports = logger.err err: err, 'error destorying session' res.redirect '/login' - settings : (req, res)-> - logger.log user: req.session.user, "loading settings page" - User.findById req.session.user._id, (err, user)-> - dropboxHandler.getUserRegistrationStatus user._id, (err, status)-> - userIsRegisteredWithDropbox = !err? and status.registered - res.render 'user/settings', - title:'Your settings', - userCanSeeDropbox: user.featureSwitches.dropbox - userHasDropboxFeature: user.features.dropbox - userIsRegisteredWithDropbox: userIsRegisteredWithDropbox - user: user, - themes: THEME_LIST, - editors: ['default','vim','emacs'], - fontSizes: ['10','11','12','13','14','16','20','24'] - languages: Settings.languages, - accountSettingsTabActive: true unsubscribe: (req, res)-> User.findById req.session.user._id, (err, user)-> @@ -183,10 +167,4 @@ module.exports = res.send(200) -THEME_LIST = [] -do generateThemeList = () -> - files = fs.readdirSync __dirname + '/../../../public/js/ace/theme' - for file in files - if file.slice(-2) == "js" - cleanName = file.slice(0,-3) - THEME_LIST.push name: cleanName + diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 00ce0de400..50c9c9813c 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -75,7 +75,7 @@ module.exports = class Router if Settings.enableSubscriptions app.get '/user/bonus', AuthenticationController.requireLogin(), ReferalMiddleware.getUserReferalId, ReferalController.bonus - app.get '/user/settings', AuthenticationController.requireLogin(), UserController.settings + app.get '/user/settings', AuthenticationController.requireLogin(), UserPagesController.settingsPage app.post '/user/settings', AuthenticationController.requireLogin(), UserController.apiUpdate app.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword app.get '/user/passwordreset', UserPagesController.passwordResetPage diff --git a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee index 05bfd2d474..a33cf9f8d0 100644 --- a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee @@ -11,10 +11,10 @@ ObjectId = require("mongojs").ObjectId describe "UserController", -> beforeEach -> - @UserDeleter = - deleteUser: sinon.stub().callsArgWith(1) @UserController = SandboxedModule.require modulePath, requires: "./UserDeleter": @UserDeleter + "logger-sharelatex": {log:->} + @req = new MockRequest() @res = new MockResponse() @@ -33,7 +33,3 @@ describe "UserController", -> @UserController.deleteUser @req, @res - - - - diff --git a/services/web/test/UnitTests/coffee/User/UserPagesControllerTests.coffee b/services/web/test/UnitTests/coffee/User/UserPagesControllerTests.coffee index 71d8116b4e..994d20dc2e 100644 --- a/services/web/test/UnitTests/coffee/User/UserPagesControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/User/UserPagesControllerTests.coffee @@ -11,14 +11,25 @@ describe "UserPagesController", -> beforeEach -> @settings = {} - + @user = + _id:"kwjewkl" + features:{} + @UserDeleter = + deleteUser: sinon.stub().callsArgWith(1) + @UserLocator = + findById: sinon.stub().callsArgWith(1, null, @user) + @dropboxStatus = {} + @DropboxHandler = + getUserRegistrationStatus : sinon.stub().callsArgWith(1, null, @dropboxStatus) @UserPagesController = SandboxedModule.require modulePath, requires: "settings-sharelatex":@settings "logger-sharelatex": log:-> - + "./UserLocator": @UserLocator + '../Dropbox/DropboxHandler': @DropboxHandler @req = query:{} - session:{} + session: + user:@user @res = {} @@ -89,5 +100,16 @@ describe "UserPagesController", -> @UserPagesController.passwordResetPage @req, @res + describe "settingsPage", -> + it "should render user/settings", (done)-> + @res.render = (page)-> + page.should.equal "user/settings" + done() + @UserPagesController.settingsPage @req, @res + it "should send user", (done)-> + @res.render = (page, opts)=> + opts.user.should.equal @user + done() + @UserPagesController.settingsPage @req, @res \ No newline at end of file