diff --git a/api-server/src/common/models/user.json b/api-server/src/common/models/user.json index 46c2777b423..a48b84eff75 100644 --- a/api-server/src/common/models/user.json +++ b/api-server/src/common/models/user.json @@ -110,6 +110,10 @@ "type": "boolean", "default": false }, + "isClassroomAccount": { + "type": "boolean", + "default": false + }, "currentChallengeId": { "type": "string", "description": "The challenge last visited by the user", diff --git a/api-server/src/server/boot/settings.js b/api-server/src/server/boot/settings.js index f86a0e25417..6a5e199062a 100644 --- a/api-server/src/server/boot/settings.js +++ b/api-server/src/server/boot/settings.js @@ -51,6 +51,7 @@ export default function settingsController(app) { ); api.put('/update-my-honesty', ifNoUser401, updateMyHonesty); api.put('/update-my-quincy-email', ifNoUser401, updateMyQuincyEmail); + api.put('/update-my-classroom-mode', ifNoUser401, updateMyClassroomMode); app.use(api); } @@ -319,6 +320,17 @@ function updateMyQuincyEmail(...args) { )(...args); } +export function updateMyClassroomMode(...args) { + const buildUpdate = body => _.pick(body, 'isClassroomAccount'); + const validate = ({ isClassroomAccount }) => + typeof isClassroomAccount === 'boolean'; + createUpdateUserProperties( + buildUpdate, + validate, + 'flash.classroom-mode-updated' + )(...args); +} + function handleInvalidUpdate(res) { res.status(403).json({ type: 'danger', diff --git a/api-server/src/server/boot_tests/settings.test.js b/api-server/src/server/boot_tests/settings.test.js index f51f61a4f3d..0f4c370cedf 100644 --- a/api-server/src/server/boot_tests/settings.test.js +++ b/api-server/src/server/boot_tests/settings.test.js @@ -1,4 +1,4 @@ -import { updateMySocials } from '../boot/settings'; +import { updateMySocials, updateMyClassroomMode } from '../boot/settings'; export const mockReq = opts => { const req = {}; @@ -108,4 +108,34 @@ describe('boot/settings', () => { expect(res.status).toHaveBeenCalledWith(200); }); }); + + describe('updateMyClassroomMode', () => { + it('does not allow invalid classroomMode', () => { + const req = mockReq({ + user: {}, + body: { + isClassroomAccount: 'invalid' + } + }); + const res = mockRes(); + const next = jest.fn(); + updateMyClassroomMode(req, res, next); + expect(res.status).toHaveBeenCalledWith(403); + }); + + it('allows valid classroomMode', () => { + const req = mockReq({ + user: { + updateAttributes: (_, cb) => cb() + }, + body: { + isClassroomAccount: true + } + }); + const res = mockRes(); + const next = jest.fn(); + updateMyClassroomMode(req, res, next); + expect(res.status).toHaveBeenCalledWith(200); + }); + }); }); diff --git a/client/i18n/locales/english/translations.json b/client/i18n/locales/english/translations.json index dff46fdf3f5..f8fd1298ec2 100644 --- a/client/i18n/locales/english/translations.json +++ b/client/i18n/locales/english/translations.json @@ -739,7 +739,8 @@ "err-4": "Something went wrong trying to verify your trophy. Please check and try again.", "verified": "Your trophy from Microsoft's learning platform was verified." } - } + }, + "classroom-mode-updated": "We have updated your classroom mode settings" }, "validation": { "max-characters": "There is a maximum limit of 288 characters, you have {{charsLeft}} left",