Merge branch 'master' into OPW-Moderation-Update
authortilly-Q <nattilypigeonfowl@gmail.com>
Thu, 12 Sep 2013 22:58:04 +0000 (18:58 -0400)
committertilly-Q <nattilypigeonfowl@gmail.com>
Thu, 12 Sep 2013 22:58:04 +0000 (18:58 -0400)
Conflicts:
mediagoblin/db/migrations.py

1  2 
mediagoblin/auth/views.py
mediagoblin/db/migrations.py
mediagoblin/db/models.py
mediagoblin/edit/views.py
mediagoblin/templates/mediagoblin/base.html
mediagoblin/tests/test_edit.py
mediagoblin/tests/test_notifications.py

Simple merge
index eb3f98801d67bd916b209fad6ffc2271eae98b9c,62fb7e8dd3026b848c77bd4929d62744d0970e93..2e05bf2ade26cc7cf222d06246f374047fc6321b
@@@ -462,110 -463,14 +465,122 @@@ def create_oauth1_tables(db)
  
      db.commit()
  
 -
+ @RegisterMigration(15, MIGRATIONS)
+ def wants_notifications(db):
+     """Add a wants_notifications field to User model"""
+     metadata = MetaData(bind=db.bind)
+     user_table = inspect_table(metadata, "core__users")
- @RegisterMigration(15, MIGRATIONS)
+     col = Column('wants_notifications', Boolean, default=True)
+     col.create(user_table)
++    db.commit()
++
 +class ReportBase_v0(declarative_base()):
 +    __tablename__ = 'core__reports'
 +    id = Column(Integer, primary_key=True)
 +    reporter_id = Column(Integer, ForeignKey(User.id), nullable=False)
 +    report_content = Column(UnicodeText)
 +    reported_user_id = Column(Integer, ForeignKey(User.id), nullable=False)
 +    created = Column(DateTime, nullable=False, default=datetime.datetime.now)
 +    discriminator = Column('type', Unicode(50))
 +    resolver_id = Column(Integer, ForeignKey(User.id))
 +    resolved = Column(DateTime)
 +    result = Column(UnicodeText)
 +    __mapper_args__ = {'polymorphic_on': discriminator}
 +
 +class CommentReport_v0(ReportBase_v0):
 +    __tablename__ = 'core__reports_on_comments'
 +    __mapper_args__ = {'polymorphic_identity': 'comment_report'}
 +
 +    id = Column('id',Integer, ForeignKey('core__reports.id'),
 +                                                primary_key=True)
 +    comment_id = Column(Integer, ForeignKey(MediaComment.id), nullable=False)
 +
++
++
 +class MediaReport_v0(ReportBase_v0):
 +    __tablename__ = 'core__reports_on_media'
 +    __mapper_args__ = {'polymorphic_identity': 'media_report'}
 +
 +    id = Column('id',Integer, ForeignKey('core__reports.id'), primary_key=True)
 +    media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False)
 +
 +class UserBan_v0(declarative_base()):
 +    __tablename__ = 'core__user_bans'
 +    user_id = Column('id',Integer, ForeignKey(User.id), nullable=False,
 +                                         primary_key=True)
 +    expiration_date = Column(Date)
 +    reason = Column(UnicodeText, nullable=False)
 +
 +class Privilege_v0(declarative_base()):
 +    __tablename__ = 'core__privileges'
 +    id = Column(Integer, nullable=False, primary_key=True, unique=True)
 +    privilege_name = Column(Unicode, nullable=False, unique=True)
 +
 +class PrivilegeUserAssociation_v0(declarative_base()):
 +    __tablename__ = 'core__privileges_users'
 +    group_id = Column(
 +        'core__privilege_id',
 +        Integer,
 +        ForeignKey(User.id),
 +        primary_key=True)
 +    user_id = Column(
 +        'core__user_id',
 +        Integer,
 +        ForeignKey(Privilege.id),
 +        primary_key=True)
 +
++@RegisterMigration(16, MIGRATIONS)
 +def create_moderation_tables(db):
 +    ReportBase_v0.__table__.create(db.bind)
 +    CommentReport_v0.__table__.create(db.bind)
 +    MediaReport_v0.__table__.create(db.bind)
 +    UserBan_v0.__table__.create(db.bind)
 +    Privilege_v0.__table__.create(db.bind)
 +    PrivilegeUserAssociation_v0.__table__.create(db.bind)
  
      db.commit()
- @RegisterMigration(16, MIGRATIONS)
 +
 +    for parameters in FOUNDATIONS[Privilege]:
 +        p = Privilege(**parameters)
 +        p.save()
 +
 +
++@RegisterMigration(17, MIGRATIONS)
 +def update_user_privilege_columns(db):
 +    # first, create the privileges which would be created by foundations
 +    default_privileges = Privilege.query.filter(
 +        Privilege.privilege_name !=u'admin').filter(
 +        Privilege.privilege_name !=u'moderator').filter(
 +        Privilege.privilege_name !=u'active').all()
 +    admin_privilege = Privilege.query.filter(
 +        Privilege.privilege_name ==u'admin').first()
 +    active_privilege = Privilege.query.filter(
 +        Privilege.privilege_name ==u'active').first()
 +    # then, assign them to the appropriate users
 +    for inactive_user in User.query.filter(
 +        User.status!=u'active').filter(
 +        User.is_admin==False).all():
 +
 +        inactive_user.all_privileges = default_privileges
 +        inactive_user.save()
 +    for user in User.query.filter(
 +        User.status==u'active').filter(
 +        User.is_admin==False).all():
 +
 +        user.all_privileges = default_privileges + [active_privilege]
 +        user.save()
 +    for admin_user in User.query.filter(
 +        User.is_admin==True).all():
 +
 +        admin_user.all_privileges = default_privileges + [
 +            admin_privilege, active_privilege]
 +        admin_user.save()
 +
 +    # and then drop the now vestigial status column
 +    metadata = MetaData(bind=db.bind)
 +    user_table = inspect_table(metadata, 'core__users')
 +    status = user_table.columns['status']
 +    status.drop()
 +    db.commit()
 +
index 3f9fde3a596c3f9c889d5a0e72e8aadf3750b4cc,4341e086fe922782cf2c39beae662e1332b3688e..cec311f2aeb9bfc169d356e513d2973b2bbcc635
@@@ -70,9 -68,9 +70,10 @@@ class User(Base, UserMixin)
      # Intented to be nullable=False, but migrations would not work for it
      # set to nullable=True implicitly.
      wants_comment_notification = Column(Boolean, default=True)
+     wants_notifications = Column(Boolean, default=True)
      license_preference = Column(Unicode)
 +#--column admin is VESTIGIAL with privileges and should not be used------------
 +#--should be dropped ASAP though a bug in sqlite3 prevents this atm------------
      is_admin = Column(Boolean, default=False, nullable=False)
      url = Column(Unicode)
      bio = Column(UnicodeText)  # ??
Simple merge
Simple merge