diff --git a/api/classes/model.php b/api/classes/model.php index 5388368..42df3be 100644 --- a/api/classes/model.php +++ b/api/classes/model.php @@ -177,11 +177,6 @@ class Model { } $data = self::convertFromStorage($storageObject); - - if(method_exists($model, 'restoreLegacySupportHook')) { - $model->restoreLegacySupportHook($data); - } - $properties = array_merge( static::ENCRYPTED_PROPERTIES, static::PLAIN_PROPERTIES, diff --git a/api/classes/poll.php b/api/classes/poll.php index 2fb642d..4553934 100644 --- a/api/classes/poll.php +++ b/api/classes/poll.php @@ -125,20 +125,4 @@ class Poll extends model { return false; } } - - protected function restoreLegacySupportHook(&$data) { - if (!isset($data->version) || $data->version === 'v0.3-0') { - if (isset($data->poll) && is_object($data->poll)) { - $data = $data->poll; - } - - foreach($data as $key => $value) { - if (strpos($key, 'encrypted') === 0) { - $newKey = lcfirst(substr($key, 9)); - $data->$newKey = $data->$key; - unset($data->$key); - } - } - } - } } diff --git a/api/classes/user.php b/api/classes/user.php index 71c2b34..533997e 100644 --- a/api/classes/user.php +++ b/api/classes/user.php @@ -74,20 +74,4 @@ class User extends Model { Poll::isValidId($parts[0]) && intval($parts[1]) == $parts[1]; } - - protected function restoreLegacySupportHook(&$data) { - if (!isset($data->version) || $data->version === 'v0.3-0') { - if (isset($data->user) && is_object($data->user)) { - $data = $data->user; - } - - foreach($data as $key => $value) { - if (strpos($key, 'encrypted') === 0) { - $newKey = lcfirst(substr($key, 9)); - $data->$newKey = $data->$key; - unset($data->$key); - } - } - } - } } diff --git a/api/tests/api/GetLegacyPollWithUsersCept.php b/api/tests/api/GetLegacyPollWithUsersCept.php deleted file mode 100644 index 7ce97c6..0000000 --- a/api/tests/api/GetLegacyPollWithUsersCept.php +++ /dev/null @@ -1,126 +0,0 @@ -wantTo('get an existing legacy (v0.3.0) poll with users'); -$I->sendGET('/polls/' . $pollId); -$I->seeResponseCodeIs(200); -$I->seeHttpHeader('Content-Type', 'application/json'); -$I->seeHttpHeader('Expires', '-1'); -$I->seeResponseIsJson(); - -$pollData = json_decode($pollJson, true)["poll"]; -unset($pollData["serverExpirationDate"]); -unset($pollData["encryptedIsDateTime"]); -unset($pollData["encryptedAnswers"]); -foreach($pollData as $key => $value) { - if (strpos($key, 'encrypted') === 0) { - $key = lcfirst(substr($key, 9)); - } - else { - $key = $key; - } - $I->seeResponseContainsJson( - array( - 'poll' => array( - $key => $value - ) - ) - ); -} - -$I->seeResponseContainsJson(["poll" => ["id" => $pollId]]); -$I->dontSeeResponseJsonMatchesJsonPath('poll.serverExpirationDate'); -$I->seeResponseJsonMatchesJsonPath('poll.users'); -$users = $I->grabDataFromResponseByJsonPath('poll.users')[0]; -\PHPUnit_Framework_Assert::assertTrue( - is_array($users), - 'user should be an array' -); -\PHPUnit_Framework_Assert::assertEquals( - count($users), - 2, - 'user array should contain 2 users' -); - -function wellformUser($user) { - $return = $user["user"]; - foreach ($return as $key => $value) { - if(strpos($key, 'encrypted') === 0) { - $return[lcfirst(substr($key, 9))] = $value; - unset($return[$key]); - } - } - return $return; -} -$I->seeResponseContainsJson([ - "poll" => [ - "users" => [ - wellformUser(json_decode($user1Json, true)), - wellformUser(json_decode($user2Json, true)) - ] - ] -]); - -$I->seeResponseJsonMatchesJsonPath('poll.users.0.id'); -$I->seeResponseJsonMatchesJsonPath('poll.users.1.id'); -$user1Id = $I->grabDataFromResponseByJsonPath('poll.users.0.id')[0]; -$user2Id = $I->grabDataFromResponseByJsonPath('poll.users.1.id')[0]; -\PHPUnit_Framework_Assert::assertTrue( - $user1Id !== $user2Id, - 'user ids are unique' -); -\PHPUnit_Framework_Assert::assertEquals( - explode('_', $user1Id)[0], - $pollId, - 'user id starts by poll id' -); diff --git a/app/serializers/application.js b/app/serializers/application.js index 1b7f84e..bdb9d11 100644 --- a/app/serializers/application.js +++ b/app/serializers/application.js @@ -39,11 +39,6 @@ export default class ApplicationSerializer extends RESTSerializer { } }, this); - // run legacy support transformation specified in model serializer - if (typeof this.legacySupport === 'function') { - resourceHash = this.legacySupport(resourceHash); - } - return super.normalize(modelClass, resourceHash, prop); } diff --git a/app/serializers/user.js b/app/serializers/user.js index 77ddf75..cc55309 100644 --- a/app/serializers/user.js +++ b/app/serializers/user.js @@ -1,35 +1,3 @@ -import classic from 'ember-classic-decorator'; -import { isEmpty } from '@ember/utils'; import ApplicationSerializer from './application'; -@classic -export default class UserSerializer extends ApplicationSerializer { - legacySupport(resourceHash) { - /* - * Croodle <= 0.3.0: - * * for answer type "freetext": - * selections where a string containing label - * * all other answer types ("YesNo", "YesNoMaybe"): - * selections where stored as child object of "value" property - * and selection property "type" where named "id" - */ - if (!isEmpty(resourceHash.selections[0].value)) { - resourceHash.selections.forEach(function (selection, index) { - if (typeof selection.value === 'string') { - resourceHash.selections[index] = { - label: selection.value, - }; - } else { - resourceHash.selections[index] = { - icon: selection.value.icon, - label: selection.value.label, - labelTranslation: selection.value.labelTranslation, - type: selection.value.id, - }; - } - }); - } - - return resourceHash; - } -} +export default class UserSerializer extends ApplicationSerializer {} diff --git a/tests/acceptance/legacy-support-test.js b/tests/acceptance/legacy-support-test.js deleted file mode 100644 index ef0bfa0..0000000 --- a/tests/acceptance/legacy-support-test.js +++ /dev/null @@ -1,237 +0,0 @@ -import { currentRouteName, find, findAll, visit } from '@ember/test-helpers'; -import { module, test } from 'qunit'; -import { setupApplicationTest } from 'ember-qunit'; -import { setupMirage } from 'ember-cli-mirage/test-support'; -import { setupIntl, t } from 'ember-intl/test-support'; -import switchTab from 'croodle/tests/helpers/switch-tab'; -import pollParticipate from 'croodle/tests/helpers/poll-participate'; -import PollEvaluationPage from 'croodle/tests/pages/poll/evaluation'; - -module('Acceptance | legacy support', function (hooks) { - let yesLabel; - let maybeLabel; - let noLabel; - - hooks.beforeEach(function () { - window.localStorage.setItem('locale', 'en'); - }); - - setupApplicationTest(hooks); - setupIntl(hooks); - setupMirage(hooks); - - hooks.beforeEach(function () { - yesLabel = t('answerTypes.yes.label').toString(); - maybeLabel = t('answerTypes.maybe.label').toString(); - noLabel = t('answerTypes.no.label').toString(); - }); - - test('show a default poll created with v0.3.0', async function (assert) { - const encryptionKey = '5MKFuNTKILUXw6RuqkAw6ooZw4k3mWWx98ZQw8vH'; - - let poll = this.server.create('poll', { - encryptionKey, - answerType: 'YesNoMaybe', - // property 'id' of answers has been renamed to 'type' in v0.4.0 - answers: [ - { - id: 'yes', - labelTranslation: 'answerTypes.yes.label', - icon: 'glyphicon glyphicon-thumbs-up', - label: 'Ja', - }, - { - id: 'maybe', - labelTranslation: 'answerTypes.maybe.label', - icon: 'glyphicon glyphicon-hand-right', - label: 'Vielleicht', - }, - { - id: 'no', - labelTranslation: 'answerTypes.no.label', - icon: 'glyphicon glyphicon-thumbs-down', - label: 'Nein', - }, - ], - options: [ - { title: new Date('2015-12-24T17:00').toISOString() }, - { title: new Date('2015-12-24T19:00').toISOString() }, - { title: new Date('2015-12-31T22:59').toISOString() }, - ], - users: [ - this.server.create('user', { - encryptionKey, - name: 'Fritz Bauer', - // selections.value was renamed to selections.label - // selections.id was renamed to selections.type - selections: [ - { - value: { - id: 'yes', - labelTranslation: 'answerTypes.yes.label', - icon: 'glyphicon glyphicon-thumbs-up', - label: 'Ja', - }, - }, - { - value: { - id: 'no', - labelTranslation: 'answerTypes.no.label', - icon: 'glyphicon glyphicon-thumbs-down', - label: 'Nein', - }, - }, - { - value: { - id: 'no', - labelTranslation: 'answerTypes.no.label', - icon: 'glyphicon glyphicon-thumbs-down', - label: 'Nein', - }, - }, - ], - // version tag had have wrong format - version: 'v0.3-0', - }), - ], - // version tag had have wrong format - version: 'v0.3-0', - }); - - await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`); - assert.equal(currentRouteName(), 'poll.participation'); - assert.deepEqual( - findAll( - `[data-test-form-element^="option"] label:not(.custom-control-label)`, - ).map((el) => el.textContent.trim()), - [ - Intl.DateTimeFormat('en-US', { - dateStyle: 'full', - timeStyle: 'short', - }).format(new Date('2015-12-24T17:00')), - Intl.DateTimeFormat('en-US', { timeStyle: 'short' }).format( - new Date('2015-12-24T19:00'), - ), - Intl.DateTimeFormat('en-US', { - dateStyle: 'full', - timeStyle: 'short', - }).format(new Date('2015-12-31T22:59')), - ], - ); - assert.deepEqual( - Array.from( - find('[data-test-form-element^="option"]').querySelectorAll( - '.radio label', - ), - ).map((el) => el.textContent.trim()), - [yesLabel, maybeLabel, noLabel], - ); - - await switchTab('evaluation'); - assert.equal(currentRouteName(), 'poll.evaluation'); - - let participant = PollEvaluationPage.participants.filterBy( - 'name', - 'Fritz Bauer', - )[0]; - assert.ok(participant, 'user exists in participants table'); - assert.deepEqual( - participant.selections.map((_) => _.answer), - [yesLabel, noLabel, noLabel], - 'participants table shows correct answers for new participant', - ); - - await switchTab('participation'); - assert.equal(currentRouteName(), 'poll.participation'); - - await pollParticipate('Hermann Langbein', ['yes', 'maybe', 'yes']); - assert.equal(currentRouteName(), 'poll.evaluation'); - - participant = PollEvaluationPage.participants.filterBy( - 'name', - 'Hermann Langbein', - )[0]; - assert.ok(participant, 'user exists in participants table'); - assert.deepEqual( - participant.selections.map((_) => _.answer), - [yesLabel, maybeLabel, yesLabel], - 'participants table shows correct answers for new participant', - ); - }); - - test('show a poll using free text created with v0.3.0', async function (assert) { - let encryptionKey = 'Rre6dAGOYLW9gYKOP4LhX7Qwfhe5Th3je0uKDtyy'; - let poll = this.server.create('poll', { - encryptionKey, - answerType: 'FreeText', - answers: [], - options: [ - { title: 'apple pie' }, - { title: 'pecan pie' }, - { title: 'plum pie' }, - ], - pollType: 'MakeAPoll', - users: [ - this.server.create('user', { - encryptionKey, - name: 'Paul Levi', - // selections.value was renamed to selections.label - // selections.id was renamed to selections.type - selections: [ - { value: 'would be great!' }, - { value: 'no way' }, - { value: 'if I had to' }, - ], - // version tag had have wrong format - version: 'v0.3-0', - }), - ], - // version tag had have wrong format - version: 'v0.3-0', - }); - - await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`); - assert.equal(currentRouteName(), 'poll.participation'); - assert.deepEqual( - findAll( - `[data-test-form-element^="option"] label:not(.custom-control-label)`, - ).map((el) => el.textContent.trim()), - ['apple pie', 'pecan pie', 'plum pie'], - ); - - await switchTab('evaluation'); - assert.equal(currentRouteName(), 'poll.evaluation'); - - let participant = PollEvaluationPage.participants.filterBy( - 'name', - 'Paul Levi', - )[0]; - assert.ok(participant, 'user exists in participants table'); - assert.deepEqual( - participant.selections.map((_) => _.answer), - ['would be great!', 'no way', 'if I had to'], - 'participants table shows correct answers for new participant', - ); - - await switchTab('participation'); - assert.equal(currentRouteName(), 'poll.participation'); - - await pollParticipate('Hermann Langbein', [ - "I don't care", - 'would be awesome', - "can't imagine anything better", - ]); - assert.equal(currentRouteName(), 'poll.evaluation'); - - participant = PollEvaluationPage.participants.filterBy( - 'name', - 'Hermann Langbein', - )[0]; - assert.ok(participant, 'user exists in participants table'); - assert.deepEqual( - participant.selections.map((_) => _.answer), - ["I don't care", 'would be awesome', "can't imagine anything better"], - 'participants table shows correct answers for new participant', - ); - }); -});