Add switch for admins to get all jobs (of all users)

This commit is contained in:
Patrick Jentsch 2019-08-15 13:33:15 +02:00
parent 4ffb10fd11
commit 99614a56a9

View File

@ -1,6 +1,7 @@
from flask import abort, jsonify from flask import abort, jsonify, request
from flask_login import current_user, login_required from flask_login import current_user, login_required
from . import api from . import api
from ..models import Job
@api.route('/v1.0/corpora') @api.route('/v1.0/corpora')
@ -31,7 +32,15 @@ def corpus(corpus_id):
@login_required @login_required
def jobs(): def jobs():
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, jobs.append({'id': job.id,
'creation_date': job.creation_date.timestamp(), 'creation_date': job.creation_date.timestamp(),
'description': job.description, 'description': job.description,