Manager command to create an admin user for the environment.

This commit is contained in:
Rebecca Law
2016-01-18 10:56:26 +00:00
parent 56f455fe3a
commit c4e5ab7c77
2 changed files with 26 additions and 1 deletions

View File

@@ -24,5 +24,30 @@ def list_routes():
for rule in sorted(application.url_map.iter_rules(), key=lambda r: r.rule):
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule))
@manager.command
def create_admin_user_service():
"""
Convience method to create a admin user and service
:return: API token for admin service
"""
from app.models import User, Service, Token
from app.dao import tokens_dao, users_dao, services_dao
from flask import current_app
user = User(**{'email_address': current_app.config['ADMIN_USER_EMAIL_ADDRESS']})
users_dao.save_model_user(user)
service = Service(**{'name': 'Notify Service Admin',
'users':[user],
'limit': 1000,
'active': True,
'restricted': True})
services_dao.save_model_service(service)
token = Token(**{'service_id': service.id})
tokens_dao.save_model_token(token)
print('Token: {}'.format(tokens_dao.get_unsigned_token(service.id)))
if __name__ == '__main__':
manager.run()

View File

@@ -12,7 +12,7 @@ class Development(Config):
DEBUG = True
SECRET_KEY = 'secret-key'
DANGEROUS_SALT = 'dangerous-salt'
ADMIN_USER_EMAIL_ADDRESS = 'dev-notify-admin@digital.cabinet-office.gov.uk'
class Test(Config):
DEBUG = True