From c80b6c07f5c96f4f70490e0199fccf8f9dc60429 Mon Sep 17 00:00:00 2001 From: Alexey Zakharenkov Date: Fri, 28 Feb 2020 17:32:59 +0300 Subject: [PATCH] Forbid joining a region with itself --- server/borders_api.py | 2 ++ www/borders.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/server/borders_api.py b/server/borders_api.py index 6adfd50..ddcea2f 100755 --- a/server/borders_api.py +++ b/server/borders_api.py @@ -228,6 +228,8 @@ def join_borders(): abort(405) name = request.args.get('name').encode('utf-8') name2 = request.args.get('name2').encode('utf-8') + if name == name2: + return jsonify(status='cannot join region with itself') cur = g.conn.cursor() cur.execute('update {table} set geom = ST_Union(geom, b2.g), count_k = -1 from (select geom as g from {table} where name = %s) as b2 where name = %s;'.format(table=config.TABLE), (name2, name)) cur.execute('delete from {} where name = %s;'.format(config.TABLE), (name2,)) diff --git a/www/borders.js b/www/borders.js index e69ea34..9a127f2 100644 --- a/www/borders.js +++ b/www/borders.js @@ -570,7 +570,7 @@ function bJoin() { // called from selectLayer() when joinSelected is not null function bJoinSelect(layer) { - if( 'id' in layer && layer.id in borders ) { + if( 'id' in layer && layer.id in borders && layer.id != joinSelected ) { joinAnother = layer.id; $('#j_name2').text(joinAnother); $('#j_do').css('display', 'block');