Skip to content

Commit

Permalink
Merge pull request #322 from bookbrainz/fix-alias-id
Browse files Browse the repository at this point in the history
fix: Reassign alias language id safely
  • Loading branch information
MonkeyDo committed Nov 18, 2019
2 parents 6914c74 + a7f873b commit 03e683f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/server/routes/entity/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ router.get(
);

function authorToFormState(author) {
/** The front-end expects a language id rather than the language object. */
const aliases = author.aliasSet ?
author.aliasSet.aliases.map(({languageId, ...rest}) => ({
language: languageId,
...rest
...rest,
language: languageId
})) : [];

const defaultAliasIndex = entityRoutes.getDefaultAliasIndex(aliases);
Expand Down
8 changes: 5 additions & 3 deletions src/server/routes/entity/edition-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {escapeProps} from '../../helpers/props';
import express from 'express';
import target from '../../templates/target';


const router = express.Router();

/* If the route specifies a BBID, load the EditionGroup for it. */
Expand Down Expand Up @@ -114,10 +115,11 @@ function getDefaultAliasIndex(aliases) {
}

function editionGroupToFormState(editionGroup) {
/** The front-end expects a language id rather than the language object. */
const aliases = editionGroup.aliasSet ?
editionGroup.aliasSet.aliases.map(({language, ...rest}) => ({
language: language.id,
...rest
editionGroup.aliasSet.aliases.map(({languageId, ...rest}) => ({
...rest,
language: languageId
})) : [];

const defaultAliasIndex = getDefaultAliasIndex(aliases);
Expand Down
7 changes: 4 additions & 3 deletions src/server/routes/entity/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ function getDefaultAliasIndex(aliases) {
}

function editionToFormState(edition) {
/** The front-end expects a language id rather than the language object. */
const aliases = edition.aliasSet ?
edition.aliasSet.aliases.map(({language, ...rest}) => ({
language: language.id,
...rest
edition.aliasSet.aliases.map(({languageId, ...rest}) => ({
...rest,
language: languageId
})) : [];

const defaultAliasIndex = getDefaultAliasIndex(aliases);
Expand Down
7 changes: 4 additions & 3 deletions src/server/routes/entity/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ router.get(
);

function publisherToFormState(publisher) {
/** The front-end expects a language id rather than the language object. */
const aliases = publisher.aliasSet ?
publisher.aliasSet.aliases.map(({language, ...rest}) => ({
language: language.id,
...rest
publisher.aliasSet.aliases.map(({languageId, ...rest}) => ({
...rest,
language: languageId
})) : [];

const defaultAliasIndex = entityRoutes.getDefaultAliasIndex(aliases);
Expand Down
8 changes: 5 additions & 3 deletions src/server/routes/entity/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {escapeProps} from '../../helpers/props';
import express from 'express';
import target from '../../templates/target';


const router = express.Router();

/* If the route specifies a BBID, load the Work for it. */
Expand Down Expand Up @@ -158,10 +159,11 @@ function getDefaultAliasIndex(aliases) {
}

function workToFormState(work) {
/** The front-end expects a language id rather than the language object. */
const aliases = work.aliasSet ?
work.aliasSet.aliases.map(({language, ...rest}) => ({
language: language.id,
...rest
work.aliasSet.aliases.map(({languageId, ...rest}) => ({
...rest,
language: languageId
})) : [];

const defaultAliasIndex = getDefaultAliasIndex(aliases);
Expand Down

0 comments on commit 03e683f

Please sign in to comment.