mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 09:21:39 -05:00
Merge pull request #162 from alphagov/platform-admin-role
Add platform_admin boolean on the User data model.
This commit is contained in:
@@ -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):
|
||||
|
||||
33
migrations/versions/0041_platform_admin.py
Normal file
33
migrations/versions/0041_platform_admin.py
Normal file
@@ -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 ###
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user