Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/db/AreaSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const MetadataSchema = new Schema<IAreaMetadata>({
}, { _id: false })

const ContentSchema = new Schema<IAreaContent>({
description: { type: Schema.Types.String }
description: { type: Schema.Types.String },
areaLocation: { type: Schema.Types.String }
}, { _id: false })

export const CountByGroup = new Schema<CountByGroupType>({
Expand Down
6 changes: 4 additions & 2 deletions src/db/AreaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,15 @@ export interface IAreaMetadata {
}

export interface IAreaContent {
/** longform to mediumform description of this area.
* Remembering that areas can be the size of countries, or as precise as a single cliff/boulder,
/** longform to mediumform description and location of this area.
* Remembering that area descriptions can be the size of countries, or as precise as a single cliff/boulder,
* there is not a single definition of valid content for this field.
*
* We expect users to make a call about whatever kind of context may be appropriate for this
* entity, and may be pretty short to extremely detailed.
*/
description?: string
areaLocation?: string
}

/** Fields that may be directly modified by users.
Expand All @@ -179,6 +180,7 @@ export interface IAreaContent {
export interface AreaEditableFieldsType {
areaName?: string
description?: string
areaLocation?: string
isDestination?: boolean
isLeaf?: boolean
isBoulder?: boolean
Expand Down
3 changes: 2 additions & 1 deletion src/db/import/usa/AreaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export const makeDBArea = (node: AreaNode): AreaType => {
density: 0,
totalClimbs: 0,
content: {
description: isLeaf ? (Array.isArray(node.jsonLine.description) ? node.jsonLine.description.join('\n\n') : '') : ''
description: isLeaf ? (Array.isArray(node.jsonLine.description) ? node.jsonLine.description.join('\n\n') : '') : '',
areaLocation: isLeaf ? (Array.isArray(node.jsonLine.areaLocation) ? node.jsonLine.areaLocation.join('\n\n') : '') : ''
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/graphql/schema/Area.gql
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ type CountByGradeBand {

type AreaContent {
description: String
areaLocation: String
}

input Point {
Expand Down
1 change: 1 addition & 0 deletions src/graphql/schema/AreaEdit.gql
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ input AreEditableFieldsInput {
lat: Float
lng: Float
description: String
areaLocation: String
experimentalAuthor: ExperimentalAuthorType
leftRightIndex: Int
}
Expand Down
8 changes: 7 additions & 1 deletion src/model/MutableAreaDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default class MutableAreaDataSource extends AreaDataSource {
const {
areaName,
description,
areaLocation,
shortCode,
isDestination,
isLeaf,
Expand Down Expand Up @@ -465,6 +466,10 @@ export default class MutableAreaDataSource extends AreaDataSource {
const sanitized = sanitizeStrict(description)
area.set({ 'content.description': sanitized })
}
if (areaLocation != null) {
const sanitized = sanitizeStrict(areaLocation)
area.set({ 'content.areaLocation': sanitized })
}

const latLngHasChanged = lat != null && lng != null
if (latLngHasChanged) { // we should already validate lat,lng before in GQL layer
Expand Down Expand Up @@ -697,7 +702,8 @@ export const newAreaHelper = (areaName: string, parentAncestors: string, parentP
density: 0,
totalClimbs: 0,
content: {
description: ''
description: '',
areaLocation: ''
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/model/__tests__/updateAreas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ describe('Areas', () => {
if (a1 == null) {
fail()
}
// for testing area desccription is sanitized
// for testing area description and location is sanitized
const iframeStr = '<iframe src="https://www.googlecom" title="Evil Iframe"></iframe>'
const doc1: AreaEditableFieldsType = {
areaName: '1',
shortCode: 'ONE',
description: `This is a cool area with some malicious code.${iframeStr}`,
areaLocation: `This is a cool area location with some malicious code.${iframeStr}`,
isDestination: true
}
let a1Updated = await areas.updateArea(testUser, a1?.metadata.area_id, doc1)
Expand All @@ -140,6 +141,8 @@ describe('Areas', () => {
expect(a1Updated?.shortCode).toEqual(doc1.shortCode)
// make sure area description is sanitized
expect(a1Updated?.content.description).toEqual(doc1.description?.replace(iframeStr, ''))
// make sure area location is sanitized
expect(a1Updated?.content.areaLocation).toEqual(doc1.areaLocation?.replace(iframeStr, ''))
expect(a1Updated?.metadata.isDestination).toEqual(doc1.isDestination)

const doc2: AreaEditableFieldsType = {
Expand Down