diff options
Diffstat (limited to 'mediagoblin/db')
-rw-r--r-- | mediagoblin/db/migrations.py | 20 | ||||
-rw-r--r-- | mediagoblin/db/models.py | 60 | ||||
-rw-r--r-- | mediagoblin/db/util.py | 18 |
3 files changed, 40 insertions, 58 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 762d17e6..a97458b6 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -28,7 +28,7 @@ from migrate.changeset.constraint import UniqueConstraint from mediagoblin.db.extratypes import JSONEncoded 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, Privilege, ReportBase) MIGRATIONS = {} @@ -425,7 +425,7 @@ class RequestToken_v0(declarative_base()): callback = Column(Unicode, nullable=False, default=u"oob") created = Column(DateTime, nullable=False, default=datetime.datetime.now) updated = Column(DateTime, nullable=False, default=datetime.datetime.now) - + class AccessToken_v0(declarative_base()): """ Model for representing the access tokens @@ -438,7 +438,7 @@ class AccessToken_v0(declarative_base()): request_token = Column(Unicode, ForeignKey(RequestToken_v0.token)) created = Column(DateTime, nullable=False, default=datetime.datetime.now) updated = Column(DateTime, nullable=False, default=datetime.datetime.now) - + class NonceTimestamp_v0(declarative_base()): """ @@ -467,7 +467,7 @@ class ReportBase_v0(declarative_base()): 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) + created = Column(DateTime, nullable=False, default=datetime.datetime.now) discriminator = Column('type', Unicode(50)) __mapper_args__ = {'polymorphic_on': discriminator} @@ -512,14 +512,14 @@ class Privilege_v0(declarative_base()): class PrivilegeUserAssociation_v0(declarative_base()): __tablename__ = 'core__privileges_users' group_id = Column( - 'core__privilege_id', - Integer, - ForeignKey(User.id), + 'core__privilege_id', + Integer, + ForeignKey(User.id), primary_key=True) user_id = Column( - 'core__user_id', - Integer, - ForeignKey(Privilege.id), + 'core__user_id', + Integer, + ForeignKey(Privilege.id), primary_key=True) @RegisterMigration(15, MIGRATIONS) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 62c5a5d5..dd2cd3e9 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -669,7 +669,7 @@ class ReportBase(Base): id = Column(Integer, primary_key=True) reporter_id = Column(Integer, ForeignKey(User.id), nullable=False) reporter = relationship( - User, + User, backref=backref("reports_filed_by", lazy="dynamic", cascade="all, delete-orphan"), @@ -677,7 +677,7 @@ class ReportBase(Base): report_content = Column(UnicodeText) reported_user_id = Column(Integer, ForeignKey(User.id), nullable=False) reported_user = relationship( - User, + User, backref=backref("reports_filed_on", lazy="dynamic", cascade="all, delete-orphan"), @@ -722,7 +722,7 @@ class MediaReport(ReportBase): primary_key=True) media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False) media_entry = relationship( - MediaEntry, + MediaEntry, backref=backref("reports_filed_onmod/reports/1/", lazy="dynamic", cascade="all, delete-orphan")) @@ -738,7 +738,7 @@ class ArchivedReport(ReportBase): media_entry_id = Column(Integer, ForeignKey(MediaEntry.id)) media_entry = relationship( - MediaEntry, + MediaEntry, backref=backref("past_reports_filed_on", lazy="dynamic")) comment_id = Column(Integer, ForeignKey(MediaComment.id)) @@ -748,7 +748,7 @@ class ArchivedReport(ReportBase): resolver_id = Column(Integer, ForeignKey(User.id), nullable=False) resolver = relationship( - User, + User, backref=backref("reports_resolved_by", lazy="dynamic", cascade="all, delete-orphan"), @@ -759,23 +759,23 @@ class ArchivedReport(ReportBase): 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 + 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 - :keyword user_id Holds the id of the user this object is - attached to. This is a one-to-one + :keyword user_id Holds the id of the user this object is + attached to. This is a one-to-one relationship. - :keyword expiration_date Holds the date that the ban will be lifted. - If this is null, the ban is permanent + :keyword 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. :keyword reason Holds the reason why the user was banned. """ __tablename__ = 'core__user_bans' - user_id = Column(Integer, ForeignKey(User.id), nullable=False, + user_id = Column(Integer, ForeignKey(User.id), nullable=False, primary_key=True) expiration_date = Column(DateTime) reason = Column(UnicodeText, nullable=False) @@ -785,21 +785,21 @@ class Privilege(Base): """ The Privilege table holds all of the different privileges a user can hold. If a user 'has' a privilege, the User object is in a relationship with the - privilege object. + privilege object. :keyword privilege_name Holds a unicode object that is the recognizable - name of this privilege. This is the column + name of this privilege. This is the column used for identifying whether or not a user has a necessary privilege or not. - + """ __tablename__ = 'core__privileges' id = Column(Integer, nullable=False, primary_key=True) privilege_name = Column(Unicode, nullable=False, unique=True) all_users = relationship( - User, - backref='all_privileges', + User, + backref='all_privileges', secondary="core__privileges_users") def __init__(self, privilege_name): @@ -818,25 +818,25 @@ class PrivilegeUserAssociation(Base): ''' This table holds the many-to-many relationship between User and Privilege ''' - + __tablename__ = 'core__privileges_users' privilege_id = Column( - 'core__privilege_id', - Integer, - ForeignKey(User.id), + 'core__privilege_id', + Integer, + ForeignKey(User.id), primary_key=True) user_id = Column( - 'core__user_id', - Integer, - ForeignKey(Privilege.id), + 'core__user_id', + Integer, + ForeignKey(Privilege.id), primary_key=True) MODELS = [ User, MediaEntry, Tag, MediaTag, MediaComment, Collection, CollectionItem, MediaFile, FileKeynames, MediaAttachmentFile, ProcessingMetaData, Notification, CommentNotification, ProcessingNotification, Client, - CommentSubscription, ReportBase, CommentReport, MediaReport, UserBan, + CommentSubscription, ReportBase, CommentReport, MediaReport, UserBan, Privilege, PrivilegeUserAssociation, ArchivedReport, RequestToken, AccessToken, NonceTimestamp] @@ -854,10 +854,10 @@ MODELS = [ FOUNDATIONS = {User:user_foundations} """ -privilege_foundations = [{'privilege_name':u'admin'}, - {'privilege_name':u'moderator'}, +privilege_foundations = [{'privilege_name':u'admin'}, + {'privilege_name':u'moderator'}, {'privilege_name':u'uploader'}, - {'privilege_name':u'reporter'}, + {'privilege_name':u'reporter'}, {'privilege_name':u'commenter'}, {'privilege_name':u'active'}] FOUNDATIONS = {Privilege:privilege_foundations} diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 31fc49fb..2488dcac 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -68,24 +68,6 @@ def check_collection_slug_used(creator_id, slug, ignore_c_id): does_exist = Session.query(Collection.id).filter(filt).first() is not None return does_exist -def user_privileges_to_dictionary(user_id): - """ - This function accepts a users id and returns a dictionary of True or False - values for each privilege the user does or does not have. This allows for - easier referencing of a user's privileges inside templates. - """ - privilege_dictionary = {} - user = User.query.get(user_id) - users_privileges = [p_item.privilege_name for p_item in user.all_privileges] - #TODO update this to account for plugins that may add foundations - for privilege in FOUNDATIONS[Privilege]: - privilege_name = privilege['privilege_name'] - if privilege_name in users_privileges: - privilege_dictionary[privilege_name]=True - else: - privilege_dictionary[privilege_name]=False - return privilege_dictionary - if __name__ == '__main__': from mediagoblin.db.open import setup_connection_and_db_from_config |