aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db
diff options
context:
space:
mode:
authortilly-Q <nattilypigeonfowl@gmail.com>2013-07-27 16:44:40 -0400
committertilly-Q <nattilypigeonfowl@gmail.com>2013-07-27 16:44:40 -0400
commit3aa3871b909500ae9198d63814dd79fd28921f93 (patch)
tree02fbde1fcc3c395f19dbb6e5004c6866ee28fb12 /mediagoblin/db
parent6bba33d7e6fbb0cedc39f9a11f816fe5bd372ae7 (diff)
downloadmediagoblin-3aa3871b909500ae9198d63814dd79fd28921f93.tar.lz
mediagoblin-3aa3871b909500ae9198d63814dd79fd28921f93.tar.xz
mediagoblin-3aa3871b909500ae9198d63814dd79fd28921f93.zip
This commit had some important milestones in it. The major update is that now I
have mostly completed the moderator punishment and resolution of reports. Along with this, I have also added one last table to the database: one that holds ar- -chived (or resolved) reports. This is some of the primary functionality of my whole update, so this is a big step! The other changes I made this update are primarily organizational. I refactored some of my code into functions and I cl- eaned up many of my templates. --\ mediagoblin/db/models.py --| Created the new ArchivedReport table --| Removed columns from BaseReport table that are only necessary for Archived | reports --\ mediagoblin/db/migrations.py --| Created the new ArchivedReport table --| Removed columns from BaseReport table that are only necessary for Archived | reports --\ mediagoblin/db/util.py --| Created the user_privileges_to_dictionary function. This is useful for | accessing a user's permissions from within a template. --\ mediagoblin/moderation/forms.py --| Expanded the disciplinary actions a moderator can take --| Allowed the moderator to choose more than one disciplinary action at a time | (It's now managed with a list of checkboxes rather than radio buttons) ----| Pulled a MultiCheckBox class from a wtforms tutorial --| Added various other form inputs for details of the moderator's disciplinary | actions --| Tried to ensure that every string is unicode and translated --\ mediagoblin/moderation/tools.py --| Created this file for holding useful moderation tools --| Moved the penalizing code from views to the function take_punitive_actions --| Added many more types of punitive actions --| Added the archiving of old reports --\ mediagoblin/moderation/views.py --| Used the privileges_to_dictionary function for the Users Detail view to | allow for different actions available to a moderator and an admin. --| Added in functionality for ArchivedReports to the reports_detail and | reports_panel views --| Moved the punishments of repots_detail to tools.py (as mentioned above) --\ mediagoblin/static/css/base.css --| Added new styling for the User Detail page --\ mediagoblin/static/images/icon_clipboard_alert.png --| Added this image to represent unresolved reports --\ mediagoblin/templates/mediagoblin/moderation/report.html --| Added 'Return to Reports Panel' button --| Fixed the spacing to be less that 80 columns wide --| Added in display for Archived Reports --\ mediagoblin/templates/mediagoblin/moderation/reports_panel.html --| Changed the placement and columns of the tables --| Fixed the spacing to be less that 80 columns wide --| Added in display for Archived Reports --\ mediagoblin/templates/mediagoblin/moderation/user.html --| Fixed the spacing to be less that 80 columns wide --| Took away the moderator's ability to add and remove privileges at will. | Only the admin has this power now. --\ mediagoblin/templates/mediagoblin/moderation/users_panel.html --| Fixed the spacing to be less that 80 columns wide --\ mediagoblin/tools/response.py --| Added in code to remove a UserBan from a User if that user logs in after | the expiration date
Diffstat (limited to 'mediagoblin/db')
-rw-r--r--mediagoblin/db/migrations.py20
-rw-r--r--mediagoblin/db/models.py46
-rw-r--r--mediagoblin/db/util.py19
3 files changed, 73 insertions, 12 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py
index 3e6791c4..247298ac 100644
--- a/mediagoblin/db/migrations.py
+++ b/mediagoblin/db/migrations.py
@@ -299,8 +299,6 @@ class ReportBase_v0(declarative_base()):
report_content = Column(UnicodeText)
reported_user_id = Column(Integer, ForeignKey(User.id), nullable=False)
created = Column(DateTime, nullable=False, default=datetime.datetime.now)
- resolved = Column(DateTime)
- result = Column(UnicodeText)
discriminator = Column('type', Unicode(50))
__mapper_args__ = {'polymorphic_on': discriminator}
@@ -317,13 +315,20 @@ 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)
+ id = Column('id',Integer, ForeignKey('core__reports.id'), primary_key=True)
media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False)
+class ArchivedReport_v0(ReportBase_v0):
+ __tablename__ = 'core__reports_archived'
+ __mapper_args__ = {'polymorphic_identity': 'archived_report'}
+
+ id = Column('id',Integer, ForeignKey('core__reports.id'))
+
+ media_entry_id = Column(Integer, ForeignKey(MediaEntry.id))
+ comment_id = Column(Integer, ForeignKey(MediaComment.id))
+ resolver_id = Column(Integer, ForeignKey(User.id), nullable=False)
+ resolved_time = Column(DateTime)
+ result = Column(UnicodeText)
class UserBan_v0(declarative_base()):
__tablename__ = 'core__user_bans'
@@ -356,6 +361,7 @@ def create_moderation_tables(db):
ReportBase_v0.__table__.create(db.bind)
CommentReport_v0.__table__.create(db.bind)
MediaReport_v0.__table__.create(db.bind)
+ ArchivedReport_v0.__table__.create(db.bind)
UserBan_v0.__table__.create(db.bind)
Privilege_v0.__table__.create(db.bind)
PrivilegeUserAssociation_v0.__table__.create(db.bind)
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 01078db8..c85d546f 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -515,11 +515,18 @@ class ReportBase(Base):
cascade="all, delete-orphan"),
primaryjoin="User.id==ReportBase.reported_user_id")
created = Column(DateTime, nullable=False, default=datetime.datetime.now())
- resolved = Column(DateTime)
- result = Column(UnicodeText)
discriminator = Column('type', Unicode(50))
__mapper_args__ = {'polymorphic_on': discriminator}
+ def is_comment_report(self):
+ return self.discriminator=='comment_report'
+
+ def is_media_entry_report(self):
+ return self.discriminator=='media_report'
+
+ def is_archived_report(self):
+ return self.discriminator=='archived_report'
+
class CommentReport(ReportBase):
"""
@@ -548,10 +555,40 @@ class MediaReport(ReportBase):
media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False)
media_entry = relationship(
MediaEntry,
- backref=backref("reports_filed_on",
+ backref=backref("reports_filed_onmod/reports/1/",
lazy="dynamic",
cascade="all, delete-orphan"))
+class ArchivedReport(ReportBase):
+ """
+ A table to keep track of reports that have been resolved
+ """
+ __tablename__ = 'core__reports_archived'
+ __mapper_args__ = {'polymorphic_identity': 'archived_report'}
+ id = Column('id',Integer, ForeignKey('core__reports.id'),
+ primary_key=True)
+
+ media_entry_id = Column(Integer, ForeignKey(MediaEntry.id))
+ media_entry = relationship(
+ MediaEntry,
+ backref=backref("past_reports_filed_on",
+ lazy="dynamic"))
+ comment_id = Column(Integer, ForeignKey(MediaComment.id))
+ comment = relationship(
+ MediaComment, backref=backref("past_reports_filed_on",
+ lazy="dynamic"))
+
+ resolver_id = Column(Integer, ForeignKey(User.id), nullable=False)
+ resolver = relationship(
+ User,
+ backref=backref("reports_resolved_by",
+ lazy="dynamic",
+ cascade="all, delete-orphan"),
+ primaryjoin="User.id==ArchivedReport.resolver_id")
+
+ resolved = Column(DateTime)
+ result = Column(UnicodeText)
+
class UserBan(Base):
"""
Holds the information on a specific user's ban-state. As long as one of
@@ -641,7 +678,8 @@ privilege_foundations = [[u'admin'], [u'moderator'], [u'uploader'],[u'reporter']
MODELS = [
User, MediaEntry, Tag, MediaTag, MediaComment, Collection, CollectionItem,
MediaFile, FileKeynames, MediaAttachmentFile, ProcessingMetaData, ReportBase,
- CommentReport, MediaReport, UserBan, Privilege, PrivilegeUserAssociation]
+ CommentReport, MediaReport, UserBan, Privilege, PrivilegeUserAssociation,
+ ArchivedReport]
# Foundations are the default rows that are created immediately after the tables are initialized. Each entry to
# this dictionary should be in the format of
diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py
index 6ffec44d..1aa0a63c 100644
--- a/mediagoblin/db/util.py
+++ b/mediagoblin/db/util.py
@@ -15,7 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin.db.base import Session
-from mediagoblin.db.models import MediaEntry, Tag, MediaTag, Collection
+from mediagoblin.db.models import (MediaEntry, Tag, MediaTag, Collection, \
+ User, Privilege, FOUNDATIONS)
##########################
@@ -67,6 +68,22 @@ 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]
+ for privilege_name in FOUNDATIONS[Privilege]:
+ privilege_name = privilege_name[0]
+ 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