From 93330c0efb1bffcbbd846e52861ba96e361e6beb Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Thu, 15 Aug 2019 11:48:14 +0200
Subject: [PATCH] Remove api routes from main package.
---
app/main/views.py | 54 +++++++----------------------------------------
1 file changed, 8 insertions(+), 46 deletions(-)
diff --git a/app/main/views.py b/app/main/views.py
index 18585dc9..024e74fb 100644
--- a/app/main/views.py
+++ b/app/main/views.py
@@ -1,52 +1,15 @@
-from flask import abort, current_app, flash, jsonify, redirect, request, render_template, url_for, send_from_directory
+from flask import (abort, current_app, flash, redirect, request,
+ render_template, url_for, send_from_directory)
from flask_login import current_user, login_required
-from ..models import Corpus, User, Job
+from ..models import Corpus, User
from ..tables import AdminUserTable, AdminUserItem
from . import main
from .forms import CreateCorpusForm
from ..decorators import admin_required
from .. import db
-import json
import os
-@main.route('/api/v1.0/corpora')
-@login_required
-def api_corpora():
- corpora = []
- for corpus in current_user.corpora.all():
- corpora.append({'id': corpus.id,
- 'creation_date': corpus.creation_date.timestamp(),
- 'description': corpus.description,
- 'title': corpus.title})
- return jsonify(corpora)
-
-
-@main.route('/api/v1.0/corpora/')
-@login_required
-def api_corpus():
- corpus = []
-
-
-@main.route('/api/v1.0/jobs')
-@login_required
-def api_jobs():
- jobs = []
- for job in current_user.jobs.all():
- jobs.append({'id': job.id,
- 'creation_date': job.creation_date.timestamp(),
- 'description': job.description,
- 'end_date': job.end_date.timestamp() if job.end_date else None,
- 'mem_mb': job.mem_mb,
- 'n_cores': job.n_cores,
- 'service': job.service,
- 'service_args': job.service_args,
- 'service_version': job.service_version,
- 'status': job.status,
- 'title': job.title})
- return jsonify(jobs)
-
-
@main.route('/')
def index():
return render_template('main/index.html.j2', title='Opaque')
@@ -159,15 +122,14 @@ def job(job_id):
@login_required
def job_download(job_id):
file = request.args.get('file')
- job = Job.query.filter_by(id=job_id).first()
+ job = current_user.jobs.filter_by(id=job_id).first()
if not file or not job:
- print('Job not found.')
+ print('File not found.')
abort(404)
- elif not job.user_id == current_user.id:
- print('Job does not belong to current user.')
- abort(403)
dir = os.path.join(current_app.config['OPAQUE_STORAGE'],
str(current_user.id),
'jobs',
str(job.id))
- return send_from_directory(directory=dir, filename=file, as_attachment=True)
+ return send_from_directory(as_attachment=True,
+ directory=dir,
+ filename=file)