forked from bcgov/queue-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* This commit contains working and generally finished (all questions are asked in the right order for the correct process with correct required/minLength/numeric enforecements E&OE). Both the capture Individual and the capture Group workflows are working. For working on wiring to the API. * Added create individual and group exams API calls, and status call to stream files * Clean up directory * Added download and transfer document to BCMP * All changes for SBC Managed, individual pesticide exams * Fix migration file * Test * Fixed bug with exam inventory * Fixed bugs with examinee email and phone * Finished everything for individual exams * Cleanup for everything with group exams Co-authored-by: Scott Rumsby <[email protected]>
- Loading branch information
1 parent
b068b17
commit dc9e54f
Showing
52 changed files
with
3,582 additions
and
1,071 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'''Copyright 2018 Province of British Columbia | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.''' | ||
|
||
import logging | ||
from flask import g | ||
from flask_restplus import Resource | ||
from sqlalchemy import exc | ||
from app.models.bookings import Exam | ||
from app.models.theq import CSR | ||
from app.utilities.bcmp_service import BCMPService | ||
from qsystem import api, oidc | ||
|
||
|
||
@api.route("/exams/bcmp_status/", methods=["POST"]) | ||
class ExamList(Resource): | ||
bcmp_service = BCMPService() | ||
|
||
@oidc.accept_token(require_token=True) | ||
def post(self): | ||
csr = CSR.find_by_username(g.oidc_token_info['username']) | ||
|
||
try: | ||
exams = Exam.query.filter_by(upload_received_ind=0).filter(Exam.bcmp_job_id.isnot(None)) | ||
self.bcmp_service.bulk_check_exam_status(exams) | ||
|
||
return {}, 200 | ||
|
||
except exc.SQLAlchemyError as error: | ||
logging.error(error, exc_info=True) | ||
return {'message': 'API is down'}, 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'''Copyright 2018 Province of British Columbia | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.''' | ||
|
||
from flask import g, Response | ||
from flask_restplus import Resource | ||
import io | ||
import logging | ||
import urllib | ||
from werkzeug.wsgi import FileWrapper | ||
from sqlalchemy import exc | ||
from app.models.theq import CSR | ||
from app.models.bookings import Exam | ||
from app.utilities.bcmp_service import BCMPService | ||
from qsystem import api, oidc | ||
|
||
|
||
@api.route("/exams/<int:exam_id>/download/", methods=["GET"]) | ||
class ExamStatus(Resource): | ||
bcmp_service = BCMPService() | ||
|
||
@oidc.accept_token(require_token=True) | ||
def get(self, exam_id): | ||
|
||
csr = CSR.find_by_username(g.oidc_token_info['username']) | ||
|
||
try: | ||
exam = Exam.query.filter_by(exam_id=exam_id).first() | ||
|
||
if not (exam.office_id == csr.office_id or csr.liaison_designate == 1): | ||
return {"The Exam Office ID and CSR Office ID do not match!"}, 403 | ||
|
||
status = self.bcmp_service.check_exam_status(exam) | ||
print(status) | ||
|
||
if status == 'PACKAGE_GENERATED': | ||
package_url = status["jobProperties"]["EXAM_PACKAGE_URL"] | ||
req = urllib.request.Request(package_url) | ||
response = urllib.request.urlopen(req).read() | ||
exam_file = io.BytesIO(response) | ||
file_wrapper = FileWrapper(exam_file) | ||
|
||
return Response(file_wrapper, | ||
mimetype="application/pdf", | ||
direct_passthrough=True, | ||
headers={ | ||
"Content-Disposition": 'attachment; filename="%s.csv"' % exam.exam_id, | ||
"Content-Type": "application/pdf" | ||
}) | ||
else: | ||
return {'message': 'API is down'}, 400 | ||
# test_url = 'http://www.pdf995.com/samples/pdf.pdf' | ||
# req = urllib.request.Request(test_url) | ||
# response = urllib.request.urlopen(req).read() | ||
# exam_file = io.BytesIO(response) | ||
# file_wrapper = FileWrapper(exam_file) | ||
# | ||
# return Response(file_wrapper, | ||
# mimetype="application/pdf", | ||
# direct_passthrough=True, | ||
# headers={ | ||
# "Content-Disposition": 'attachment; filename="%s.csv"' % exam.exam_id, | ||
# "Content-Type": "application/pdf" | ||
# }) | ||
|
||
except exc.SQLAlchemyError as error: | ||
logging.error(error, exc_info=True) | ||
return {'message': 'API is down'}, 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'''Copyright 2018 Province of British Columbia | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.''' | ||
|
||
from flask import g, request | ||
from flask_restplus import Resource | ||
import logging | ||
from sqlalchemy import exc | ||
from app.models.theq import CSR | ||
from app.models.bookings import Exam | ||
from app.utilities.bcmp_service import BCMPService | ||
from qsystem import api, db, oidc | ||
|
||
|
||
@api.route("/exams/<int:exam_id>/email_invigilator/", methods=["POST"]) | ||
class ExamEmailInvigilator(Resource): | ||
bcmp_service = BCMPService() | ||
|
||
@oidc.accept_token(require_token=True) | ||
def post(self, exam_id): | ||
|
||
csr = CSR.find_by_username(g.oidc_token_info['username']) | ||
|
||
try: | ||
exam = Exam.query.filter_by(exam_id=exam_id).first() | ||
|
||
if not (exam.office_id == csr.office_id or csr.liaison_designate == 1): | ||
return {"The Exam Office ID and CSR Office ID do not match!"}, 403 | ||
|
||
json_data = request.get_json() | ||
invigilator_id = json_data["invigilator_id"] | ||
invigilator_name = json_data["invigilator_name"] | ||
invigilator_email = json_data["invigilator_email"] | ||
invigilator_phone = json_data["invigilator_phone"] | ||
|
||
if not invigilator_email or not invigilator_phone or not invigilator_name: | ||
return {"Invigilator name, email, and phone number are required"}, 422 | ||
|
||
response = self.bcmp_service.email_exam_invigilator( | ||
exam, | ||
invigilator_name, | ||
invigilator_email, | ||
invigilator_phone | ||
) | ||
|
||
if response: | ||
exam.invigilator_id = invigilator_id | ||
db.session.add(exam) | ||
db.session.commit() | ||
return {}, 200 | ||
else: | ||
return {}, 500 | ||
|
||
except exc.SQLAlchemyError as error: | ||
logging.error(error, exc_info=True) | ||
return {'message': 'API is down'}, 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'''Copyright 2018 Province of British Columbia | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.''' | ||
|
||
from flask import g | ||
from flask_restplus import Resource | ||
import logging | ||
from sqlalchemy import exc | ||
from app.models.theq import CSR | ||
from app.models.bookings import Exam | ||
from app.utilities.bcmp_service import BCMPService | ||
from qsystem import api, oidc | ||
|
||
|
||
@api.route("/exams/<int:exam_id>/transfer/", methods=["POST"]) | ||
class ExamStatus(Resource): | ||
bcmp_service = BCMPService() | ||
|
||
@oidc.accept_token(require_token=True) | ||
def post(self, exam_id): | ||
|
||
csr = CSR.find_by_username(g.oidc_token_info['username']) | ||
|
||
try: | ||
exam = Exam.query.filter_by(exam_id=exam_id).first() | ||
|
||
if not (exam.office_id == csr.office_id or csr.liaison_designate == 1): | ||
return {"The Exam Office ID and CSR Office ID do not match!"}, 403 | ||
|
||
self.bcmp_service.send_exam_to_bcmp(exam) | ||
return {} | ||
|
||
except exc.SQLAlchemyError as error: | ||
logging.error(error, exc_info=True) | ||
return {'message': 'API is down'}, 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'''Copyright 2018 Province of British Columbia | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.''' | ||
|
||
from flask import g, request | ||
from flask_restplus import Resource | ||
import logging | ||
from sqlalchemy import exc | ||
from app.models.theq import CSR | ||
from app.models.bookings import Exam | ||
from app.utilities.document_service import DocumentService | ||
from qsystem import api, application, oidc | ||
|
||
|
||
@api.route("/exams/<int:exam_id>/upload/", methods=["GET"]) | ||
class ExamStatus(Resource): | ||
|
||
@oidc.accept_token(require_token=True) | ||
def get(self, exam_id): | ||
csr = CSR.find_by_username(g.oidc_token_info['username']) | ||
|
||
try: | ||
exam = Exam.query.filter_by(exam_id=exam_id).first() | ||
|
||
if not (exam.office_id == csr.office_id or csr.liaison_designate == 1): | ||
return {"The Exam Office ID and CSR Office ID do not match!"}, 403 | ||
client = DocumentService( | ||
application.config["MINIO_HOST"], | ||
application.config["MINIO_BUCKET"], | ||
application.config["MINIO_ACCESS_KEY"], | ||
application.config["MINIO_SECRET_KEY"], | ||
application.config["MINIO_USE_SECURE"] | ||
) | ||
|
||
object_name = "%s.pdf" % exam_id | ||
url = client.get_presigned_put_url(object_name) | ||
|
||
return {"url": url} | ||
|
||
except exc.SQLAlchemyError as error: | ||
logging.error(error, exc_info=True) | ||
return {'message': 'API is down'}, 500 |
Oops, something went wrong.