Skip to content

Commit

Permalink
Merge pull request #1217 from pekrau/devel
Browse files Browse the repository at this point in the history
Allow API delete of order report
  • Loading branch information
pekrau authored Oct 28, 2023
2 parents cf72c30 + 8e3c7c6 commit ae10cb2
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api_scripts/add_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
must be provided in the JSON indata, and must therefore be
base64-encoded in UTF-8.
NOTE: You need to change several upper-case variables.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""
Expand Down
2 changes: 1 addition & 1 deletion api_scripts/create_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""API example script: Create an order from a given form.
NOTE: You need to change several upper-case variables.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""
Expand Down
27 changes: 27 additions & 0 deletions api_scripts/delete_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""API example script: Delete a report for an order.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""

import base64
import json
import os

import requests

# Base URL for your OrderPortal instance.
BASE_URL = "http://localhost:8881/"

# The IUID for the report.
REPORT_IUID = "f753f72504b04186aa5ee03a41fa955e"

API_KEY = os.environ["ORDERPORTAL_API_KEY"]


url = f"{BASE_URL}api/v1/report/{REPORT_IUID}"
headers = {"X-OrderPortal-API-key": API_KEY}

response = requests.delete(url, headers=headers)
assert response.status_code == 204, (response.status_code, response.reason)
2 changes: 1 addition & 1 deletion api_scripts/edit_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""API example script: Edit an order; fields, title.
NOTE: You need to change several upper-case variables.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""
Expand Down
4 changes: 2 additions & 2 deletions api_scripts/edit_report.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""API example script: Edit the content and status of a report for an order.
NOTE: The 'order' and 'owner' of the report cannot be edited.
NOTE: You need to review/change the upper-case variables.
NOTE: You need to change several upper-case variables.
NOTE: The 'order' and 'owner' of the report cannot be edited.
NOTE: The third-party 'requests' module is used.
"""
Expand Down
2 changes: 1 addition & 1 deletion api_scripts/get_account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""API example script: Get account data.
NOTE: You need to change several upper-case variables.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""
Expand Down
2 changes: 1 addition & 1 deletion api_scripts/get_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""API example script: Get order data.
NOTE: You need to change several upper-case variables.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""
Expand Down
4 changes: 2 additions & 2 deletions api_scripts/get_reports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""API example script: Get reports for an order.
NOTE: You need to change several upper-case variables.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""
Expand All @@ -15,7 +15,7 @@
BASE_URL = "http://localhost:8881"

# The identifier for the order.
ORDER_ID = "OP0032"
ORDER_ID = "OP00013"

API_KEY = os.environ["ORDERPORTAL_API_KEY"]

Expand Down
2 changes: 1 addition & 1 deletion api_scripts/submit_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""API example script: Submit the order.
NOTE: You need to change several upper-case variables.
NOTE: You need to review/change the upper-case variables.
NOTE: The third-party 'requests' module is used.
"""
Expand Down
2 changes: 1 addition & 1 deletion orderportal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pycountry


__version__ = "11.3.7"
__version__ = "11.4.0"


class Constants:
Expand Down
34 changes: 31 additions & 3 deletions orderportal/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,9 @@ status transitions.

### API Add order report

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

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


### API Edit order report

A report for an order can be edited by doing a POST to the order
report URI containing the report UUID, and a request body containing
the name of the report and the contents of the report file.

The content type (MIME type) of the data is recorded with the
report. If it is `text/html` or `text/plain`, the content will be
display in-line in the user's browser. Otherwise the content will be
downloaded as a file to the user's browser when the report button is
clicked.

For an example edit report script, see
[edit_report.py](https://github.com/pekrau/OrderPortal/blob/master/api_scripts/edit_report.py "!").


### API Delete order report

A report for an order can be deleted by doing a DELETE to the order
report URI containing the report UUID. No request body should be used.

For an example delete report script, see
[delete_report.py](https://github.com/pekrau/OrderPortal/blob/master/api_scripts/delete_report.py "!").


## CLI

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

$ python3 cli.py --help


# Backup

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

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

- The back-end is written in Python using [tornado](https://pypi.org/project/tornado/ "!").
- The back-end is written in Python 3 using [tornado](https://pypi.org/project/tornado/ "!").
- The back-end generates HTML for display using the tornado template system.
- The front-end uses [Bootstrap](https://getbootstrap.com/docs/3.4/ "!").
- The back-end uses the No-SQL database [CouchDB](https://couchdb.apache.org/ "!").
Expand Down
13 changes: 13 additions & 0 deletions orderportal/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,19 @@ def post(self, iuid):
raise tornado.web.HTTPError(400, reason=str(error))
self.write(self.get_report_json(report, self.get_order(report["order"])))

def delete(self, iuid):
try:
self.check_staff()
except ValueError as error:
raise tornado.web.HTTPError(403, reason=str(error))
try:
report = self.get_report(iuid)
except ValueError as error:
raise tornado.web.HTTPError(404, reason=str(error))
self.delete_logs(report["_id"])
self.db.delete(report)
self.set_status(204) # Empty content.


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

0 comments on commit ae10cb2

Please sign in to comment.