Skip to content

Commit

Permalink
Merge branch 'develop' into py311
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimarBauer authored Sep 3, 2023
2 parents 3c0ff3f + 56e9528 commit 865259c
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 48 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/python-flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ on:
branches:
- develop
- stable
- GSOC2023-NilupulManodya
- GSOC2023-ShubhGaur
pull_request:
branches:
- develop
- stable
- GSOC2023-NilupulManodya
- GSOC2023-ShubhGaur

jobs:
lint:
Expand Down
6 changes: 6 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ def pytest_generate_tests(metafunc):
# mscolab data directory
MSCOLAB_DATA_DIR = fs.path.join(DATA_DIR, 'filedata')
# To enable logging set to True or pass a logger object to use.
SOCKETIO_LOGGER = True
# To enable Engine.IO logging set to True or pass a logger object to use.
ENGINEIO_LOGGER = True
# used to generate and parse tokens
SECRET_KEY = secrets.token_urlsafe(16)
Expand Down
6 changes: 6 additions & 0 deletions docs/samples/config/mscolab/mscolab_settings.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"""
import os

# To enable logging set to True or pass a logger object to use.
SOCKETIO_LOGGER = False

# To enable Engine.IO logging set to True or pass a logger object to use.
ENGINEIO_LOGGER = False

# Set which origins are allowed to communicate with your server
CORS_ORIGINS = ["*"]

Expand Down
2 changes: 1 addition & 1 deletion localbuild/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ requirements:
- unicodecsv
- fs_filepicker
- cftime >=1.0.1
- matplotlib >=3.7
- matplotlib >=3.5.3
- itsdangerous
- pyjwt
- flask >=2.3.2
Expand Down
6 changes: 6 additions & 0 deletions mslib/mscolab/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class default_mscolab_settings:
# expire token in seconds
# EXPIRATION = 86400

# To enable logging set to True or pass a logger object to use.
SOCKETIO_LOGGER = False

# To enable Engine.IO logging set to True or pass a logger object to use.
ENGINEIO_LOGGER = False

# Which origins are allowed to communicate with your server
CORS_ORIGINS = ["*"]

Expand Down
45 changes: 25 additions & 20 deletions mslib/mscolab/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FileManager:
def __init__(self, data_dir):
self.data_dir = data_dir

def create_operation(self, path, description, user, last_used=None, content=None, category="default"):
def create_operation(self, path, description, user, last_used=None, content=None, category="default", active=True):
"""
path: path to the operation
description: description of the operation
Expand All @@ -54,7 +54,7 @@ def create_operation(self, path, description, user, last_used=None, content=None
return False
if last_used is None:
last_used = datetime.datetime.utcnow()
operation = Operation(path, description, last_used, category)
operation = Operation(path, description, last_used, category, active=active)
db.session.add(operation)
db.session.flush()
operation_id = operation.id
Expand Down Expand Up @@ -96,22 +96,27 @@ def get_operation_details(self, op_id, user):
return op
return False

def list_operations(self, user):
def list_operations(self, user, skip_archived=False):
"""
user: logged in user
skip_archived: filter by active operations
"""
operations = []
permissions = Permission.query.filter_by(u_id=user.id).all()
for permission in permissions:
operation = Operation.query.filter_by(id=permission.op_id).first()
operations.append({
"op_id": permission.op_id,
"access_level": permission.access_level,
"path": operation.path,
"description": operation.description,
"category": operation.category,
"active": operation.active
})
if skip_archived:
operation = Operation.query.filter_by(id=permission.op_id, active=skip_archived).first()
else:
operation = Operation.query.filter_by(id=permission.op_id).first()
if operation is not None:
operations.append({
"op_id": permission.op_id,
"access_level": permission.access_level,
"path": operation.path,
"description": operation.description,
"category": operation.category,
"active": operation.active
})
return operations

def is_member(self, u_id, op_id):
Expand Down Expand Up @@ -303,7 +308,7 @@ def get_file(self, op_id, user):
operation_data = operation_file.read()
return operation_data

def get_all_changes(self, op_id, user, named_version=None):
def get_all_changes(self, op_id, user, named_version=False):
"""
op_id: operation-id
user: user of this request
Expand All @@ -314,19 +319,19 @@ def get_all_changes(self, op_id, user, named_version=None):
perm = Permission.query.filter_by(u_id=user.id, op_id=op_id).first()
if perm is None:
return False
# Get all changes
if named_version is None:
changes = Change.query.\
filter_by(op_id=op_id)\
.order_by(Change.created_at.desc())\
.all()
# Get only named versions
else:
if named_version:
changes = Change.query\
.filter(Change.op_id == op_id)\
.filter(~Change.version_name.is_(None))\
.order_by(Change.created_at.desc())\
.all()
# Get all changes
else:
changes = Change.query\
.filter_by(op_id=op_id)\
.order_by(Change.created_at.desc())\
.all()

return list(map(lambda change: {
'id': change.id,
Expand Down
9 changes: 6 additions & 3 deletions mslib/mscolab/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ def create_operation():
content = request.form.get('content', None)
description = request.form.get('description', None)
category = request.form.get('category', "default")
active = (request.form.get('active', "True") == "True")
last_used = datetime.datetime.utcnow()
user = g.user
r = str(fm.create_operation(path, description, user, last_used, content=content, category=category))
r = str(fm.create_operation(path, description, user, last_used,
content=content, category=category, active=active))
if r == "True":
token = request.args.get('token', request.form.get('token', False))
json_config = {"token": token}
Expand All @@ -422,7 +424,7 @@ def get_operation_by_id():
@verify_user
def get_all_changes():
op_id = request.args.get('op_id', request.form.get('op_id', None))
named_version = request.args.get('named_version')
named_version = request.args.get('named_version') == "True"
user = g.user
result = fm.get_all_changes(int(op_id), user, named_version)
if result is False:
Expand Down Expand Up @@ -465,8 +467,9 @@ def authorized_users():
@APP.route('/operations', methods=['GET'])
@verify_user
def get_operations():
skip_archived = (request.args.get('skip_archived', request.form.get('skip_archived', "False")) == "True")
user = g.user
return json.dumps({"operations": fm.list_operations(user)})
return json.dumps({"operations": fm.list_operations(user, skip_archived=skip_archived)})


@APP.route('/delete_operation', methods=["POST"])
Expand Down
3 changes: 2 additions & 1 deletion mslib/mscolab/sockets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from mslib.mscolab.utils import get_session_id
from mslib.mscolab.conf import mscolab_settings

socketio = SocketIO(cors_allowed_origins=("*" if not hasattr(mscolab_settings, "CORS_ORIGINS") or
socketio = SocketIO(logger=mscolab_settings.SOCKETIO_LOGGER, engineio_logger=mscolab_settings.ENGINEIO_LOGGER,
cors_allowed_origins=("*" if not hasattr(mscolab_settings, "CORS_ORIGINS") or
"*" in mscolab_settings.CORS_ORIGINS else mscolab_settings.CORS_ORIGINS))


Expand Down
5 changes: 2 additions & 3 deletions mslib/msui/kmloverlay_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add_point(self, point, style, name):
:param point: fastkml object specifying point
:param name: name of placemark for annotation
"""
x, y = (point.geometry.x, point.geometry.y)
x, y = self.map(point.geometry.x, point.geometry.y)
self.patches.append(self.map.plot(x, y, "o", zorder=10, color=self.color))
if name is not None:
self.patches.append([self.map.ax.annotate(
Expand Down Expand Up @@ -107,8 +107,7 @@ def add_multipoint(self, geoms, style, name):
:param point: fastkml object specifying point
:param name: name of placemark for annotation
"""
xs = [point.x for point in geoms]
ys = [point.y for point in geoms]
xs, ys = self.map([point.x for point in geoms], [point.y for point in geoms])
self.patches.append(self.map.plot(xs, ys, "o", zorder=10, color=self.color))
if name is not None:
self.patches.append([self.map.ax.annotate(
Expand Down
25 changes: 15 additions & 10 deletions mslib/msui/mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ def after_login(self, emailid, url, r):
self.ui.connectBtn.hide()
self.ui.openOperationsGb.show()
# display connection status
self.ui.mscStatusLabel.setText(self.ui.tr(f"Status: connected to '{self.mscolab_server_url}'"))
transport_layer = self.conn.sio.transport()
self.ui.mscStatusLabel.setText(self.ui.tr(
f"Status: connected to '{self.mscolab_server_url}' by transport layer '{transport_layer}'"))
# display username beside useroptions toolbutton
self.ui.usernameLabel.setText(f"{self.user['username']}")
self.ui.usernameLabel.show()
Expand Down Expand Up @@ -888,8 +890,10 @@ def get_recent_op_id(self):
"""
get most recent operation's op_id
"""
skip_archived = config_loader(dataset="MSCOLAB_skip_archived_operations")
data = {
"token": self.token
"token": self.token,
"skip_archived": skip_archived
}
r = requests.get(self.mscolab_server_url + '/operations', data=data)
if r.text != "False":
Expand Down Expand Up @@ -1535,8 +1539,10 @@ def add_operations_to_ui(self):
logging.debug('add_operations_to_ui')
r = None
if verify_user_token(self.mscolab_server_url, self.token):
skip_archived = config_loader(dataset="MSCOLAB_skip_archived_operations")
data = {
"token": self.token
"token": self.token,
"skip_archived": skip_archived
}
r = requests.get(f'{self.mscolab_server_url}/operations', data=data,
timeout=tuple(config_loader(dataset="MSCOLAB_timeout")))
Expand Down Expand Up @@ -1829,6 +1835,7 @@ def reload_wps_from_server(self):
self.reload_view_windows()

def handle_waypoints_changed(self):
logging.debug("handle_waypoints_changed")
if verify_user_token(self.mscolab_server_url, self.token):
if self.ui.workLocallyCheckbox.isChecked():
self.waypoints_model.save_to_ftml(self.local_ftml_file)
Expand Down Expand Up @@ -1856,6 +1863,7 @@ def reload_view_windows(self):
logging.error("%s" % err)

def handle_import_msc(self, file_path, extension, function, pickertype):
logging.debug("handle_import_msc")
if verify_user_token(self.mscolab_server_url, self.token):
if self.active_op_id is None:
return
Expand All @@ -1878,21 +1886,18 @@ def handle_import_msc(self, file_path, extension, function, pickertype):
model = ft.WaypointsTableModel(waypoints=new_waypoints)
xml_doc = self.waypoints_model.get_xml_doc()
xml_content = xml_doc.toprettyxml(indent=" ", newl="\n")
self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
self.waypoints_model.dataChanged.disconnect(self.handle_waypoints_changed)
self.waypoints_model = model
if self.ui.workLocallyCheckbox.isChecked():
self.waypoints_model.save_to_ftml(self.local_ftml_file)
self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
else:
self.conn.save_file(self.token, self.active_op_id, xml_content, comment=None)
self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
self.handle_waypoints_changed()
self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
self.reload_view_windows()
show_popup(self.ui, "Import Success", f"The file - {file_name}, was imported successfully!", 1)
else:
show_popup(self.ui, "Error", "Your Connection is expired. New Login required!")
self.logout()

def handle_export_msc(self, extension, function, pickertype):
logging.debug("handle_export_msc")
if verify_user_token(self.mscolab_server_url, self.token):
if self.active_op_id is None:
return
Expand Down
7 changes: 3 additions & 4 deletions mslib/msui/mscolab_version_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import json

import requests
from urllib.parse import urljoin
from werkzeug.urls import url_encode
from urllib.parse import urljoin, urlencode

from mslib.utils.verify_user_token import verify_user_token
from mslib.msui.flighttrack import WaypointsTableModel
Expand Down Expand Up @@ -134,10 +133,10 @@ def load_all_changes(self):
"token": self.token,
"op_id": self.op_id
}
named_version_only = None
named_version_only = False
if self.versionFilterCB.currentIndex() == 0:
named_version_only = True
query_string = url_encode({"named_version": named_version_only})
query_string = urlencode({"named_version": named_version_only})
url_path = f'get_all_changes?{query_string}'
url = urljoin(self.mscolab_server_url, url_path)
r = requests.get(url, data=data, timeout=tuple(config_loader(dataset="MSCOLAB_timeout")))
Expand Down
11 changes: 9 additions & 2 deletions mslib/msui/multiple_flightpath_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import mslib.msui.msui_mainwindow as msui_mainwindow
from mslib.utils.verify_user_token import verify_user_token
from mslib.utils.qt import Worker
from mslib.utils.config import config_loader


class QMscolabOperationsListWidgetItem(QtWidgets.QListWidgetItem):
Expand Down Expand Up @@ -113,7 +114,7 @@ class MultipleFlightpathControlWidget(QtWidgets.QWidget, ui.Ui_MultipleViewWidge
signal_parent_closes = QtCore.pyqtSignal()

def __init__(self, parent=None, view=None, listFlightTracks=None,
listOperationsMSC=None, activeFlightTrack=None, mscolab_server_url=None, token=None):
listOperationsMSC=None, category=None, activeFlightTrack=None, mscolab_server_url=None, token=None):
super().__init__(parent)
# ToDO: Remove all patches, on closing dockwidget.
self.ui = parent
Expand All @@ -122,6 +123,7 @@ def __init__(self, parent=None, view=None, listFlightTracks=None,
self.flight_path = None # flightpath object
self.dict_flighttrack = {} # Dictionary of flighttrack data: patch,color,wp_model
self.active_flight_track = activeFlightTrack
self.msc_category = category # object of active category
self.listOperationsMSC = listOperationsMSC
self.listFlightTracks = listFlightTracks
self.mscolab_server_url = mscolab_server_url
Expand Down Expand Up @@ -548,13 +550,18 @@ def set_flag(self):

def get_wps_from_server(self):
operations = {}
skip_archived = config_loader(dataset="MSCOLAB_skip_archived_operations")
data = {
"token": self.token
"token": self.token,
"skip_archived": skip_archived
}
r = requests.get(self.mscolab_server_url + "/operations", data=data, timeout=(2, 10))
if r.text != "False":
_json = json.loads(r.text)
operations = _json["operations"]
selected_category = self.parent.msc_category.currentText()
if selected_category != "*ANY*":
operations = [op for op in operations if op['category'] == selected_category]
return operations

def request_wps_from_server(self, op_id):
Expand Down
1 change: 1 addition & 0 deletions mslib/msui/topview.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def openTool(self, index):
widget = mf.MultipleFlightpathControlWidget(parent=self, view=self.mpl.canvas,
listFlightTracks=self.ui.listFlightTracks,
listOperationsMSC=self.ui.listOperationsMSC,
category=self.ui.filterCategoryCb,
activeFlightTrack=self.active_flighttrack,
mscolab_server_url=self.mscolab_server_url,
token=self.token)
Expand Down
4 changes: 4 additions & 0 deletions mslib/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class MSUIDefaultConfig:
# timeout for MSColab in seconds. First value is for connection, second for reply
MSCOLAB_timeout = [2, 10]

# don't query for archived operations
MSCOLAB_skip_archived_operations = False

# list of MSC servers {"http://www.your-mscolab-server.de": "authuser",
# "http://www.your-wms-server.de": "authuser"}
MSS_auth = {}
Expand Down Expand Up @@ -242,6 +245,7 @@ class MSUIDefaultConfig:
'num_interpolation_points',
'new_flighttrack_flightlevel',
'MSCOLAB_category',
'MSCOLAB_skip_archived_operations',
'mscolab_server_url',
'MSCOLAB_auth_user_name',
'wms_cache',
Expand Down
Loading

0 comments on commit 865259c

Please sign in to comment.