Skip to content

Commit ae10cb2

Browse files
authored
Merge pull request #1217 from pekrau/devel
Allow API delete of order report
2 parents cf72c30 + 8e3c7c6 commit ae10cb2

12 files changed

+82
-14
lines changed

api_scripts/add_report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
must be provided in the JSON indata, and must therefore be
66
base64-encoded in UTF-8.
77
8-
NOTE: You need to change several upper-case variables.
8+
NOTE: You need to review/change the upper-case variables.
99
1010
NOTE: The third-party 'requests' module is used.
1111
"""

api_scripts/create_order.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API example script: Create an order from a given form.
22
3-
NOTE: You need to change several upper-case variables.
3+
NOTE: You need to review/change the upper-case variables.
44
55
NOTE: The third-party 'requests' module is used.
66
"""

api_scripts/delete_report.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""API example script: Delete a report for an order.
2+
3+
NOTE: You need to review/change the upper-case variables.
4+
5+
NOTE: The third-party 'requests' module is used.
6+
"""
7+
8+
import base64
9+
import json
10+
import os
11+
12+
import requests
13+
14+
# Base URL for your OrderPortal instance.
15+
BASE_URL = "http://localhost:8881/"
16+
17+
# The IUID for the report.
18+
REPORT_IUID = "f753f72504b04186aa5ee03a41fa955e"
19+
20+
API_KEY = os.environ["ORDERPORTAL_API_KEY"]
21+
22+
23+
url = f"{BASE_URL}api/v1/report/{REPORT_IUID}"
24+
headers = {"X-OrderPortal-API-key": API_KEY}
25+
26+
response = requests.delete(url, headers=headers)
27+
assert response.status_code == 204, (response.status_code, response.reason)

api_scripts/edit_order.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API example script: Edit an order; fields, title.
22
3-
NOTE: You need to change several upper-case variables.
3+
NOTE: You need to review/change the upper-case variables.
44
55
NOTE: The third-party 'requests' module is used.
66
"""

api_scripts/edit_report.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""API example script: Edit the content and status of a report for an order.
22
3-
NOTE: The 'order' and 'owner' of the report cannot be edited.
3+
NOTE: You need to review/change the upper-case variables.
44
5-
NOTE: You need to change several upper-case variables.
5+
NOTE: The 'order' and 'owner' of the report cannot be edited.
66
77
NOTE: The third-party 'requests' module is used.
88
"""

api_scripts/get_account.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API example script: Get account data.
22
3-
NOTE: You need to change several upper-case variables.
3+
NOTE: You need to review/change the upper-case variables.
44
55
NOTE: The third-party 'requests' module is used.
66
"""

api_scripts/get_order.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API example script: Get order data.
22
3-
NOTE: You need to change several upper-case variables.
3+
NOTE: You need to review/change the upper-case variables.
44
55
NOTE: The third-party 'requests' module is used.
66
"""

api_scripts/get_reports.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API example script: Get reports for an order.
22
3-
NOTE: You need to change several upper-case variables.
3+
NOTE: You need to review/change the upper-case variables.
44
55
NOTE: The third-party 'requests' module is used.
66
"""
@@ -15,7 +15,7 @@
1515
BASE_URL = "http://localhost:8881"
1616

1717
# The identifier for the order.
18-
ORDER_ID = "OP0032"
18+
ORDER_ID = "OP00013"
1919

2020
API_KEY = os.environ["ORDERPORTAL_API_KEY"]
2121

api_scripts/submit_order.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API example script: Submit the order.
22
3-
NOTE: You need to change several upper-case variables.
3+
NOTE: You need to review/change the upper-case variables.
44
55
NOTE: The third-party 'requests' module is used.
66
"""

orderportal/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pycountry
1111

1212

13-
__version__ = "11.3.7"
13+
__version__ = "11.4.0"
1414

1515

1616
class Constants:

orderportal/documentation.md

+31-3
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,9 @@ status transitions.
719719

720720
### API Add order report
721721

722-
A report for an order can be added by doing a PUT to the order
723-
report URI with the report content file as request body.
722+
A report for an order can be added by doing a POST to the order
723+
report URI with a request body containing the name of the report
724+
and the contents of the report file.
724725

725726
The content type (MIME type) of the data is recorded with the
726727
report. If it is `text/html` or `text/plain`, the content will be
@@ -732,6 +733,31 @@ For an example add report script, see
732733
[add_report.py](https://github.com/pekrau/OrderPortal/blob/master/api_scripts/add_report.py "!").
733734

734735

736+
### API Edit order report
737+
738+
A report for an order can be edited by doing a POST to the order
739+
report URI containing the report UUID, and a request body containing
740+
the name of the report and the contents of the report file.
741+
742+
The content type (MIME type) of the data is recorded with the
743+
report. If it is `text/html` or `text/plain`, the content will be
744+
display in-line in the user's browser. Otherwise the content will be
745+
downloaded as a file to the user's browser when the report button is
746+
clicked.
747+
748+
For an example edit report script, see
749+
[edit_report.py](https://github.com/pekrau/OrderPortal/blob/master/api_scripts/edit_report.py "!").
750+
751+
752+
### API Delete order report
753+
754+
A report for an order can be deleted by doing a DELETE to the order
755+
report URI containing the report UUID. No request body should be used.
756+
757+
For an example delete report script, see
758+
[delete_report.py](https://github.com/pekrau/OrderPortal/blob/master/api_scripts/delete_report.py "!").
759+
760+
735761
## CLI
736762

737763
The Command Line Interface (CLI) allows system various maintenance
@@ -740,6 +766,8 @@ on the command line of the machine which hosts the OrderPortal
740766
instance. This means that only users with accounts of sufficient
741767
privilege on this machine can use it.
742768

769+
$ python3 cli.py --help
770+
743771

744772
# Backup
745773

@@ -813,7 +841,7 @@ The current installation procedure is described in the `README.md` for the
813841

814842
The implementation of Anubis is based on the following design decisions:
815843

816-
- The back-end is written in Python using [tornado](https://pypi.org/project/tornado/ "!").
844+
- The back-end is written in Python 3 using [tornado](https://pypi.org/project/tornado/ "!").
817845
- The back-end generates HTML for display using the tornado template system.
818846
- The front-end uses [Bootstrap](https://getbootstrap.com/docs/3.4/ "!").
819847
- The back-end uses the No-SQL database [CouchDB](https://couchdb.apache.org/ "!").

orderportal/report.py

+13
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,19 @@ def post(self, iuid):
444444
raise tornado.web.HTTPError(400, reason=str(error))
445445
self.write(self.get_report_json(report, self.get_order(report["order"])))
446446

447+
def delete(self, iuid):
448+
try:
449+
self.check_staff()
450+
except ValueError as error:
451+
raise tornado.web.HTTPError(403, reason=str(error))
452+
try:
453+
report = self.get_report(iuid)
454+
except ValueError as error:
455+
raise tornado.web.HTTPError(404, reason=str(error))
456+
self.delete_logs(report["_id"])
457+
self.db.delete(report)
458+
self.set_status(204) # Empty content.
459+
447460

448461
class ReportEdit(ReportMixin, RequestHandler):
449462
"Edit a report for an order."

0 commit comments

Comments
 (0)