diff options
Diffstat (limited to 'mediagoblin/db')
-rw-r--r-- | mediagoblin/db/migrations.py | 69 | ||||
-rw-r--r-- | mediagoblin/db/models.py | 88 |
2 files changed, 154 insertions, 3 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 2c553396..110a48d4 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -26,7 +26,7 @@ from sqlalchemy.sql import and_ from migrate.changeset.constraint import UniqueConstraint from mediagoblin.db.migration_tools import RegisterMigration, inspect_table -from mediagoblin.db.models import MediaEntry, Collection, User +from mediagoblin.db.models import MediaEntry, Collection, User, MediaComment, Group MIGRATIONS = {} @@ -287,3 +287,70 @@ def unique_collections_slug(db): constraint.create() 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) + created = Column(DateTime, nullable=False, default=datetime.datetime.now) + resolved = Column(DateTime) + discriminator = Column('type', Unicode(50)) + __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) + +@RegisterMigration(11, MIGRATIONS) +def create_report_tables(db): + ReportBase_v0.__table__.create(db.bind) + CommentReport_v0.__table__.create(db.bind) + MediaReport_v0.__table__.create(db.bind) + db.commit() + +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(DateTime) + reason = Column(UnicodeText, nullable=False) + +class Group_v0(declarative_base()): + __tablename__ = 'core__groups' + id = Column(Integer, nullable=False, primary_key=True) + group_name = Column(Unicode, nullable=False) + +class GroupUserAssociation_v0(declarative_base()): + __tablename__ = 'core__group_user_associations' + + group_id = Column('core__group_id', Integer, ForeignKey(User.id), primary_key=True) + user_id = Column('core__user_id', Integer, ForeignKey(Group.id), primary_key=True) + + + +@RegisterMigration(12, MIGRATIONS) +def create_banned_and_group_tables(db): + UserBan_v0.__table__.create(db.bind) + Group_v0.__table__.create(db.bind) + GroupUserAssociation_v0.__table__.create(db.bind) + db.commit() + + + diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 2b925983..f524b220 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -29,6 +29,7 @@ from sqlalchemy.orm.collections import attribute_mapped_collection from sqlalchemy.sql.expression import desc from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.util import memoized_property +from sqlalchemy.schema import Table from mediagoblin.db.extratypes import PathTupleWithSlashes, JSONEncoded from mediagoblin.db.base import Base, DictReadAttrProxy @@ -484,10 +485,93 @@ class ProcessingMetaData(Base): return DictReadAttrProxy(self) +class ReportBase(Base): + """ + + """ + __tablename__ = 'core__reports' + id = Column(Integer, primary_key=True) + reporter_id = Column(Integer, ForeignKey(User.id), nullable=False) + reporter = relationship(User, backref=backref("reports_filed_by", + lazy="dynamic", + cascade="all, delete-orphan")) + report_content = Column(UnicodeText) + created = Column(DateTime, nullable=False, default=datetime.datetime.now()) + resolved = Column(DateTime) + discriminator = Column('type', Unicode(50)) + __mapper_args__ = {'polymorphic_on': discriminator} + + +class CommentReport(ReportBase): + """ + A class to keep track of reports that have been filed on comments + """ + __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) + comment = relationship(MediaComment, backref=backref("reports_filed_on", + lazy="dynamic", + cascade="all, delete-orphan")) + +class MediaReport(ReportBase): + """ + A class to keep track of reports that have been filed on media entries + """ + __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) + media_entry = relationship(MediaEntry, backref=backref("reports_filed_on", + lazy="dynamic", + cascade="all, delete-orphan")) + +class UserBan(Base): + """ + Holds the information on a specific user's ban-state. As long as one of these + is attached to a user, they are banned from accessing mediagoblin. When they + try to log in, they are greeted with a page that tells them the reason why + they are banned and when (if ever) the ban will be lifted + :param user_id Holds the id of the user this object is attached to. + This should be a one-to-one relationship. + :param expiration_date Holds the date that the ban will be lifted. If this + is null, the ban is permanent unless a moderator + manually lifts it. + :param reason Holds the reason why the user was banned. + """ + __tablename__ = 'core__user_bans' + + user_id = Column('id',Integer, ForeignKey(User.id), nullable=False, + primary_key=True) + expiration_date = Column(DateTime) + reason = Column(UnicodeText, nullable=False) + + +class Group(Base): + __tablename__ = 'core__groups' + + id = Column(Integer, nullable=False, primary_key=True) + group_name = Column(Unicode, nullable=False) + all_users = relationship(User, backref='all_groups', secondary="core__group_user_associations") + + def __repr__(self): + return "<Group %s>" % (self.group_name) + +class GroupUserAssociation(Base): + __tablename__ = 'core__group_user_associations' + + group_id = Column('core__group_id', Integer, ForeignKey(User.id), primary_key=True) + user_id = Column('core__user_id', Integer, ForeignKey(Group.id), primary_key=True) + + + MODELS = [ User, MediaEntry, Tag, MediaTag, MediaComment, Collection, CollectionItem, MediaFile, FileKeynames, - MediaAttachmentFile, ProcessingMetaData] - + MediaAttachmentFile, ProcessingMetaData, CommentReport, MediaReport, UserBan, Group, GroupUserAssociation] ###################################################### # Special, migrations-tracking table |