Skip to content

Commit

Permalink
introduces a config var to skip archived operations on the server (#1987
Browse files Browse the repository at this point in the history
)

* feature added skip archived operations

* skip_archived implemented for the multiple flightpath docking widget

* flake8

* simplified active check
  • Loading branch information
ReimarBauer authored Sep 3, 2023
1 parent abef5ea commit 56e9528
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 19 deletions.
29 changes: 17 additions & 12 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
7 changes: 5 additions & 2 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 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
8 changes: 6 additions & 2 deletions mslib/msui/mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,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 @@ -1537,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
5 changes: 4 additions & 1 deletion 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 @@ -549,8 +550,10 @@ 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":
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
25 changes: 25 additions & 0 deletions tests/_test_mscolab/test_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,31 @@ def test_list_operations(self):
'path': 'second'}]
assert self.fm.list_operations(self.user) == expected_result

def test_list_operations_skip_archived(self):
with self.app.test_client():
self.fm.create_operation("first", "info about first", self.user, active=False)
self.fm.create_operation("second", "info about second", self.user)
expected_result_all = [{'access_level': 'creator',
'active': False,
'category': 'default',
'description': 'info about first',
'op_id': 1,
'path': 'first'},
{'access_level': 'creator',
'active': True,
'category': 'default',
'description': 'info about second',
'op_id': 2,
'path': 'second'}]
expected_result_skipped_true = [{'access_level': 'creator',
'active': True,
'category': 'default',
'description': 'info about second',
'op_id': 2,
'path': 'second'}]
assert self.fm.list_operations(self.user, skip_archived=False) == expected_result_all
assert self.fm.list_operations(self.user, skip_archived=True) == expected_result_skipped_true

def test_is_creator(self):
with self.app.test_client():
flight_path, operation = self._create_operation(flight_path='third')
Expand Down
24 changes: 22 additions & 2 deletions tests/_test_mscolab/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ def test_create_operation(self):
with self.app.test_client() as test_client:
operation, token = self._create_operation(test_client, self.userdata)
assert operation is not None
assert operation.active is True
assert token is not None
operation, token = self._create_operation(test_client,
self.userdata, path="archived_operation", active=False)
assert operation is not None
assert operation.active is False
assert token is not None

def test_get_operation_by_id(self):
Expand All @@ -227,6 +233,19 @@ def test_get_operations(self):
assert data["operations"][0]["path"] == "firstflightpath1"
assert data["operations"][1]["path"] == "firstflightpath2"

def test_get_operations_skip_archived(self):
assert add_user(self.userdata[0], self.userdata[1], self.userdata[2])
with self.app.test_client() as test_client:
self._create_operation(test_client, self.userdata, path="firstflightpath1")
operation, token = self._create_operation(test_client, self.userdata, path="firstflightpath2", active=False)
response = test_client.get('/operations', data={"token": token,
"skip_archived": "True"})
assert response.status_code == 200
data = json.loads(response.data.decode('utf-8'))
assert len(data["operations"]) == 1
assert data["operations"][0]["path"] == "firstflightpath1"
assert "firstflightpath2" not in data["operations"]

def test_get_all_changes(self):
assert add_user(self.userdata[0], self.userdata[1], self.userdata[2])
with self.app.test_client() as test_client:
Expand Down Expand Up @@ -383,15 +402,16 @@ def test_import_permissions(self):
# creator is not listed
assert data["success"] is True

def _create_operation(self, test_client, userdata=None, path="firstflight", description="simple test"):
def _create_operation(self, test_client, userdata=None, path="firstflight", description="simple test", active=True):
if userdata is None:
userdata = self.userdata
response = test_client.post('/token', data={"email": userdata[0], "password": userdata[2]})
data = json.loads(response.data.decode('utf-8'))
token = data["token"]
response = test_client.post('/create_operation', data={"token": token,
"path": path,
"description": description})
"description": description,
"active": str(active)})
assert response.status_code == 200
assert response.data.decode('utf-8') == "True"
operation = Operation.query.filter_by(path=path).first()
Expand Down

0 comments on commit 56e9528

Please sign in to comment.