diff --git a/app/models.py b/app/models.py index d437a5427..63fdc7480 100644 --- a/app/models.py +++ b/app/models.py @@ -40,6 +40,7 @@ class User(db.Model): logged_in_at = db.Column(db.DateTime, nullable=True) failed_login_count = db.Column(db.Integer, nullable=False, default=0) state = db.Column(db.String, nullable=False, default='pending') + platform_admin = db.Column(db.Boolean, nullable=False, default=False) @property def password(self): @@ -306,6 +307,7 @@ SEND_EMAILS = 'send_emails' SEND_LETTERS = 'send_letters' MANAGE_API_KEYS = 'manage_api_keys' ACCESS_DEVELOPER_DOCS = 'access_developer_docs' +PLATFORM_ADMIN = 'platform_admin' # List of permissions PERMISSION_LIST = [ @@ -316,7 +318,8 @@ PERMISSION_LIST = [ SEND_EMAILS, SEND_LETTERS, MANAGE_API_KEYS, - ACCESS_DEVELOPER_DOCS] + ACCESS_DEVELOPER_DOCS, + PLATFORM_ADMIN] class Permission(db.Model): diff --git a/migrations/versions/0041_platform_admin.py b/migrations/versions/0041_platform_admin.py new file mode 100644 index 000000000..d75c8f5c0 --- /dev/null +++ b/migrations/versions/0041_platform_admin.py @@ -0,0 +1,33 @@ +"""empty message + +Revision ID: 0041_platform_admin +Revises: 0040_add_reference +Create Date: 2016-03-16 16:33:15.279429 + +""" + +# revision identifiers, used by Alembic. +revision = '0041_platform_admin' +down_revision = '0040_add_reference' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.create_index(op.f('ix_notification_statistics_service_id'), 'notification_statistics', ['service_id'], unique=False) + op.drop_index('ix_service_notification_stats_service_id', table_name='notification_statistics') + op.add_column('users', sa.Column('platform_admin', sa.Boolean(), nullable=True, default=False)) + op.get_bind() + op.execute('update users set platform_admin = False') + op.alter_column('users', 'platform_admin', nullable=False) + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.drop_column('users', 'platform_admin') + op.create_index('ix_service_notification_stats_service_id', 'notification_statistics', ['service_id'], unique=False) + op.drop_index(op.f('ix_notification_statistics_service_id'), table_name='notification_statistics') + ### end Alembic commands ### diff --git a/tests/app/dao/test_users_dao.py b/tests/app/dao/test_users_dao.py index 8f928a954..35dce1b60 100644 --- a/tests/app/dao/test_users_dao.py +++ b/tests/app/dao/test_users_dao.py @@ -32,6 +32,7 @@ def test_create_user(notify_api, notify_db, notify_db_session): assert User.query.count() == 1 assert User.query.first().email_address == email assert User.query.first().id == user.id + assert not user.platform_admin def test_get_all_users(notify_api, notify_db, notify_db_session, sample_user):