Skip to content

Commit

Permalink
[sdesk-4980] Create two locations with same name
Browse files Browse the repository at this point in the history
  • Loading branch information
marwoodandrew committed Jan 30, 2020
1 parent 08ce57d commit 6480382
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions client/actions/locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ const getMoreLocations = () => (
}
);

const saveNominatim = (nominatim) => (
const saveNominatim = (nominatim, language) => (
(dispatch, getState, {api}) => {
const {address} = formatAddress(nominatim);

return api('locations').save({}, {
unique_name: nominatim.display_name,
name: nominatim.namedetails.name,
name: get(nominatim, 'namedetails.name:' + language,
get(nominatim, 'namedetails.name', get(address, 'line[0]'))),
address: address,
position: {
latitude: nominatim.lat,
Expand All @@ -137,15 +138,15 @@ const saveFreeTextLocation = (location) => (
(dispatch, getState, {api}) => (
api('locations').save({}, {
...location,
unique_name: location.name,
unique_name: get(location, 'name').concat(' ', get(formatAddress(location), 'formattedAddress')),
})
)
);

const saveLocation = (newLocation) => (
(dispatch) => {
const uniqueName = get(newLocation, 'nominatim.display_name')
|| get(newLocation, 'name')
|| get(newLocation, 'name').concat(' ', get(formatAddress(newLocation), 'formattedAddress'))
|| newLocation;
// Check if the newLocation is already saved in internal
// locations resources, if so just return the name and guid as qcode
Expand All @@ -159,7 +160,7 @@ const saveLocation = (newLocation) => (

// this is a new location
if (newLocation.nominatim) {
return dispatch(self.saveNominatim(newLocation.nominatim))
return dispatch(self.saveNominatim(newLocation.nominatim, get(newLocation, 'language')))
.then(
(result) => Promise.resolve(result),
() => Promise.reject('Failed to save location.!')
Expand Down Expand Up @@ -198,6 +199,7 @@ const getLocation = (searchText, unique = false, page = 1) => (
query: {
bool: {
must: [{term: {unique_name: {value: searchText}}}],
must_not: [{term: {is_active: {value: false}}}],
},
},
},
Expand Down
1 change: 1 addition & 0 deletions client/components/GeoLookupInput/AddGeoLookupInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class GeoLookupInputComponent extends React.Component {
name: get(suggest, nameField, shortName),
boundingbox: get(suggest, 'boundingbox'),
type: get(suggest, 'type'),
language: this.language,
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion server/planning/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def delete(self, lookup):
events = superdesk.get_resource_service('events').find(
where={'location.qcode': str(location.get('guid'))})
if events.count():
superdesk.get_resource_service('locations').patch(location[config.ID_FIELD], {'is_active': False})
# patch the unique name in case the location get recreated
superdesk.get_resource_service('locations').patch(location[config.ID_FIELD],
{'is_active': False,
'unique_name': str(location[config.ID_FIELD])})
return
super().delete(lookup)

Expand Down

0 comments on commit 6480382

Please sign in to comment.