From 99614a56a9315d049a9992996625daa8d40bf485 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Thu, 15 Aug 2019 13:33:15 +0200
Subject: [PATCH] Add switch for admins to get all jobs (of all users)
---
app/api/views.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/app/api/views.py b/app/api/views.py
index 0555155b..eb86d105 100644
--- a/app/api/views.py
+++ b/app/api/views.py
@@ -1,6 +1,7 @@
-from flask import abort, jsonify
+from flask import abort, jsonify, request
from flask_login import current_user, login_required
from . import api
+from ..models import Job
@api.route('/v1.0/corpora')
@@ -31,7 +32,15 @@ def corpus(corpus_id):
@login_required
def jobs():
jobs = []
- for job in current_user.jobs.all():
+ all = request.args.get('all')
+ if all and all.lower() == 'true':
+ if current_user.is_administrator():
+ jobs_query = Job.query
+ else:
+ return abort(403)
+ else:
+ jobs_query = current_user.jobs
+ for job in jobs_query.all():
jobs.append({'id': job.id,
'creation_date': job.creation_date.timestamp(),
'description': job.description,