diff --git a/CHANGELOG.md b/CHANGELOG.md index 138416a00d..0cf52e17b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Format based on [Keep a Changelog](http://keepachangelog.com/) ### Security ### Migrations +## [2.2.1] +### Fixes + - Ensures order on personaIdentifier IFIs + ## [2.2.0] ### Added - Override system email address ([#1029](https://github.com/LearningLocker/learninglocker/pull/1029)) (thanks to [@eashman](https://github.com/eashman)) diff --git a/VERSION b/VERSION index ccbccc3dc6..c043eea776 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.0 +2.2.1 diff --git a/api/src/routes/tests/personaController/postIdentifier-test.js b/api/src/routes/tests/personaController/postIdentifier-test.js index 25913c3efc..829355423e 100644 --- a/api/src/routes/tests/personaController/postIdentifier-test.js +++ b/api/src/routes/tests/personaController/postIdentifier-test.js @@ -14,6 +14,7 @@ describe('personaController postIdentifier', () => { beforeEach(async () => { await personaService.clearService(); + await personaService.migrate(); token = await createOrgToken(); }); @@ -47,4 +48,39 @@ describe('personaController postIdentifier', () => { expect(result.body.ifi.key).to.equal('account'); expect(result.body.persona).to.equal(persona.id); }); + + it('should not be able to duplicate an identifier', async () => { + const { persona } = await personaService.createPersona({ + organisation: testId, + name: 'Dave' + }); + + const ifi = { + key: 'account', + value: { + homePage: 'http://example.org', + name: 'test' + } + }; + + await personaService.createIdentifier({ + organisation: testId, + persona: persona.id, + ifi + }); + + await apiApp.post(routes.PERSONA_IDENTIFIER) + .set('Authorization', `Bearer ${token}`) + .send({ + ifi: { + key: ifi.key, + value: { + name: ifi.value.name, + homePage: ifi.value.homePage, + } + }, + persona: persona.id + }) + .expect(400); + }); }); diff --git a/cli/src/commands/v2-migrations/20171127214900_migrate_identifiers.js b/cli/src/commands/v2-migrations/20171127214900_migrate_identifiers.js index cb54f175ef..8086bee555 100644 --- a/cli/src/commands/v2-migrations/20171127214900_migrate_identifiers.js +++ b/cli/src/commands/v2-migrations/20171127214900_migrate_identifiers.js @@ -1,5 +1,7 @@ import highland from 'highland'; import logger from 'lib/logger'; +import isPlainObject from 'lodash/isPlainObject'; +import has from 'lodash/has'; import { getConnection } from 'lib/connections/mongoose'; import { MongoError, ObjectID } from 'mongodb'; @@ -24,7 +26,11 @@ const processStream = stream => const createNewIdent = (doc) => { const { key, value } = doc.uniqueIdentifier; + const newKey = /^statement\.actor\./.test(key) ? key.replace('statement.actor.', '') : key; + const newValue = (isPlainObject(value) && has(value, 'homePage') && has(value, 'name')) + ? { homePage: value.homePage, name: value.name } + : value; return { _id: doc._id, @@ -34,7 +40,7 @@ const createNewIdent = (doc) => { persona: doc.persona, ifi: { key: newKey, - value, + value: newValue, } }; }; diff --git a/package.json b/package.json index b2cbf06f2e..82381124d0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "learning_locker", "description": "An open source learning record store", "license": "GPL-3.0", - "version": "2.2.0", + "version": "2.2.1", "repository": { "type": "git", "url": "https://github.com/LearningLocker/learninglocker" @@ -50,7 +50,7 @@ "dependencies": { "@google-cloud/pubsub": "^0.16.1", "@google-cloud/storage": "^1.5.2", - "@learninglocker/persona-service": "^1.6.8", + "@learninglocker/persona-service": "^1.6.9", "@learninglocker/xapi-statements": "^5.0.9", "@learninglocker/xapi-validation": "^2.1.5", "@newrelic/native-metrics": "^2.1.0", diff --git a/yarn.lock b/yarn.lock index ef5af722a1..10c0ff46f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -84,9 +84,9 @@ string-format-obj "^1.0.0" through2 "^2.0.0" -"@learninglocker/persona-service@^1.6.8": - version "1.6.8" - resolved "https://registry.yarnpkg.com/@learninglocker/persona-service/-/persona-service-1.6.8.tgz#a95811a14698387cb288080870dbdbb8ddd902de" +"@learninglocker/persona-service@^1.6.9": + version "1.6.9" + resolved "https://registry.yarnpkg.com/@learninglocker/persona-service/-/persona-service-1.6.9.tgz#60518ca809e6ae3179b56ac90706aa2f6794e28b" dependencies: aws-sdk "^2.0.1" bluebird "^3.5.0"