diff --git a/server/lib/Sensor.py b/server/lib/Sensor.py index c74b6a3..af83cd4 100755 --- a/server/lib/Sensor.py +++ b/server/lib/Sensor.py @@ -148,3 +148,17 @@ def delete_pending_sensor(req_dict): def _delete_pending_sensor(sensor_uuid): r_serv_db.srem('sensor_pending_registration', sensor_uuid) return ({'uuid': sensor_uuid}, 200) + +def delete_registered_sensor(req_dict): + sensor_uuid = req_dict.get('uuid', None) + if not is_valid_uuid_v4(sensor_uuid): + return ({"status": "error", "reason": "Invalid uuid"}, 400) + sensor_uuid = sensor_uuid.replace('-', '') + # sensor not registred + if not r_serv_db.sismember('registered_uuid', sensor_uuid): + return ({"status": "error", "reason": "Sensor not registered"}, 404) + return _delete_registered_sensor(sensor_uuid) + +def _delete_registered_sensor(sensor_uuid): + r_serv_db.srem('registered_uuid', sensor_uuid) + return ({'uuid': sensor_uuid}, 200) diff --git a/server/web/Flask_server.py b/server/web/Flask_server.py index 50eee84..43efd91 100755 --- a/server/web/Flask_server.py +++ b/server/web/Flask_server.py @@ -762,6 +762,17 @@ def delete_pending_sensor(): else: return jsonify(res[0]) +@app.route('/server/delete_registered_sensor') +@login_required +@login_admin +def delete_registered_sensor(): + uuid_sensor = request.args.get('uuid') + res = Sensor.delete_registered_sensor({'uuid': uuid_sensor}) + if res[1] == 200: + return redirect(url_for('registered_sensor')) + else: + return jsonify(res[0]) + @app.route('/uuid_change_stream_max_size') @login_required @login_user_basic diff --git a/server/web/templates/registered_sensors.html b/server/web/templates/registered_sensors.html index f97bb89..cf20aae 100644 --- a/server/web/templates/registered_sensors.html +++ b/server/web/templates/registered_sensors.html @@ -38,6 +38,7 @@