Skip to content

Commit

Permalink
Integrated user auth seems functional. Data migration done manually v…
Browse files Browse the repository at this point in the history
…ia csv export/import.
  • Loading branch information
chintal committed Jan 15, 2016
1 parent cdf9110 commit 00b93d8
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 38 deletions.
@@ -0,0 +1,65 @@
"""Add user auth models to primary db
Revision ID: 3badcc784860
Revises: 4e622fb65953
Create Date: 2016-01-15 10:09:31.464087
"""

# revision identifiers, used by Alembic.
revision = '3badcc784860'
down_revision = '4e622fb65953'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('Role',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=50), nullable=True),
sa.Column('description', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('User',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('confirmed_at', sa.DateTime(), nullable=True),
sa.Column('is_active', sa.Boolean(), server_default='0', nullable=False),
sa.Column('full_name', sa.String(length=50), server_default='', nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('UserAuth',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('username', sa.String(length=50), nullable=False),
sa.Column('password', sa.String(length=255), server_default='', nullable=False),
sa.Column('reset_password_token', sa.String(length=100), server_default='', nullable=False),
sa.Column('active', sa.Boolean(), server_default='0', nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['User.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('username')
)
op.create_table('UserRoles',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('role_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['role_id'], ['Role.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['User.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('UserRoles')
op.drop_table('UserAuth')
op.drop_table('User')
op.drop_table('Role')
### end Alembic commands ###
9 changes: 9 additions & 0 deletions tendril/auth/db/controller.py
Expand Up @@ -21,3 +21,12 @@
"""
Docstring for controller
"""

from tendril.utils.db import with_db

from .model import User


@with_db
def get_users_list(session=None):
return session.query(User.full_name).all()
17 changes: 9 additions & 8 deletions tendril/auth/db/model.py
Expand Up @@ -42,6 +42,14 @@
logger = log.get_logger(__name__, log.DEFAULT)


# Define the UserRoles association model
class UserRoles(DeclBase, BaseMixin):
user_id = Column(Integer(),
ForeignKey('User.id', ondelete='CASCADE'))
role_id = Column(Integer(),
ForeignKey('Role.id', ondelete='CASCADE'))


# Define the User data model. Make sure to add the flask_user.UserMixin !!
class User(DeclBase, BaseMixin, UserMixin):

Expand All @@ -56,7 +64,7 @@ class User(DeclBase, BaseMixin, UserMixin):

# Relationships
user_auth = relationship('UserAuth', uselist=False)
roles = relationship('Role', secondary='UserRoles',
roles = relationship('Role', secondary=UserRoles.__table__,
backref=backref('users', lazy='dynamic'))


Expand All @@ -81,10 +89,3 @@ class Role(DeclBase, BaseMixin):
name = Column(String(50), unique=True)
description = Column(String(255))


# Define the UserRoles association model
class UserRoles(DeclBase, BaseMixin):
user_id = Column(Integer(),
ForeignKey('User.id', ondelete='CASCADE'))
role_id = Column(Integer(),
ForeignKey('Role.id', ondelete='CASCADE'))
2 changes: 1 addition & 1 deletion tendril/frontend/parts/forms.py
Expand Up @@ -29,7 +29,7 @@
from wtforms.validators import ValidationError

from flask_user import current_user
from tendril.frontend.users.controller import get_users_list
from tendril.auth.db.controller import get_users_list


def user_auth_check(form, field):
Expand Down
29 changes: 0 additions & 29 deletions tendril/frontend/users/controller.py

This file was deleted.

0 comments on commit 00b93d8

Please sign in to comment.