Requires login

This commit is contained in:
Aaron Louie 2020-03-11 15:27:22 -04:00
parent e977ee9e0d
commit 3262833102
6 changed files with 22 additions and 8 deletions

View File

@ -2,16 +2,18 @@ from datetime import datetime
from flask import g
from crc import session
from crc import session, auth
from crc.models.stats import WorkflowStatsModel, WorkflowStatsModelSchema, TaskEventModel, TaskEventModelSchema
@auth.login_required
def get_workflow_stats(workflow_id):
schema = WorkflowStatsModelSchema()
workflow_model = session.query(WorkflowStatsModel).filter_by(id=workflow_id).first()
return schema.dump(workflow_model)
@auth.login_required
def update_workflow_stats(workflow_model, workflow_api_model):
stats = session.query(WorkflowStatsModel) \
.filter_by(study_id=workflow_model.study_id) \
@ -41,6 +43,7 @@ def update_workflow_stats(workflow_model, workflow_api_model):
return WorkflowStatsModelSchema().dump(stats)
@auth.login_required
def log_task_complete(workflow_model, task_id):
task_event = TaskEventModel(
study_id=workflow_model.study_id,

View File

@ -33,7 +33,6 @@ def add_study(body):
return StudyModelSchema().dump(study)
@auth.login_required
def update_study(study_id, body):
if study_id is None:

View File

@ -1,7 +1,7 @@
import uuid
from crc.api.stats import update_workflow_stats, log_task_complete
from crc import session
from crc import session, auth
from crc.api.common import ApiError, ApiErrorSchema
from crc.api.file import delete_file
from crc.models.api_models import Task, WorkflowApi, WorkflowApiSchema
@ -15,6 +15,7 @@ def all_specifications():
return schema.dump(session.query(WorkflowSpecModel).all())
@auth.login_required
def add_workflow_specification(body):
new_spec = WorkflowSpecModelSchema().load(body, session=session)
session.add(new_spec)
@ -22,6 +23,7 @@ def add_workflow_specification(body):
return WorkflowSpecModelSchema().dump(new_spec)
@auth.login_required
def get_workflow_specification(spec_id):
if spec_id is None:
error = ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.')
@ -36,6 +38,7 @@ def get_workflow_specification(spec_id):
return WorkflowSpecModelSchema().dump(spec)
@auth.login_required
def update_workflow_specification(spec_id, body):
spec = WorkflowSpecModelSchema().load(body, session=session)
spec.id = spec_id
@ -44,6 +47,7 @@ def update_workflow_specification(spec_id, body):
return WorkflowSpecModelSchema().dump(spec)
@auth.login_required
def delete_workflow_specification(spec_id):
if spec_id is None:
error = ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.')
@ -83,6 +87,7 @@ def __get_workflow_api_model(processor: WorkflowProcessor):
return workflow_api
@auth.login_required
def get_workflow(workflow_id, soft_reset=False, hard_reset=False):
workflow_model = session.query(WorkflowModel).filter_by(id=workflow_id).first()
processor = WorkflowProcessor(workflow_model, soft_reset=soft_reset, hard_reset=hard_reset)
@ -92,16 +97,19 @@ def get_workflow(workflow_id, soft_reset=False, hard_reset=False):
return WorkflowApiSchema().dump(workflow_api_model)
@auth.login_required
def delete(workflow_id):
session.query(WorkflowModel).filter_by(id=workflow_id).delete()
session.commit()
@auth.login_required
def get_task(workflow_id, task_id):
workflow = session.query(WorkflowModel).filter_by(id=workflow_id).first()
return workflow.bpmn_workflow().get_task(task_id)
@auth.login_required
def update_task(workflow_id, task_id, body):
workflow_model = session.query(WorkflowModel).filter_by(id=workflow_id).first()
processor = WorkflowProcessor(workflow_model)

View File

@ -174,7 +174,7 @@ class TestStudyApi(BaseTest):
self.assertEqual(1, session.query(WorkflowModel).count())
json_data = json.loads(rv.get_data(as_text=True))
workflow = WorkflowApiSchema().load(json_data)
rv = self.app.delete('/v1.0/workflow/%i' % workflow.id)
rv = self.app.delete('/v1.0/workflow/%i' % workflow.id, headers=self.logged_in_headers())
self.assert_success(rv)
self.assertEqual(0, session.query(WorkflowModel).count())

View File

@ -29,6 +29,7 @@ class TestTasksApi(BaseTest):
def get_workflow_api(self, workflow, soft_reset=False, hard_reset=False):
rv = self.app.get('/v1.0/workflow/%i?soft_reset=%s&hard_reset=%s' %
(workflow.id, str(soft_reset), str(hard_reset)),
headers=self.logged_in_headers(),
content_type="application/json")
json_data = json.loads(rv.get_data(as_text=True))
workflow_api = WorkflowApiSchema().load(json_data)
@ -37,6 +38,7 @@ class TestTasksApi(BaseTest):
def complete_form(self, workflow, task, dict_data):
rv = self.app.put('/v1.0/workflow/%i/task/%s/data' % (workflow.id, task.id),
headers=self.logged_in_headers(),
content_type="application/json",
data=json.dumps(dict_data))
self.assert_success(rv)
@ -158,7 +160,7 @@ class TestTasksApi(BaseTest):
self.assertIsNotNone(workflow_api.next_task)
self.assertEquals("EndEvent_0evb22x", workflow_api.next_task['name'])
self.assertTrue(workflow_api.status == WorkflowStatus.complete)
rv = self.app.get('/v1.0/file?workflow_id=%i' % workflow.id)
rv = self.app.get('/v1.0/file?workflow_id=%i' % workflow.id, headers=self.logged_in_headers())
self.assert_success(rv)
json_data = json.loads(rv.get_data(as_text=True))
files = FileModelSchema(many=True).load(json_data, session=session)

View File

@ -27,7 +27,9 @@ class TestWorkflowSpec(BaseTest):
num_before = session.query(WorkflowSpecModel).count()
spec = WorkflowSpecModel(id='make_cookies', display_name='Cooooookies',
description='Om nom nom delicious cookies')
rv = self.app.post('/v1.0/workflow-specification', content_type="application/json",
rv = self.app.post('/v1.0/workflow-specification',
headers=self.logged_in_headers(),
content_type="application/json",
data=json.dumps(WorkflowSpecModelSchema().dump(spec)))
self.assert_success(rv)
db_spec = session.query(WorkflowSpecModel).filter_by(id='make_cookies').first()
@ -38,7 +40,7 @@ class TestWorkflowSpec(BaseTest):
def test_get_workflow_specification(self):
self.load_example_data()
db_spec = session.query(WorkflowSpecModel).first()
rv = self.app.get('/v1.0/workflow-specification/%s' % db_spec.id)
rv = self.app.get('/v1.0/workflow-specification/%s' % db_spec.id, headers=self.logged_in_headers())
self.assert_success(rv)
json_data = json.loads(rv.get_data(as_text=True))
api_spec = WorkflowSpecModelSchema().load(json_data, session=session)
@ -55,7 +57,7 @@ class TestWorkflowSpec(BaseTest):
num_workflows_before = session.query(WorkflowModel).filter_by(workflow_spec_id=spec_id).count()
self.assertGreater(num_files_before + num_workflows_before, 0)
rv = self.app.delete('/v1.0/workflow-specification/' + spec_id)
rv = self.app.delete('/v1.0/workflow-specification/' + spec_id, headers=self.logged_in_headers())
self.assert_success(rv)
num_specs_after = session.query(WorkflowSpecModel).filter_by(id=spec_id).count()