
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
94 lines
3.4 KiB
Python
94 lines
3.4 KiB
Python
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# 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, \
|
|
User, Privilege, FOUNDATIONS)
|
|
|
|
|
|
##########################
|
|
# Random utility functions
|
|
##########################
|
|
|
|
|
|
def atomic_update(table, query_dict, update_values):
|
|
table.find(query_dict).update(update_values,
|
|
synchronize_session=False)
|
|
Session.commit()
|
|
|
|
|
|
def check_media_slug_used(uploader_id, slug, ignore_m_id):
|
|
query = MediaEntry.query.filter_by(uploader=uploader_id, slug=slug)
|
|
if ignore_m_id is not None:
|
|
query = query.filter(MediaEntry.id != ignore_m_id)
|
|
does_exist = query.first() is not None
|
|
return does_exist
|
|
|
|
|
|
def media_entries_for_tag_slug(dummy_db, tag_slug):
|
|
return MediaEntry.query \
|
|
.join(MediaEntry.tags_helper) \
|
|
.join(MediaTag.tag_helper) \
|
|
.filter(
|
|
(MediaEntry.state == u'processed')
|
|
& (Tag.slug == tag_slug))
|
|
|
|
|
|
def clean_orphan_tags(commit=True):
|
|
"""Search for unused MediaTags and delete them"""
|
|
q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id==None)
|
|
for t in q1:
|
|
Session.delete(t)
|
|
# The "let the db do all the work" version:
|
|
# q1 = Session.query(Tag.id).outerjoin(MediaTag).filter(MediaTag.id==None)
|
|
# q2 = Session.query(Tag).filter(Tag.id.in_(q1))
|
|
# q2.delete(synchronize_session = False)
|
|
if commit:
|
|
Session.commit()
|
|
|
|
|
|
def check_collection_slug_used(creator_id, slug, ignore_c_id):
|
|
filt = (Collection.creator == creator_id) \
|
|
& (Collection.slug == slug)
|
|
if ignore_c_id is not None:
|
|
filt = filt & (Collection.id != 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
|
|
|
|
db = setup_connection_and_db_from_config({'sql_engine':'sqlite:///mediagoblin.db'})
|
|
|
|
clean_orphan_tags()
|