diff --git a/src/routes/profile.js b/src/routes/profile.js index a53a5876e..a7369cb9d 100644 --- a/src/routes/profile.js +++ b/src/routes/profile.js @@ -3,7 +3,8 @@ exports = module.exports = { get: get, update: update, - changePassword: changePassword + changePassword: changePassword, + setShowTutorial: setShowTutorial }; var assert = require('assert'), @@ -30,6 +31,7 @@ function get(req, res, next) { result.username = req.user.username; result.email = req.user.email; result.displayName = req.user.displayName; + result.showTutorial = req.user.showTutorial; groups.isMember(groups.ADMIN_GROUP_ID, req.user.id, function (error, isAdmin) { if (error) return next(new HttpError(500, error)); @@ -80,3 +82,17 @@ function changePassword(req, res, next) { next(new HttpSuccess(204)); }); } + +function setShowTutorial(req, res, next) { + assert.strictEqual(typeof req.user, 'object'); + assert.strictEqual(typeof req.body, 'object'); + + if (typeof req.body.showTutorial !== 'boolean') return next(new HttpError(400, 'showTutorial must be a boolean.')); + + user.setShowTutorial(req.user.id, req.body.showTutorial, function (error) { + if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(403, 'Wrong password')); + if (error) return next(new HttpError(500, error)); + + next(new HttpSuccess(204)); + }); +} diff --git a/src/server.js b/src/server.js index b5ad5ab3e..c280a875f 100644 --- a/src/server.js +++ b/src/server.js @@ -103,6 +103,7 @@ function initializeExpressSync() { router.get ('/api/v1/profile', profileScope, routes.profile.get); router.put ('/api/v1/profile', profileScope, routes.profile.update); router.put ('/api/v1/profile/password', profileScope, routes.user.verifyPassword, routes.profile.changePassword); + router.put ('/api/v1/profile/tutorial', profileScope, routes.profile.setShowTutorial); // user routes only for admins router.get ('/api/v1/users', usersScope, routes.user.requireAdmin, routes.user.list);