-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotes.py
More file actions
62 lines (52 loc) · 2.53 KB
/
notes.py
File metadata and controls
62 lines (52 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from settings import *
from user import checkAccess
from namastox import notes
import json
# GET NOTES LIST of RA
@app.route(f'{url_base}{version}notes/<string:ra_name>',methods=['GET'])
@app.route(f'{url_base}{version}notes/<string:ra_name>/<int:step>',methods=['GET'])
def getNotes(ra_name, step=None):
granted, access_result = checkAccess(ra_name,'read')
if not granted:
return access_result # this is the 403 JSON response
success, data = notes.action_notes(ra_name, step, out='json')
if success:
return json.dumps(data), 200, {'ContentType':'application/json'}
else:
return json.dumps(f'Failed to obtain notes for {ra_name} {step}'), 500, {'ContentType':'application/json'}
@app.route(f'{url_base}{version}note/<string:ra_name>/<string:note_id>',methods=['GET'])
def getNote(ra_name, note_id):
granted, access_result = checkAccess(ra_name,'read')
if not granted:
return access_result # this is the 403 JSON response
success, data = notes.action_note(ra_name, note_id)
if success:
return json.dumps(data), 200, {'ContentType':'application/json'}
else:
return json.dumps(f'Failed to obtain note {note_id} for {ra_name}'), 500 , {'ContentType':'application/json'}
@app.route(f'{url_base}{version}note/<string:ra_name>',methods=['PUT'])
def putNote(ra_name):
granted, access_result = checkAccess(ra_name,'write')
if not granted:
return access_result # this is the 403 JSON response
note = {}
if 'title' in request.form and 'text' in request.form :
note['title'] = request.form['title']
note['text'] = request.form['text']
else:
return json.dumps('No note found'), 500, {'ContentType':'application/json'}
success, data = notes.action_note_add(ra_name, note)
if success:
return json.dumps(data), 200, {'ContentType':'application/json'}
else:
return json.dumps(f'Failed to add note to {ra_name}'), 500, {'ContentType':'application/json'}
@app.route(f'{url_base}{version}note/<string:ra_name>/<string:note_id>',methods=['DELETE'])
def deleteNote(ra_name, note_id):
granted, access_result = checkAccess(ra_name,'write')
if not granted:
return access_result # this is the 403 JSON response
success, data = notes.action_note_delete(ra_name, note_id)
if success:
return json.dumps(data), 200, {'ContentType':'application/json'}
else:
return json.dumps(f'Failed to delete note {note_id} note to {ra_name}'), 500, {'ContentType':'application/json'}