mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
92 lines
2.9 KiB
JavaScript
92 lines
2.9 KiB
JavaScript
import { actionChangeTags } from '../actions';
|
|
import { t } from '../util/locale';
|
|
import { utilDisplayLabel } from '../util';
|
|
import { validationIssue, validationIssueFix } from '../core/validator';
|
|
|
|
|
|
export function validationPrivateData() {
|
|
var type = 'private_data';
|
|
|
|
// assume that some buildings are private
|
|
var privateBuildingValues = {
|
|
detached: true,
|
|
farm: true,
|
|
house: true,
|
|
residential: true,
|
|
semidetached_house: true,
|
|
static_caravan: true
|
|
};
|
|
|
|
// but they might be public if they have one of these other tags
|
|
var okayModifierKeys = {
|
|
amenity: true,
|
|
craft: true,
|
|
historic: true,
|
|
leisure: true,
|
|
shop: true,
|
|
tourism: true
|
|
};
|
|
|
|
// these tags may contain personally identifying info
|
|
var personalTags = {
|
|
'contact:email': true,
|
|
'contact:fax': true,
|
|
'contact:phone': true,
|
|
'contact:website': true,
|
|
email: true,
|
|
fax: true,
|
|
phone: true,
|
|
website: true
|
|
};
|
|
|
|
function privateDataKeys(entity) {
|
|
var tags = entity.tags;
|
|
if (!tags.building || !privateBuildingValues[tags.building]) return [];
|
|
var privateKeys = [];
|
|
for (var key in tags) {
|
|
if (okayModifierKeys[key]) return [];
|
|
if (personalTags[key]) privateKeys.push(key);
|
|
}
|
|
return privateKeys;
|
|
}
|
|
|
|
var validation = function checkPrivateData(entity, context) {
|
|
var privateKeys = privateDataKeys(entity);
|
|
if (privateKeys.length === 0) return [];
|
|
|
|
var fixID = privateKeys.length === 1 ? 'remove_tag' : 'remove_tags';
|
|
return [new validationIssue({
|
|
type: type,
|
|
severity: 'warning',
|
|
message: t('issues.private_data.contact.message', {
|
|
feature: utilDisplayLabel(entity, context),
|
|
}),
|
|
tooltip: t('issues.private_data.tip'),
|
|
entities: [entity],
|
|
info: { privateKeys: privateKeys },
|
|
fixes: [
|
|
new validationIssueFix({
|
|
icon: 'iD-operation-delete',
|
|
title: t('issues.fix.' + fixID + '.title'),
|
|
onClick: function() {
|
|
var entity = this.issue.entities[0];
|
|
var tags = Object.assign({}, entity.tags); // shallow copy
|
|
var privateKeys = this.issue.info.privateKeys;
|
|
for (var index in privateKeys) {
|
|
delete tags[privateKeys[index]];
|
|
}
|
|
context.perform(
|
|
actionChangeTags(entity.id, tags),
|
|
t('issues.fix.remove_private_info.annotation')
|
|
);
|
|
}
|
|
})
|
|
]
|
|
})];
|
|
};
|
|
|
|
validation.type = type;
|
|
|
|
return validation;
|
|
}
|