mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-13 08:42:21 -05:00
Manager command to create an admin user for the environment.
This commit is contained in:
@@ -24,5 +24,30 @@ def list_routes():
|
|||||||
for rule in sorted(application.url_map.iter_rules(), key=lambda r: r.rule):
|
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))
|
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__':
|
if __name__ == '__main__':
|
||||||
manager.run()
|
manager.run()
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Development(Config):
|
|||||||
DEBUG = True
|
DEBUG = True
|
||||||
SECRET_KEY = 'secret-key'
|
SECRET_KEY = 'secret-key'
|
||||||
DANGEROUS_SALT = 'dangerous-salt'
|
DANGEROUS_SALT = 'dangerous-salt'
|
||||||
|
ADMIN_USER_EMAIL_ADDRESS = 'dev-notify-admin@digital.cabinet-office.gov.uk'
|
||||||
|
|
||||||
class Test(Config):
|
class Test(Config):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|||||||
Reference in New Issue
Block a user