From 18e3af9259dd81913d9c70a725eaed19fba09d05 Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Fri, 21 Jun 2019 11:48:33 +0530 Subject: [PATCH] Linter fixes --- features/steps/failed_login.py | 2 +- features/steps/failed_registration.py | 2 +- features/steps/login.py | 4 +- features/steps/registration.py | 4 +- lastuser_core/models/__init__.py | 80 +-- lastuser_core/models/client.py | 2 +- lastuser_core/models/helpers.py | 73 +++ lastuser_core/models/notification.py | 39 +- lastuser_core/models/user.py | 10 +- lastuser_core/registry.py | 2 +- lastuser_oauth/providers/openid.py | 6 +- lastuser_oauth/views/login.py | 1 + lastuser_oauth/views/oauth.py | 2 +- lastuser_oauth/views/resource.py | 2 +- lastuser_ui/views/dashboard.py | 2 +- lastuser_ui/views/org.py | 2 +- lastuser_ui/views/profile.py | 4 +- migrations/env.py | 1 + migrations/versions/184ed1055383_init.py | 546 +++++++++--------- .../versions/25e7a9839cd4_user_status_flag.py | 4 - .../2b0f9d6ddf96_switch_to_timestamptz.py | 6 +- .../2dcc6f5ab4cf_one_claim_per_email_.py | 2 +- .../35a6ffd7a079_restricted_resources.py | 2 +- .../versions/3b3583fcbaea_namespace_column.py | 5 +- .../versions/3e15e2b894d5_longer_scope.py | 1 + .../versions/4072c5dbca9f_email_length.py | 1 + ...921b_track_clients_that_verify_sessions.py | 2 +- .../7b0ba76b89e_resource_namespace.py | 6 +- ...remove_org_and_team_ownership_of_email_.py | 24 +- ..._email_and_phone_linked_to_org_and_team.py | 24 +- runtests.sh | 2 +- runtestserver.py | 6 +- tests/unit/lastuser_core/fixtures.py | 4 +- .../lastuser_core/test_model_user_User.py | 2 +- tests/unit/lastuser_core/test_utils.py | 3 +- website.py | 2 + 36 files changed, 441 insertions(+), 439 deletions(-) create mode 100644 lastuser_core/models/helpers.py diff --git a/features/steps/failed_login.py b/features/steps/failed_login.py index fc8cf22..ac1e74b 100644 --- a/features/steps/failed_login.py +++ b/features/steps/failed_login.py @@ -8,7 +8,7 @@ def given_existing_user(context): context.test_user = dict( username='bobthehacker', password='bobthehacker' - ) + ) @when("the nonexisting user tries to log in") diff --git a/features/steps/failed_registration.py b/features/steps/failed_registration.py index 323226c..c3f3e1b 100755 --- a/features/steps/failed_registration.py +++ b/features/steps/failed_registration.py @@ -10,7 +10,7 @@ def given_new_user(context): username='alyssa', password='alyssa', confirm_password='alyssa' - ) + ) # registering the test user context.browser.visit('/register') assert context.browser.find_element_by_name('csrf_token').is_enabled() diff --git a/features/steps/login.py b/features/steps/login.py index ecb5112..2624eca 100644 --- a/features/steps/login.py +++ b/features/steps/login.py @@ -10,7 +10,7 @@ def given_existing_user(context): username='alyssa', password='alyssa', confirm_password='alyssa' - ) + ) context.browser.visit('/register') assert context.browser.find_element_by_name('csrf_token').is_enabled() @@ -26,7 +26,7 @@ def when_login_form_submit(context): context.login_data = { 'username': context.test_user['username'], 'password': context.test_user['password'] - } + } wait = ui.WebDriverWait(context.browser, 30) context.browser.visit('/login') diff --git a/features/steps/registration.py b/features/steps/registration.py index fca069c..e99745c 100755 --- a/features/steps/registration.py +++ b/features/steps/registration.py @@ -10,7 +10,7 @@ def given_new_user(context): username='alyssa', password='alyssa', confirm_password='alyssa' - ) + ) @when('a new user submits the registration form with the proper details') @@ -29,4 +29,4 @@ def when_form_submit(context): def then_user_registered(context): user = User.get(username=context.test_user['username']) assert user is not None - assert len(user.emailclaims) is 1 + assert len(user.emailclaims) == 1 diff --git a/lastuser_core/models/__init__.py b/lastuser_core/models/__init__.py index b361779..95b6317 100644 --- a/lastuser_core/models/__init__.py +++ b/lastuser_core/models/__init__.py @@ -1,80 +1,14 @@ # -*- coding: utf-8 -*- +# flake8: noqa # Imported from here by other models -from coaster.sqlalchemy import TimestampMixin, BaseMixin, BaseScopedNameMixin, UuidMixin # NOQA +from coaster.sqlalchemy import TimestampMixin, BaseMixin, BaseScopedNameMixin, UuidMixin from coaster.db import db TimestampMixin.__with_timezone__ = True -from .user import * # NOQA -from .session import * # NOQA -from .client import * # NOQA -from .notification import * # NOQA - - -def getuser(name): - if '@' in name: - # TODO: This should have used UserExternalId.__at_username_services__, - # but this bit has traditionally been for Twitter only. Fix pending. - if name.startswith('@'): - extid = UserExternalId.get(service='twitter', username=name[1:]) - if extid and extid.user.is_active: - return extid.user - else: - return None - else: - useremail = UserEmail.get(email=name) - if useremail and useremail.user is not None and useremail.user.is_active: - return useremail.user - # No verified email id. Look for an unverified id; return first found - results = UserEmailClaim.all(email=name) - if results and results[0].user.is_active: - return results[0].user - return None - else: - return User.get(username=name) - - -def getextid(service, userid): - return UserExternalId.get(service=service, userid=userid) - - -def merge_users(user1, user2): - """ - Merge two user accounts and return the new user account. - """ - # Always keep the older account and merge from the newer account - if user1.created_at < user2.created_at: - keep_user, merge_user = user1, user2 - else: - keep_user, merge_user = user2, user1 - - # 1. Release the username - if not keep_user.username: - if merge_user.username: - # Flush before re-assigning to avoid dupe name constraint - username = merge_user.username - merge_user.username = None - db.session.flush() - keep_user.username = username - merge_user.username = None - - # 2. Inspect all tables for foreign key references to merge_user and switch to keep_user. - for model in db.Model.__subclasses__(): - if model != User: - # a. This is a model and it's not the User model. Does it have a migrate_user classmethod? - if hasattr(model, 'migrate_user'): - model.migrate_user(olduser=merge_user, newuser=keep_user) - # b. No migrate_user? Does it have a user_id column? - elif hasattr(model, 'user_id') and hasattr(model, 'query'): - for row in model.query.filter_by(user_id=merge_user.id).all(): - row.user_id = keep_user.id - # 3. Add merge_user's uuid to olduserids. Commit session. - db.session.add(UserOldId(id=merge_user.uuid, user=keep_user)) - # 4. Mark merge_user as merged. Commit session. - merge_user.status = USER_STATUS.MERGED - # 5. Commit all of this - db.session.commit() - - # 6. Return keep_user. - return keep_user +from .user import * +from .session import * +from .client import * +from .notification import * +from .helpers import * diff --git a/lastuser_core/models/client.py b/lastuser_core/models/client.py index 157c2c2..06f9af8 100644 --- a/lastuser_core/models/client.py +++ b/lastuser_core/models/client.py @@ -30,7 +30,7 @@ def _scope_get(self): if not self._scope: return () else: - return tuple(sorted([t.strip() for t in self._scope.replace('\r', ' ').replace('\n', ' ').split(u' ') if t])) + return tuple(sorted(self._scope.split())) def _scope_set(self, value): if isinstance(value, basestring): diff --git a/lastuser_core/models/helpers.py b/lastuser_core/models/helpers.py new file mode 100644 index 0000000..a619394 --- /dev/null +++ b/lastuser_core/models/helpers.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +from .user import db, User, UserEmail, UserEmailClaim, UserExternalId, UserOldId, USER_STATUS + +__all__ = ['getuser', 'getextid', 'merge_users'] + + +def getuser(name): + if '@' in name: + # TODO: This should have used UserExternalId.__at_username_services__, + # but this bit has traditionally been for Twitter only. Fix pending. + if name.startswith('@'): + extid = UserExternalId.get(service='twitter', username=name[1:]) + if extid and extid.user.is_active: + return extid.user + else: + return None + else: + useremail = UserEmail.get(email=name) + if useremail and useremail.user is not None and useremail.user.is_active: + return useremail.user + # No verified email id. Look for an unverified id; return first found + results = UserEmailClaim.all(email=name) + if results and results[0].user.is_active: + return results[0].user + return None + else: + return User.get(username=name) + + +def getextid(service, userid): + return UserExternalId.get(service=service, userid=userid) + + +def merge_users(user1, user2): + """ + Merge two user accounts and return the new user account. + """ + # Always keep the older account and merge from the newer account + if user1.created_at < user2.created_at: + keep_user, merge_user = user1, user2 + else: + keep_user, merge_user = user2, user1 + + # 1. Release the username + if not keep_user.username: + if merge_user.username: + # Flush before re-assigning to avoid dupe name constraint + username = merge_user.username + merge_user.username = None + db.session.flush() + keep_user.username = username + merge_user.username = None + + # 2. Inspect all tables for foreign key references to merge_user and switch to keep_user. + for model in db.Model.__subclasses__(): + if model != User: + # a. This is a model and it's not the User model. Does it have a migrate_user classmethod? + if hasattr(model, 'migrate_user'): + model.migrate_user(olduser=merge_user, newuser=keep_user) + # b. No migrate_user? Does it have a user_id column? + elif hasattr(model, 'user_id') and hasattr(model, 'query'): + for row in model.query.filter_by(user_id=merge_user.id).all(): + row.user_id = keep_user.id + # 3. Add merge_user's uuid to olduserids. Commit session. + db.session.add(UserOldId(id=merge_user.uuid, user=keep_user)) + # 4. Mark merge_user as merged. Commit session. + merge_user.status = USER_STATUS.MERGED + # 5. Commit all of this + db.session.commit() + + # 6. Return keep_user. + return keep_user diff --git a/lastuser_core/models/notification.py b/lastuser_core/models/notification.py index 1dae3e5..2cd2d3d 100644 --- a/lastuser_core/models/notification.py +++ b/lastuser_core/models/notification.py @@ -1,12 +1,9 @@ # -*- coding: utf-8 -*- -from sqlalchemy.ext.declarative import declared_attr from coaster.utils import LabeledEnum from baseframe import __ from ..registry import OrderedDict -from . import db, BaseMixin, BaseScopedNameMixin -from .user import User, UserEmail, UserPhone -from .client import Client +from . import db, BaseMixin __all__ = ['SMSMessage', 'SMS_STATUS'] @@ -14,33 +11,33 @@ # --- Flags ------------------------------------------------------------------- class SMS_STATUS(LabeledEnum): - QUEUED = (0, __(u"Queued")) - PENDING = (1, __(u"Pending")) - DELIVERED = (2, __(u"Delivered")) - FAILED = (3, __(u"Failed")) - UNKNOWN = (4, __(u"Unknown")) + QUEUED = (0, __(u"Queued")) # NOQA: E221 + PENDING = (1, __(u"Pending")) # NOQA: E221 + DELIVERED = (2, __(u"Delivered")) # NOQA: E221 + FAILED = (3, __(u"Failed")) # NOQA: E221 + UNKNOWN = (4, __(u"Unknown")) # NOQA: E221 class NOTIFICATION_FLAGS(LabeledEnum): - DELIVERY = (0, __(u"Delivery")) - READ = (1, __(u"Read")) - BOUNCE = (2, __(u"Bounce")) + DELIVERY = (0, __(u"Delivery")) # NOQA: E221 + READ = (1, __(u"Read")) # NOQA: E221 + BOUNCE = (2, __(u"Bounce")) # NOQA: E221 class NOTIFICATION_TYPE(LabeledEnum): - MANDATORY = (0, u'mandatory', __(u"Mandatory")) # Mandatory service announcement - TRANSACTIONAL = (1, u'transactional', __(u"Transactional")) # Result of user activity - ALERT = (2, u'alert', __(u"Alert")) # Periodic alert based on set criteria - MASS = (3, u'mass', __(u"Mass")) # Mass mail from the service provider + MANDATORY = (0, u'mandatory', __(u"Mandatory")) # Mandatory service announcement # NOQA: E221,E241 + TRANSACTIONAL = (1, u'transactional', __(u"Transactional")) # Result of user activity # NOQA: E221,E241 + ALERT = (2, u'alert', __(u"Alert")) # Periodic alert based on set criteria # NOQA: E221,E241 + MASS = (3, u'mass', __(u"Mass")) # Mass mail from the service provider # NOQA: E221,E241 # A note on frequency: scheduling/batching is done by Lastuser, not by the client app class NOTIFICATION_FREQUENCY(LabeledEnum): - IMMEDIATE = (0, u'immed', __(u"Immediately")) # Alert user immediately - DELAYED = (1, u'delay', __(u"Delayed")) # Send after a timeout, allowing app to cancel (tentative) - DAILY = (2, u'daily', __(u"Batched daily")) # Send a daily digest - WEEKLY = (3, u'weekly', __(u"Batched weekly")) # Send a weekly digest - MONTHLY = (4, u'monthly', __(u"Batched monthly")) # Send a monthly digest + IMMEDIATE = (0, u'immed', __(u"Immediately")) # Alert user immediately # NOQA: E221,E241 + DELAYED = (1, u'delay', __(u"Delayed")) # Send after a timeout, allowing app to cancel (tentative) # NOQA: E221,E241 + DAILY = (2, u'daily', __(u"Batched daily")) # Send a daily digest # NOQA: E221,E241 + WEEKLY = (3, u'weekly', __(u"Batched weekly")) # Send a weekly digest # NOQA: E221,E241 + MONTHLY = (4, u'monthly', __(u"Batched monthly")) # Send a monthly digest # NOQA: E221,E241 # --- Transport Channels ------------------------------------------------------ diff --git a/lastuser_core/models/user.py b/lastuser_core/models/user.py index 5852670..237f1f3 100644 --- a/lastuser_core/models/user.py +++ b/lastuser_core/models/user.py @@ -44,9 +44,9 @@ class Name(UuidMixin, BaseMixin, db.Model): __table_args__ = ( db.CheckConstraint( - db.case([(user_id != None, 1)], else_=0) + - db.case([(org_id != None, 1)], else_=0) + - db.case([(reserved == True, 1)], else_=0) == 1, + db.case([(user_id != None, 1)], else_=0) + + db.case([(org_id != None, 1)], else_=0) + + db.case([(reserved == True, 1)], else_=0) == 1, name='username_owner_check'), # NOQA db.Index('ix_name_name_lower', db.func.lower(name).label('name_lower'), unique=True, postgresql_ops={'name_lower': 'varchar_pattern_ops'}) @@ -478,12 +478,12 @@ def autocomplete(cls, query): db.session.query(UserExternalId.user_id).filter( UserExternalId.service.in_(UserExternalId.__at_username_services__), db.func.lower(UserExternalId.username).like(db.func.lower(query[1:])) - ).subquery())).options(*cls._defercols).limit(100).all() + users + ).subquery())).options(*cls._defercols).limit(100).all() + users elif '@' in query: users = cls.query.filter(cls.status == USER_STATUS.ACTIVE, cls.id.in_( db.session.query(UserEmail.user_id).filter(UserEmail.user_id != None).filter( # NOQA db.func.lower(UserEmail.email).like(db.func.lower(query)) - ).subquery())).options(*cls._defercols).limit(100).all() + users + ).subquery())).options(*cls._defercols).limit(100).all() + users return users diff --git a/lastuser_core/registry.py b/lastuser_core/registry.py index 77fafa2..ecadaa2 100644 --- a/lastuser_core/registry.py +++ b/lastuser_core/registry.py @@ -198,4 +198,4 @@ def callback(self, *args, **kwargs): 'email': None, # Verified email address. Service can be trusted 'emailclaim': None, # Claimed email address. Must be verified 'email_md5sum': None, # For when we have the email md5sum, but not the email itself - } + } diff --git a/lastuser_oauth/providers/openid.py b/lastuser_oauth/providers/openid.py index 11ce84e..29e2ad9 100644 --- a/lastuser_oauth/providers/openid.py +++ b/lastuser_oauth/providers/openid.py @@ -42,8 +42,8 @@ def login_openid_success(resp): Called when OpenID login succeeds """ openid = resp.identity_url - if (openid.startswith('https://profiles.google.com/') or - openid.startswith('https://www.google.com/accounts/o8/id?id=')): + if (openid.startswith('https://profiles.google.com/') + or openid.startswith('https://www.google.com/accounts/o8/id?id=')): service = 'google' else: service = 'openid' @@ -55,7 +55,7 @@ def login_openid_success(resp): 'oauth_token': None, 'oauth_token_secret': None, 'oauth_token_type': None, - } + } if resp.email: if service == 'google': # Google id. Trust the email address. diff --git a/lastuser_oauth/views/login.py b/lastuser_oauth/views/login.py index ee96b1f..4a7cbae 100644 --- a/lastuser_oauth/views/login.py +++ b/lastuser_oauth/views/login.py @@ -28,6 +28,7 @@ def openid_log(message, level=0): import sys print(message, file=sys.stderr) + oidutil.log = openid_log diff --git a/lastuser_oauth/views/oauth.py b/lastuser_oauth/views/oauth.py index fc4d22d..55545f0 100644 --- a/lastuser_oauth/views/oauth.py +++ b/lastuser_oauth/views/oauth.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from flask import flash, render_template, redirect, request, jsonify, get_flashed_messages +from flask import render_template, redirect, request, jsonify, get_flashed_messages from coaster.utils import newsecret from coaster.auth import current_auth from coaster.sqlalchemy import failsafe_add diff --git a/lastuser_oauth/views/resource.py b/lastuser_oauth/views/resource.py index 00013a3..c14fe07 100644 --- a/lastuser_oauth/views/resource.py +++ b/lastuser_oauth/views/resource.py @@ -637,7 +637,7 @@ def resource_login_providers(authtoken, args, files=None): 'oauth_token': unicode(extid.oauth_token), 'oauth_token_secret': unicode(extid.oauth_token_secret), 'oauth_token_type': unicode(extid.oauth_token_type) - } + } return response diff --git a/lastuser_ui/views/dashboard.py b/lastuser_ui/views/dashboard.py index 6852109..8dff4b8 100644 --- a/lastuser_ui/views/dashboard.py +++ b/lastuser_ui/views/dashboard.py @@ -68,7 +68,7 @@ def dashboard_data_users_by_client(): ): clients = db.session.query('client_id', 'count', 'title', 'website').from_statement(db.text( '''SELECT client_users.client_id, count(*) AS count, client.title AS title, client.website AS website FROM (SELECT user_session.user_id, session_client.client_id FROM user_session, session_client, "user" WHERE user_session.user_id = "user".id AND session_client.user_session_id = user_session.id AND "user".status = :status AND session_client.updated_at >= (NOW() AT TIME ZONE 'UTC') - INTERVAL :interval GROUP BY session_client.client_id, user_session.user_id) AS client_users, client WHERE client.id = client_users.client_id GROUP by client_users.client_id, client.title, client.website ORDER BY count DESC''' - )).params(status=USER_STATUS.ACTIVE, interval=interval).all() + )).params(status=USER_STATUS.ACTIVE, interval=interval).all() for row in clients: client_users[row.client_id]['title'] = row.title client_users[row.client_id]['website'] = row.website diff --git a/lastuser_ui/views/org.py b/lastuser_ui/views/org.py index 8e21b4c..c9b0aa1 100644 --- a/lastuser_ui/views/org.py +++ b/lastuser_ui/views/org.py @@ -119,7 +119,7 @@ class TeamView(UrlForView, ModelView): route_model_map = { # Map and in URLs to model attributes, for `url_for` automation 'name': 'org.name', 'buid': 'buid' - } + } def loader(self, name, buid): obj = Team.get(buid=buid, with_parent=True) diff --git a/lastuser_ui/views/profile.py b/lastuser_ui/views/profile.py index 323b81e..cffa4e7 100644 --- a/lastuser_ui/views/profile.py +++ b/lastuser_ui/views/profile.py @@ -97,7 +97,7 @@ def make_email_primary(): else: flash(_("No such email address is linked to this user account"), 'danger') else: - flash(_("Please select an email address"), 'danger') + flash(_("Please select an email address"), 'danger') return render_redirect(url_for('.account'), code=303) @@ -118,7 +118,7 @@ def make_phone_primary(): else: flash(_("No such phone number is linked to this user account"), 'danger') else: - flash(_("Please select a phone number"), 'danger') + flash(_("Please select a phone number"), 'danger') return render_redirect(url_for('.account'), code=303) diff --git a/migrations/env.py b/migrations/env.py index 4593816..46a8e20 100755 --- a/migrations/env.py +++ b/migrations/env.py @@ -81,6 +81,7 @@ def process_revision_directives(context, revision, directives): finally: connection.close() + if context.is_offline_mode(): run_migrations_offline() else: diff --git a/migrations/versions/184ed1055383_init.py b/migrations/versions/184ed1055383_init.py index d9b407a..535b49d 100644 --- a/migrations/versions/184ed1055383_init.py +++ b/migrations/versions/184ed1055383_init.py @@ -15,312 +15,309 @@ def upgrade(): - ### commands auto generated by Alembic - please adjust! ### op.create_table('user', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('userid', sa.String(length=22), nullable=False), - sa.Column('fullname', sa.Unicode(length=80), nullable=False), - sa.Column('username', sa.Unicode(length=80), nullable=True), - sa.Column('pw_hash', sa.String(length=80), nullable=True), - sa.Column('timezone', sa.Unicode(length=40), nullable=True), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('userid'), - sa.UniqueConstraint('username') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('userid', sa.String(length=22), nullable=False), + sa.Column('fullname', sa.Unicode(length=80), nullable=False), + sa.Column('username', sa.Unicode(length=80), nullable=True), + sa.Column('pw_hash', sa.String(length=80), nullable=True), + sa.Column('timezone', sa.Unicode(length=40), nullable=True), + sa.Column('description', sa.UnicodeText(), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('userid'), + sa.UniqueConstraint('username') + ) op.create_table('organization', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('owners_id', sa.Integer(), nullable=True), - sa.Column('userid', sa.String(length=22), nullable=False), - sa.Column('name', sa.Unicode(length=80), nullable=True), - sa.Column('title', sa.Unicode(length=80), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name'), - sa.UniqueConstraint('userid') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('owners_id', sa.Integer(), nullable=True), + sa.Column('userid', sa.String(length=22), nullable=False), + sa.Column('name', sa.Unicode(length=80), nullable=True), + sa.Column('title', sa.Unicode(length=80), nullable=False), + sa.Column('description', sa.UnicodeText(), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name'), + sa.UniqueConstraint('userid') + ) op.create_table('smsmessage', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('phone_number', sa.String(length=15), nullable=False), - sa.Column('transaction_id', sa.Unicode(length=40), nullable=True), - sa.Column('message', sa.UnicodeText(), nullable=False), - sa.Column('status', sa.Integer(), nullable=False), - sa.Column('status_at', sa.DateTime(), nullable=True), - sa.Column('fail_reason', sa.Unicode(length=25), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('transaction_id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('phone_number', sa.String(length=15), nullable=False), + sa.Column('transaction_id', sa.Unicode(length=40), nullable=True), + sa.Column('message', sa.UnicodeText(), nullable=False), + sa.Column('status', sa.Integer(), nullable=False), + sa.Column('status_at', sa.DateTime(), nullable=True), + sa.Column('fail_reason', sa.Unicode(length=25), nullable=True), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('transaction_id') + ) op.create_table('client', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('org_id', sa.Integer(), nullable=True), - sa.Column('title', sa.Unicode(length=250), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.Column('website', sa.Unicode(length=250), nullable=False), - sa.Column('redirect_uri', sa.Unicode(length=250), nullable=True), - sa.Column('notification_uri', sa.Unicode(length=250), nullable=True), - sa.Column('iframe_uri', sa.Unicode(length=250), nullable=True), - sa.Column('resource_uri', sa.Unicode(length=250), nullable=True), - sa.Column('active', sa.Boolean(), nullable=False), - sa.Column('allow_any_login', sa.Boolean(), nullable=False), - sa.Column('team_access', sa.Boolean(), nullable=False), - sa.Column('key', sa.String(length=22), nullable=False), - sa.Column('secret', sa.String(length=44), nullable=False), - sa.Column('trusted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['org_id'], ['organization.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('key') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('org_id', sa.Integer(), nullable=True), + sa.Column('title', sa.Unicode(length=250), nullable=False), + sa.Column('description', sa.UnicodeText(), nullable=False), + sa.Column('website', sa.Unicode(length=250), nullable=False), + sa.Column('redirect_uri', sa.Unicode(length=250), nullable=True), + sa.Column('notification_uri', sa.Unicode(length=250), nullable=True), + sa.Column('iframe_uri', sa.Unicode(length=250), nullable=True), + sa.Column('resource_uri', sa.Unicode(length=250), nullable=True), + sa.Column('active', sa.Boolean(), nullable=False), + sa.Column('allow_any_login', sa.Boolean(), nullable=False), + sa.Column('team_access', sa.Boolean(), nullable=False), + sa.Column('key', sa.String(length=22), nullable=False), + sa.Column('secret', sa.String(length=44), nullable=False), + sa.Column('trusted', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['org_id'], ['organization.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('key') + ) op.create_table('permission', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('org_id', sa.Integer(), nullable=True), - sa.Column('name', sa.Unicode(length=80), nullable=False), - sa.Column('title', sa.Unicode(length=250), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.Column('allusers', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['org_id'], ['organization.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('org_id', sa.Integer(), nullable=True), + sa.Column('name', sa.Unicode(length=80), nullable=False), + sa.Column('title', sa.Unicode(length=250), nullable=False), + sa.Column('description', sa.UnicodeText(), nullable=False), + sa.Column('allusers', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['org_id'], ['organization.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('noticetype', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=80), nullable=False), - sa.Column('title', sa.Unicode(length=250), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.Column('allusers', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('name', sa.Unicode(length=80), nullable=False), + sa.Column('title', sa.Unicode(length=250), nullable=False), + sa.Column('description', sa.UnicodeText(), nullable=False), + sa.Column('allusers', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('useremailclaim', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('email', sa.Unicode(length=80), nullable=True), - sa.Column('verification_code', sa.String(length=44), nullable=False), - sa.Column('md5sum', sa.String(length=32), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('email', sa.Unicode(length=80), nullable=True), + sa.Column('verification_code', sa.String(length=44), nullable=False), + sa.Column('md5sum', sa.String(length=32), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('useroldid', - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('userid', sa.String(length=22), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('userid') - ) + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('userid', sa.String(length=22), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('userid') + ) op.create_table('userphoneclaim', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('phone', sa.Unicode(length=80), nullable=False), - sa.Column('gets_text', sa.Boolean(), nullable=False), - sa.Column('verification_code', sa.Unicode(length=4), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('phone', sa.Unicode(length=80), nullable=False), + sa.Column('gets_text', sa.Boolean(), nullable=False), + sa.Column('verification_code', sa.Unicode(length=4), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('useremail', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('email', sa.Unicode(length=80), nullable=False), - sa.Column('md5sum', sa.String(length=32), nullable=False), - sa.Column('primary', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('email'), - sa.UniqueConstraint('md5sum') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('email', sa.Unicode(length=80), nullable=False), + sa.Column('md5sum', sa.String(length=32), nullable=False), + sa.Column('primary', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('email'), + sa.UniqueConstraint('md5sum') + ) op.create_table('userphone', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('primary', sa.Boolean(), nullable=False), - sa.Column('phone', sa.Unicode(length=80), nullable=False), - sa.Column('gets_text', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('phone') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('primary', sa.Boolean(), nullable=False), + sa.Column('phone', sa.Unicode(length=80), nullable=False), + sa.Column('gets_text', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('phone') + ) op.create_table('team', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('userid', sa.String(length=22), nullable=False), - sa.Column('title', sa.Unicode(length=250), nullable=False), - sa.Column('org_id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('userid') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('userid', sa.String(length=22), nullable=False), + sa.Column('title', sa.Unicode(length=250), nullable=False), + sa.Column('org_id', sa.Integer(), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('userid') + ) op.create_table('userexternalid', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('service', sa.String(length=20), nullable=False), - sa.Column('userid', sa.String(length=250), nullable=False), - sa.Column('username', sa.Unicode(length=80), nullable=True), - sa.Column('oauth_token', sa.String(length=250), nullable=True), - sa.Column('oauth_token_secret', sa.String(length=250), nullable=True), - sa.Column('oauth_token_type', sa.String(length=250), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('service','userid') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('service', sa.String(length=20), nullable=False), + sa.Column('userid', sa.String(length=250), nullable=False), + sa.Column('username', sa.Unicode(length=80), nullable=True), + sa.Column('oauth_token', sa.String(length=250), nullable=True), + sa.Column('oauth_token_secret', sa.String(length=250), nullable=True), + sa.Column('oauth_token_type', sa.String(length=250), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('service', 'userid') + ) op.create_table('passwordresetrequest', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('reset_code', sa.String(length=44), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('reset_code', sa.String(length=44), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('userflashmessage', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('seq', sa.Integer(), nullable=False), - sa.Column('category', sa.Unicode(length=20), nullable=False), - sa.Column('message', sa.Unicode(length=250), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('seq', sa.Integer(), nullable=False), + sa.Column('category', sa.Unicode(length=20), nullable=False), + sa.Column('message', sa.Unicode(length=250), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('authcode', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('client_id', sa.Integer(), nullable=False), - sa.Column('code', sa.String(length=44), nullable=False), - sa.Column('scope', sa.Unicode(length=250), nullable=False), - sa.Column('redirect_uri', sa.Unicode(length=1024), nullable=False), - sa.Column('used', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('code', sa.String(length=44), nullable=False), + sa.Column('scope', sa.Unicode(length=250), nullable=False), + sa.Column('redirect_uri', sa.Unicode(length=1024), nullable=False), + sa.Column('used', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('team_membership', - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('team_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['team_id'], ['team.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint() - ) + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('team_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['team_id'], ['team.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint() + ) op.create_table('userclientpermissions', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('client_id', sa.Integer(), nullable=False), - sa.Column('permissions', sa.Unicode(length=250), nullable=False), - sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('user_id','client_id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('permissions', sa.Unicode(length=250), nullable=False), + sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('user_id', 'client_id') + ) op.create_table('authtoken', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('client_id', sa.Integer(), nullable=False), - sa.Column('token', sa.String(length=22), nullable=False), - sa.Column('token_type', sa.String(length=250), nullable=False), - sa.Column('secret', sa.String(length=44), nullable=True), - sa.Column('algorithm', sa.String(length=20), nullable=True), - sa.Column('scope', sa.Unicode(length=250), nullable=False), - sa.Column('validity', sa.Integer(), nullable=False), - sa.Column('refresh_token', sa.String(length=22), nullable=True), - sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('refresh_token'), - sa.UniqueConstraint('token'), - sa.UniqueConstraint('user_id','client_id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('token', sa.String(length=22), nullable=False), + sa.Column('token_type', sa.String(length=250), nullable=False), + sa.Column('secret', sa.String(length=44), nullable=True), + sa.Column('algorithm', sa.String(length=20), nullable=True), + sa.Column('scope', sa.Unicode(length=250), nullable=False), + sa.Column('validity', sa.Integer(), nullable=False), + sa.Column('refresh_token', sa.String(length=22), nullable=True), + sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('refresh_token'), + sa.UniqueConstraint('token'), + sa.UniqueConstraint('user_id', 'client_id') + ) op.create_table('teamclientpermissions', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('team_id', sa.Integer(), nullable=False), - sa.Column('client_id', sa.Integer(), nullable=False), - sa.Column('permissions', sa.Unicode(length=250), nullable=False), - sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), - sa.ForeignKeyConstraint(['team_id'], ['team.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('team_id','client_id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('team_id', sa.Integer(), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('permissions', sa.Unicode(length=250), nullable=False), + sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), + sa.ForeignKeyConstraint(['team_id'], ['team.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('team_id', 'client_id') + ) op.create_table('resource', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('name', sa.Unicode(length=20), nullable=False), - sa.Column('client_id', sa.Integer(), nullable=False), - sa.Column('title', sa.Unicode(length=250), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.Column('siteresource', sa.Boolean(), nullable=False), - sa.Column('trusted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('name', sa.Unicode(length=20), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('title', sa.Unicode(length=250), nullable=False), + sa.Column('description', sa.UnicodeText(), nullable=False), + sa.Column('siteresource', sa.Boolean(), nullable=False), + sa.Column('trusted', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) op.create_table('clientteamaccess', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('org_id', sa.Integer(), nullable=True), - sa.Column('client_id', sa.Integer(), nullable=False), - sa.Column('access_level', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), - sa.ForeignKeyConstraint(['org_id'], ['organization.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('org_id', sa.Integer(), nullable=True), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('access_level', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), + sa.ForeignKeyConstraint(['org_id'], ['organization.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('resourceaction', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('name', sa.Unicode(length=20), nullable=False), - sa.Column('resource_id', sa.Integer(), nullable=False), - sa.Column('title', sa.Unicode(length=250), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.ForeignKeyConstraint(['resource_id'], ['resource.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name','resource_id') - ) + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('name', sa.Unicode(length=20), nullable=False), + sa.Column('resource_id', sa.Integer(), nullable=False), + sa.Column('title', sa.Unicode(length=250), nullable=False), + sa.Column('description', sa.UnicodeText(), nullable=False), + sa.ForeignKeyConstraint(['resource_id'], ['resource.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name', 'resource_id') + ) op.create_foreign_key( "fk_organization_owners_id", "organization", "team", ['owners_id'], ['id'] - ) + ) op.create_foreign_key( "fk_team_org_id", "team", "organization", ['org_id'], ['id'] - ) - ### end Alembic commands ### + ) def downgrade(): - ### commands auto generated by Alembic - please adjust! ### op.drop_table('resourceaction') op.drop_table('clientteamaccess') op.drop_table('resource') @@ -344,4 +341,3 @@ def downgrade(): op.drop_table('smsmessage') op.drop_table('organization') op.drop_table('user') - ### end Alembic commands ### diff --git a/migrations/versions/25e7a9839cd4_user_status_flag.py b/migrations/versions/25e7a9839cd4_user_status_flag.py index e580968..f2016c6 100644 --- a/migrations/versions/25e7a9839cd4_user_status_flag.py +++ b/migrations/versions/25e7a9839cd4_user_status_flag.py @@ -15,14 +15,10 @@ def upgrade(): - ### commands auto generated by Alembic - please adjust! ### op.add_column('user', sa.Column('status', sa.SmallInteger(), nullable=False, server_default=sa.text('0'))) op.alter_column('user', 'status', server_default=None) - ### end Alembic commands ### def downgrade(): - ### commands auto generated by Alembic - please adjust! ### op.drop_column('user', 'status') - ### end Alembic commands ### diff --git a/migrations/versions/2b0f9d6ddf96_switch_to_timestamptz.py b/migrations/versions/2b0f9d6ddf96_switch_to_timestamptz.py index dfb8919..f6b5da2 100644 --- a/migrations/versions/2b0f9d6ddf96_switch_to_timestamptz.py +++ b/migrations/versions/2b0f9d6ddf96_switch_to_timestamptz.py @@ -78,7 +78,7 @@ ('userphone', 'updated_at'), ('userphoneclaim', 'created_at'), ('userphoneclaim', 'updated_at'), -] + ] def upgrade(): @@ -86,7 +86,7 @@ def upgrade(): op.execute(sa.DDL( 'ALTER TABLE "%(table)s" ALTER COLUMN "%(column)s" TYPE TIMESTAMP WITH TIME ZONE USING "%(column)s" AT TIME ZONE \'UTC\'', context={'table': table, 'column': column} - )) + )) def downgrade(): @@ -94,4 +94,4 @@ def downgrade(): op.execute(sa.DDL( 'ALTER TABLE "%(table)s" ALTER COLUMN "%(column)s" TYPE TIMESTAMP WITHOUT TIME ZONE', context={'table': table, 'column': column} - )) + )) diff --git a/migrations/versions/2dcc6f5ab4cf_one_claim_per_email_.py b/migrations/versions/2dcc6f5ab4cf_one_claim_per_email_.py index e4ae2c4..ac804f9 100644 --- a/migrations/versions/2dcc6f5ab4cf_one_claim_per_email_.py +++ b/migrations/versions/2dcc6f5ab4cf_one_claim_per_email_.py @@ -11,7 +11,7 @@ down_revision = '4072c5dbca9f' from alembic import op -import sqlalchemy as sa +import sqlalchemy as sa # NOQA def upgrade(): diff --git a/migrations/versions/35a6ffd7a079_restricted_resources.py b/migrations/versions/35a6ffd7a079_restricted_resources.py index c25a5e2..ddfafab 100644 --- a/migrations/versions/35a6ffd7a079_restricted_resources.py +++ b/migrations/versions/35a6ffd7a079_restricted_resources.py @@ -11,7 +11,7 @@ down_revision = '3b3583fcbaea' from alembic import op -import sqlalchemy as sa +import sqlalchemy as sa # NOQA def upgrade(): diff --git a/migrations/versions/3b3583fcbaea_namespace_column.py b/migrations/versions/3b3583fcbaea_namespace_column.py index 92ac8f7..8d03933 100644 --- a/migrations/versions/3b3583fcbaea_namespace_column.py +++ b/migrations/versions/3b3583fcbaea_namespace_column.py @@ -18,10 +18,8 @@ def upgrade(): - ### commands auto generated by Alembic - please adjust! ### op.add_column('client', sa.Column('namespace', sa.Unicode(length=250), nullable=True)) op.create_unique_constraint('client_namespace_key', 'client', ['namespace']) - ### end Alembic commands ### connection = op.get_bind() client = table('client', @@ -44,7 +42,6 @@ def upgrade(): updt_stmt = client.update().where(client.c.id == bindparam('clientid')).values(namespace=bindparam('namespace')) connection.execute(updt_stmt, namespaces) + def downgrade(): - ### commands auto generated by Alembic - please adjust! ### op.drop_column('client', 'namespace') - ### end Alembic commands ### diff --git a/migrations/versions/3e15e2b894d5_longer_scope.py b/migrations/versions/3e15e2b894d5_longer_scope.py index 71528f4..c9a5009 100644 --- a/migrations/versions/3e15e2b894d5_longer_scope.py +++ b/migrations/versions/3e15e2b894d5_longer_scope.py @@ -18,6 +18,7 @@ def upgrade(): op.alter_column('authcode', 'scope', type_=sa.UnicodeText) op.alter_column('authtoken', 'scope', type_=sa.UnicodeText) + def downgrade(): op.alter_column('authtoken', 'scope', type_=sa.Unicode(250)) op.alter_column('authcode', 'scope', type_=sa.Unicode(250)) diff --git a/migrations/versions/4072c5dbca9f_email_length.py b/migrations/versions/4072c5dbca9f_email_length.py index 7d3669b..2b3ca0b 100644 --- a/migrations/versions/4072c5dbca9f_email_length.py +++ b/migrations/versions/4072c5dbca9f_email_length.py @@ -18,6 +18,7 @@ def upgrade(): op.alter_column('useremail', 'email', type_=sa.Unicode(254)) op.alter_column('useremailclaim', 'email', type_=sa.Unicode(254)) + def downgrade(): op.alter_column('useremailclaim', 'email', type_=sa.Unicode(80)) op.alter_column('useremail', 'email', type_=sa.Unicode(80)) diff --git a/migrations/versions/51eadbed921b_track_clients_that_verify_sessions.py b/migrations/versions/51eadbed921b_track_clients_that_verify_sessions.py index 85a3804..717ca20 100644 --- a/migrations/versions/51eadbed921b_track_clients_that_verify_sessions.py +++ b/migrations/versions/51eadbed921b_track_clients_that_verify_sessions.py @@ -23,7 +23,7 @@ def upgrade(): sa.ForeignKeyConstraint(['client_id'], ['client.id'], ), sa.ForeignKeyConstraint(['user_session_id'], ['user_session.id'], ), sa.PrimaryKeyConstraint('user_session_id', 'client_id') - ) + ) def downgrade(): diff --git a/migrations/versions/7b0ba76b89e_resource_namespace.py b/migrations/versions/7b0ba76b89e_resource_namespace.py index b5e7e22..11e135a 100644 --- a/migrations/versions/7b0ba76b89e_resource_namespace.py +++ b/migrations/versions/7b0ba76b89e_resource_namespace.py @@ -11,14 +11,14 @@ down_revision = '3e15e2b894d5' from alembic import op -import sqlalchemy as sa +import sqlalchemy as sa # NOQA def upgrade(): - op.drop_constraint('resource_name_key','resource') + op.drop_constraint('resource_name_key', 'resource') op.create_unique_constraint('resource_client_id_name_key', 'resource', ['client_id', 'name']) def downgrade(): - op.drop_constraint('resource_client_id_name_key','resource') + op.drop_constraint('resource_client_id_name_key', 'resource') op.create_unique_constraint('resource_name_key', 'resource', ['name']) diff --git a/migrations/versions/c446b9bc0691_remove_org_and_team_ownership_of_email_.py b/migrations/versions/c446b9bc0691_remove_org_and_team_ownership_of_email_.py index 0ce9147..7455ce0 100644 --- a/migrations/versions/c446b9bc0691_remove_org_and_team_ownership_of_email_.py +++ b/migrations/versions/c446b9bc0691_remove_org_and_team_ownership_of_email_.py @@ -56,9 +56,9 @@ def downgrade(): op.create_unique_constraint(u'userphoneclaim_org_id_phone_key', 'userphoneclaim', ['org_id', 'phone']) op.alter_column('userphoneclaim', 'user_id', existing_type=sa.INTEGER(), nullable=True) op.create_check_constraint('userphoneclaim_user_id_or_org_id_or_team_id', 'userphoneclaim', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA op.add_column('userphone', sa.Column('org_id', sa.INTEGER(), autoincrement=False, nullable=True)) op.add_column('userphone', sa.Column('team_id', sa.INTEGER(), autoincrement=False, nullable=True)) @@ -66,9 +66,9 @@ def downgrade(): op.create_foreign_key(u'userphone_org_id_fkey', 'userphone', 'organization', ['org_id'], ['id']) op.alter_column('userphone', 'user_id', existing_type=sa.INTEGER(), nullable=True) op.create_check_constraint('userphone_user_id_or_org_id_or_team_id', 'userphone', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA op.add_column('useremailclaim', sa.Column('org_id', sa.INTEGER(), autoincrement=False, nullable=True)) op.add_column('useremailclaim', sa.Column('team_id', sa.INTEGER(), autoincrement=False, nullable=True)) @@ -78,9 +78,9 @@ def downgrade(): op.create_unique_constraint(u'useremailclaim_org_id_email_key', 'useremailclaim', ['org_id', 'email']) op.alter_column('useremailclaim', 'user_id', existing_type=sa.INTEGER(), nullable=True) op.create_check_constraint('useremailclaim_user_id_or_org_id_or_team_id', 'useremailclaim', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA op.add_column('useremail', sa.Column('org_id', sa.INTEGER(), autoincrement=False, nullable=True)) op.add_column('useremail', sa.Column('team_id', sa.INTEGER(), autoincrement=False, nullable=True)) @@ -88,6 +88,6 @@ def downgrade(): op.create_foreign_key(u'useremail_team_id_fkey', 'useremail', 'team', ['team_id'], ['id']) op.alter_column('useremail', 'user_id', existing_type=sa.INTEGER(), nullable=True) op.create_check_constraint('useremail_user_id_or_org_id_or_team_id', 'useremail', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA diff --git a/migrations/versions/d94bd59a2f0_email_and_phone_linked_to_org_and_team.py b/migrations/versions/d94bd59a2f0_email_and_phone_linked_to_org_and_team.py index ee47b51..aee47c6 100644 --- a/migrations/versions/d94bd59a2f0_email_and_phone_linked_to_org_and_team.py +++ b/migrations/versions/d94bd59a2f0_email_and_phone_linked_to_org_and_team.py @@ -24,9 +24,9 @@ def upgrade(): op.create_foreign_key('useremail_org_id_fkey', 'useremail', 'organization', ['org_id'], ['id']) op.create_foreign_key('useremail_team_id_fkey', 'useremail', 'team', ['team_id'], ['id']) op.create_check_constraint('useremail_user_id_or_org_id_or_team_id', 'useremail', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA op.add_column('useremailclaim', sa.Column('org_id', sa.Integer(), nullable=True)) op.add_column('useremailclaim', sa.Column('team_id', sa.Integer(), nullable=True)) @@ -40,9 +40,9 @@ def upgrade(): op.create_foreign_key('useremailclaim_org_id_fkey', 'useremailclaim', 'organization', ['org_id'], ['id']) op.create_foreign_key('useremailclaim_team_id_fkey', 'useremailclaim', 'team', ['team_id'], ['id']) op.create_check_constraint('useremailclaim_user_id_or_org_id_or_team_id', 'useremailclaim', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA op.alter_column('userphone', 'phone', type_=sa.Unicode(16)) op.add_column('userphone', sa.Column('org_id', sa.Integer(), nullable=True)) @@ -53,9 +53,9 @@ def upgrade(): op.create_foreign_key('userphone_org_id_fkey', 'userphone', 'organization', ['org_id'], ['id']) op.create_foreign_key('userphone_team_id_fkey', 'userphone', 'team', ['team_id'], ['id']) op.create_check_constraint('userphone_user_id_or_org_id_or_team_id', 'userphone', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA op.alter_column('userphoneclaim', 'phone', type_=sa.Unicode(16)) op.add_column('userphoneclaim', sa.Column('org_id', sa.Integer(), nullable=True)) @@ -69,9 +69,9 @@ def upgrade(): op.create_foreign_key('userphoneclaim_org_id_fkey', 'userphoneclaim', 'organization', ['org_id'], ['id']) op.create_foreign_key('userphoneclaim_team_id_fkey', 'userphoneclaim', 'team', ['team_id'], ['id']) op.create_check_constraint('userphoneclaim_user_id_or_org_id_or_team_id', 'userphoneclaim', - sa.case([(column('user_id') != None, 1)], else_=0) + - sa.case([(column('org_id') != None, 1)], else_=0) + - sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA + sa.case([(column('user_id') != None, 1)], else_=0) + + sa.case([(column('org_id') != None, 1)], else_=0) + + sa.case([(column('team_id') != None, 1)], else_=0) == 1) # NOQA def downgrade(): diff --git a/runtests.sh b/runtests.sh index 9803716..3bec107 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e export FLASK_ENV="TESTING" if [ -f secrets.test ]; then diff --git a/runtestserver.py b/runtestserver.py index 7b528d2..aef5f21 100644 --- a/runtestserver.py +++ b/runtestserver.py @@ -5,11 +5,11 @@ sys.setdefaultencoding('utf-8') from lastuserapp import app, db -from lastuser_core.models import * +from lastuser_core.models import User, Organization, Client, Permission -#incase data exists from previously run tests +# incase data exists from previously run tests db.drop_all() -#create schema again +# create schema again db.create_all() # Add fixtures for test app diff --git a/tests/unit/lastuser_core/fixtures.py b/tests/unit/lastuser_core/fixtures.py index fb61b19..63339a6 100644 --- a/tests/unit/lastuser_core/fixtures.py +++ b/tests/unit/lastuser_core/fixtures.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- from lastuserapp import db -from lastuser_core.models import * # NOQA +from lastuser_core.models import (User, UserEmail, UserPhone, Organization, Client, Team, + TeamClientPermissions, ClientTeamAccess, Permission, UserClientPermissions, Resource, + ResourceAction, SMSMessage, CLIENT_TEAM_ACCESS) class Fixtures(object): diff --git a/tests/unit/lastuser_core/test_model_user_User.py b/tests/unit/lastuser_core/test_model_user_User.py index 433f27e..affdfe7 100644 --- a/tests/unit/lastuser_core/test_model_user_User.py +++ b/tests/unit/lastuser_core/test_model_user_User.py @@ -231,7 +231,7 @@ def test_user_phone(self): self.assertTrue(snowball.phone.primary) # scenario 3: when there is no phone on db piglet = self.fixtures.piglet - assert piglet.phone is u'' + assert piglet.phone == u'' def test_user_password(self): """ diff --git a/tests/unit/lastuser_core/test_utils.py b/tests/unit/lastuser_core/test_utils.py index 97fa630..d24c85a 100644 --- a/tests/unit/lastuser_core/test_utils.py +++ b/tests/unit/lastuser_core/test_utils.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- import unittest -from lastuser_core.utils import * # NOQA +from lastuser_core.utils import (strip_phone, valid_phone, get_gravatar_md5sum, make_redirect_url, + mask_email) class FlaskrTestCase(unittest.TestCase): diff --git a/website.py b/website.py index c18cb31..8cb9e13 100644 --- a/website.py +++ b/website.py @@ -2,3 +2,5 @@ import os.path sys.path.insert(0, os.path.dirname(__file__)) from lastuserapp import app as application + +__all__ = ['application']