Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Database changes for project-level admin
Browse files Browse the repository at this point in the history
Summary: Added a new column, project_permissions, to the User model to keep track of projects that users will have access to.

Test Plan: the local dev environment worked fine

Reviewers: anupc

Reviewed By: anupc

Subscribers: changesbot, kylec

Differential Revision: https://tails.corp.dropbox.com/D221719
  • Loading branch information
Naphat Sanguansin committed Aug 19, 2016
1 parent 5ec4000 commit 6dd9771
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions changes/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from datetime import datetime
from sqlalchemy import Boolean, Column, String, DateTime
from sqlalchemy.dialects.postgresql import ARRAY

from changes.config import db
from changes.db.types.guid import GUID
Expand All @@ -18,6 +19,13 @@ class User(db.Model):
is_admin = Column(Boolean, default=False, nullable=False)
date_created = Column(DateTime, default=datetime.utcnow)

# this keeps track of the list of wildcard patterns of project names that
# the user has access to. For example:
# - `foo` matches `foo`
# - `foo.*` matches anything starting with `foo.`, like `foo.staging`, `foo.`
# - `*foo*` matches anything containing `foo`, like `barfoobar`, `foo`
project_permissions = Column(ARRAY(String(256)), nullable=False, default=[])

def __init__(self, **kwargs):
super(User, self).__init__(**kwargs)
if not self.id:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""add project_permissions column to user
Revision ID: 460741ff1212
Revises: 3b94584c761e
Create Date: 2016-08-19 09:26:10.731482
"""

# revision identifiers, used by Alembic.
revision = '460741ff1212'
down_revision = '3b94584c761e'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


def upgrade():
op.add_column('user', sa.Column('project_permissions', postgresql.ARRAY(sa.String(length=256)), nullable=False, default=[]))


def downgrade():
op.drop_column('user', 'project_permissions')

0 comments on commit 6dd9771

Please sign in to comment.