From e0c28cbc7d8534ada77f0edcfc333b5af4f48fa5 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 1 Dec 2020 11:17:07 -0500 Subject: [PATCH] Make it easer to start things up. --- crc/api/user.py | 2 ++ example_data.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/crc/api/user.py b/crc/api/user.py index 5992626b..bbd51130 100644 --- a/crc/api/user.py +++ b/crc/api/user.py @@ -70,6 +70,8 @@ def verify_token(token=None): else: # Fall back to a default user if this is not production. g.user = UserModel.query.first() + if not g.user: + raise ApiError("no_user", "You are in development mode, but there are no users in the database. Add one, and it will use it.") token = g.user.encode_auth_token() token_info = UserModel.decode_auth_token(token) return token_info diff --git a/example_data.py b/example_data.py index 57ea5394..41395ee1 100644 --- a/example_data.py +++ b/example_data.py @@ -4,6 +4,7 @@ import os from crc import app, db, session from crc.models.file import CONTENT_TYPES +from crc.models.user import UserModel from crc.models.workflow import WorkflowSpecModel, WorkflowSpecCategoryModel from crc.services.file_service import FileService @@ -20,6 +21,7 @@ class ExampleDataLoader: def load_all(self): self.load_reference_documents() + self.load_default_user() categories = [ WorkflowSpecCategoryModel( @@ -324,6 +326,11 @@ class ExampleDataLoader: content_type=CONTENT_TYPES['xls']) file.close() + def load_default_user(self): + user = UserModel(uid="xxx9x", email="xxx9x@virginia.edu", display_name="Development User") + db.session.add(user) + db.session.commit() + def ldap(): return "x"; def study_info(i): return {"x":"Y"};