Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdesk-4980] Create two locations with same name #1420

Merged
merged 1 commit into from
Feb 7, 2020
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
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
2 changes: 1 addition & 1 deletion e2e/cypress/integration/events/event_action_cancel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Planning.Events: event cancel action', () => {
function expectCancelledInPreview() {
preview.waitTillOpen();
preview.element
.find('.label--yellow2')
.find('.label--yellow2', {timeout: 30000})
.should('contain.text', 'Cancelled');

preview.element
Expand Down
3 changes: 2 additions & 1 deletion e2e/cypress/support/common/ui/actionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class ActionMenu {
get menuButton() {
return this.parent
.find('.icon-dots-vertical')
.first();
.first()
.should('exist');
}

/**
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