From 0a5981fd5416c60858c3e460f943692d1c62629d Mon Sep 17 00:00:00 2001
From: tilly-Q
Date: Fri, 29 Nov 2013 14:29:56 -0500
Subject: [PATCH 01/10] In this commit I made it so that each deployment can
have custom settings for which privileges are given to users when they are
intiated. These settings are modified in mediagoblin.ini.
---
mediagoblin.ini | 1 +
mediagoblin/auth/__init__.py | 1 -
mediagoblin/auth/tools.py | 14 +++++++++-----
mediagoblin/config_spec.ini | 3 +++
4 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/mediagoblin.ini b/mediagoblin.ini
index 934858a2..19c3e4b0 100644
--- a/mediagoblin.ini
+++ b/mediagoblin.ini
@@ -35,6 +35,7 @@ allow_reporting = true
## If you want the terms of service displayed, you can uncomment this
# show_tos = true
+user_privilege_scheme= "uploader,commenter,reporter"
[storage:queuestore]
base_dir = %(here)s/user_dev/media/queue
diff --git a/mediagoblin/auth/__init__.py b/mediagoblin/auth/__init__.py
index be5d0eed..f518a09d 100644
--- a/mediagoblin/auth/__init__.py
+++ b/mediagoblin/auth/__init__.py
@@ -25,7 +25,6 @@ def create_user(register_form):
results = hook_runall("auth_create_user", register_form)
return results[0]
-
def extra_validation(register_form):
from mediagoblin.auth.tools import basic_extra_validation
diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py
index 88716e1c..191a2b9d 100644
--- a/mediagoblin/auth/tools.py
+++ b/mediagoblin/auth/tools.py
@@ -132,11 +132,7 @@ def register_user(request, register_form):
user = auth.create_user(register_form)
# give the user the default privileges
- default_privileges = [
- Privilege.query.filter(Privilege.privilege_name==u'commenter').first(),
- Privilege.query.filter(Privilege.privilege_name==u'uploader').first(),
- Privilege.query.filter(Privilege.privilege_name==u'reporter').first()]
- user.all_privileges += default_privileges
+ user.all_privileges += get_default_privileges(user)
user.save()
# log the user in
@@ -151,6 +147,14 @@ def register_user(request, register_form):
return None
+def get_default_privileges(user):
+ instance_privilege_scheme = mg_globals.app_config['user_privilege_scheme']
+ default_privileges = [Privilege.query.filter(
+ Privilege.privilege_name==privilege_name).first()
+ for privilege_name in instance_privilege_scheme.split(',')]
+ default_privileges = [privilege for privilege in default_privileges if not privilege == None]
+
+ return default_privileges
def check_login_simple(username, password):
user = auth.get_user(username=username)
diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index cc1ac637..a29b481e 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -89,6 +89,9 @@ upload_limit = integer(default=None)
# Max file size (in Mb)
max_file_size = integer(default=None)
+# Privilege scheme
+user_privilege_scheme = string(default="")
+
[jinja2]
# Jinja2 supports more directives than the minimum required by mediagoblin.
# This setting allows users creating custom templates to specify a list of
From f4a5325e677e5fb4ce9519ad29843e1e4645423d Mon Sep 17 00:00:00 2001
From: Berker Peksag
Date: Fri, 21 Feb 2014 10:20:03 +0200
Subject: [PATCH 02/10] Tweak the trim whitespace plugin documentation.
- Fix code highlighting
- Wrap all lines to 80 chars
- Add more markup (eg. Response() to ``Response()``)
---
mediagoblin/plugins/trim_whitespace/README.rst | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/mediagoblin/plugins/trim_whitespace/README.rst b/mediagoblin/plugins/trim_whitespace/README.rst
index b55ce35e..db9a0c53 100644
--- a/mediagoblin/plugins/trim_whitespace/README.rst
+++ b/mediagoblin/plugins/trim_whitespace/README.rst
@@ -3,17 +3,22 @@
=======================
Mediagoblin templates are written with 80 char limit for better
-readability. However that means that the html output is very verbose
-containing LOTS of whitespace. This plugin inserts a Middleware that
-filters out whitespace from the returned HTML in the Response() objects.
+readability. However that means that the HTML output is very verbose
+containing *lots* of whitespace. This plugin inserts a middleware that
+filters out whitespace from the returned HTML in the ``Response()``
+objects.
-Simply enable this plugin by putting it somewhere where python can reach it and put it's path into the [plugins] section of your mediagoblin.ini or mediagoblin_local.ini like for example this:
+Simply enable this plugin by putting it somewhere where Python can reach
+it and put it's path into the ``[plugins]`` section of your
+``mediagoblin.ini`` or ``mediagoblin_local.ini`` like for example this:
+
+.. code-block:: ini
[plugins]
[[mediagoblin.plugins.trim_whitespace]]
There is no further configuration required. If this plugin is enabled,
-all text/html documents should not have lots of whitespace in between
+all *text/html* documents should not have lots of whitespace in between
elements, although it does a very naive filtering right now (just keep
the first whitespace and delete all subsequent ones).
From 521824da5c34b7e2aa22f6dceed03ead1791d266 Mon Sep 17 00:00:00 2001
From: Berker Peksag
Date: Sun, 23 Feb 2014 16:20:03 +0200
Subject: [PATCH 03/10] Issue #824: Add gmg deletemedia command.
---
mediagoblin/gmg_commands/__init__.py | 4 +++
mediagoblin/gmg_commands/deletemedia.py | 38 +++++++++++++++++++++++++
2 files changed, 42 insertions(+)
create mode 100644 mediagoblin/gmg_commands/deletemedia.py
diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py
index a1eb599d..9de4130e 100644
--- a/mediagoblin/gmg_commands/__init__.py
+++ b/mediagoblin/gmg_commands/__init__.py
@@ -53,6 +53,10 @@ SUBCOMMAND_MAP = {
'setup': 'mediagoblin.gmg_commands.addmedia:parser_setup',
'func': 'mediagoblin.gmg_commands.addmedia:addmedia',
'help': 'Reprocess media entries'},
+ 'deletemedia': {
+ 'setup': 'mediagoblin.gmg_commands.deletemedia:parser_setup',
+ 'func': 'mediagoblin.gmg_commands.deletemedia:deletemedia',
+ 'help': 'Delete media entries'},
# 'theme': {
# 'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup',
# 'func': 'mediagoblin.gmg_commands.theme:theme',
diff --git a/mediagoblin/gmg_commands/deletemedia.py b/mediagoblin/gmg_commands/deletemedia.py
new file mode 100644
index 00000000..d08e76cc
--- /dev/null
+++ b/mediagoblin/gmg_commands/deletemedia.py
@@ -0,0 +1,38 @@
+# 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 .
+
+from mediagoblin.gmg_commands import util as commands_util
+
+
+def parser_setup(subparser):
+ subparser.add_argument('media_ids',
+ help='Comma separated list of media IDs to will be deleted.')
+
+
+def deletemedia(args):
+ app = commands_util.setup_app(args)
+
+ media_ids = set(map(int, args.media_ids.split(',')))
+ found_medias = set()
+ filter_ids = app.db.MediaEntry.id.in_(media_ids)
+ medias = app.db.MediaEntry.query.filter(filter_ids).all()
+ for media in medias:
+ found_medias.add(media.id)
+ media.delete()
+ print 'Media ID %d has been deleted.' % media.id
+ for media in media_ids - found_medias:
+ print 'Can\'t find a media with ID %d.' % media
+ print 'Done.'
From de6a313c5a3ca9bd7beaf92addb6da0bbe3ad0c2 Mon Sep 17 00:00:00 2001
From: Berker Peksag
Date: Sun, 23 Feb 2014 14:47:09 +0200
Subject: [PATCH 04/10] Issue #686: Create User.url_for_self() method.
*Note from cwebber on merge of this branch:*
Thanks also to Sturm who provided an early version of this patch.
---
mediagoblin/db/mixin.py | 6 ++++
mediagoblin/tests/__init__.py | 41 ++++++++++++++++++++++++++
mediagoblin/tests/test_modelmethods.py | 24 +++++++++++++++
3 files changed, 71 insertions(+)
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py
index 25ce6642..048cc07c 100644
--- a/mediagoblin/db/mixin.py
+++ b/mediagoblin/db/mixin.py
@@ -46,6 +46,12 @@ class UserMixin(object):
def bio_html(self):
return cleaned_markdown_conversion(self.bio)
+ def url_for_self(self, urlgen, **kwargs):
+ """Generate a URL for this User's home page."""
+ return urlgen('mediagoblin.user_pages.user_home',
+ user=self.username, **kwargs)
+
+
class GenerateSlugMixin(object):
"""
Mixin to add a generate_slug method to objects.
diff --git a/mediagoblin/tests/__init__.py b/mediagoblin/tests/__init__.py
index cf200791..fbf3fc6c 100644
--- a/mediagoblin/tests/__init__.py
+++ b/mediagoblin/tests/__init__.py
@@ -14,9 +14,50 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
+import pytest
+
+from mediagoblin.db.models import User
+from mediagoblin.tests.tools import fixture_add_user
+from mediagoblin.tools import template
+
def setup_package():
import warnings
from sqlalchemy.exc import SAWarning
warnings.simplefilter("error", SAWarning)
+
+
+class MGClientTestCase:
+
+ usernames = None
+
+ @pytest.fixture(autouse=True)
+ def setup(self, test_app):
+ self.test_app = test_app
+
+ if self.usernames is None:
+ msg = ('The usernames attribute should be overridden '
+ 'in the subclass')
+ raise pytest.skip(msg)
+ for username, options in self.usernames:
+ fixture_add_user(username, **options)
+
+ def user(self, username):
+ return User.query.filter(User.username == username).first()
+
+ def _do_request(self, url, *context_keys, **kwargs):
+ template.clear_test_template_context()
+ response = self.test_app.request(url, **kwargs)
+ context_data = template.TEMPLATE_TEST_CONTEXT
+ for key in context_keys:
+ context_data = context_data[key]
+ return response, context_data
+
+ def do_get(self, url, *context_keys, **kwargs):
+ kwargs['method'] = 'GET'
+ return self._do_request(url, *context_keys, **kwargs)
+
+ def do_post(self, url, *context_keys, **kwargs):
+ kwargs['method'] = 'POST'
+ return self._do_request(url, *context_keys, **kwargs)
diff --git a/mediagoblin/tests/test_modelmethods.py b/mediagoblin/tests/test_modelmethods.py
index 86513c76..ca436c76 100644
--- a/mediagoblin/tests/test_modelmethods.py
+++ b/mediagoblin/tests/test_modelmethods.py
@@ -20,9 +20,11 @@
from mediagoblin.db.base import Session
from mediagoblin.db.models import MediaEntry, User, Privilege
+from mediagoblin.tests import MGClientTestCase
from mediagoblin.tests.tools import fixture_add_user
import mock
+import pytest
class FakeUUID(object):
@@ -30,6 +32,8 @@ class FakeUUID(object):
UUID_MOCK = mock.Mock(return_value=FakeUUID())
+REQUEST_CONTEXT = ['mediagoblin/root.html', 'request']
+
class TestMediaEntrySlugs(object):
def _setup(self):
@@ -204,3 +208,23 @@ def test_media_data_init(test_app):
print repr(obj)
assert obj_in_session == 0
+
+class TestUserUrlForSelf(MGClientTestCase):
+
+ usernames = [(u'lindsay', dict(privileges=[u'active']))]
+
+ def test_url_for_self(self):
+ _, request = self.do_get('/', *REQUEST_CONTEXT)
+
+ assert self.user(u'lindsay').url_for_self(request.urlgen) == '/u/lindsay/'
+
+ def test_url_for_self_not_callable(self):
+ _, request = self.do_get('/', *REQUEST_CONTEXT)
+
+ def fake_urlgen():
+ pass
+
+ with pytest.raises(TypeError) as excinfo:
+ self.user(u'lindsay').url_for_self(fake_urlgen())
+ assert excinfo.errisinstance(TypeError)
+ assert 'object is not callable' in str(excinfo)
From e36bb0ee18e1209b747aab4ea4d2539872fd694f Mon Sep 17 00:00:00 2001
From: Christopher Allan Webber
Date: Thu, 10 Apr 2014 15:27:42 -0500
Subject: [PATCH 05/10] Adding Berker to the AUTHORS list
---
AUTHORS | 1 +
1 file changed, 1 insertion(+)
diff --git a/AUTHORS b/AUTHORS
index 6fbc05a7..8ea903f5 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -19,6 +19,7 @@ Thank you!
* Asheesh Laroia
* Bassam Kurdali
* Bernhard Keller
+* Berker Peksag
* Boris Bobrov
* Brandon Invergo
* Brett Smith
From 1c7875a18dfdde208f964e82f410edf33b89132b Mon Sep 17 00:00:00 2001
From: tilly-Q
Date: Fri, 29 Nov 2013 14:29:56 -0500
Subject: [PATCH 06/10] In this commit I made it so that each deployment can
have custom settings for which privileges are given to users when they are
intiated. These settings are modified in mediagoblin.ini.
---
mediagoblin.ini | 1 +
mediagoblin/auth/__init__.py | 1 -
mediagoblin/auth/tools.py | 14 +++++++++-----
mediagoblin/config_spec.ini | 3 +++
4 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/mediagoblin.ini b/mediagoblin.ini
index fe9d5cd2..216cfc43 100644
--- a/mediagoblin.ini
+++ b/mediagoblin.ini
@@ -35,6 +35,7 @@ allow_reporting = true
## If you want the terms of service displayed, you can uncomment this
# show_tos = true
+user_privilege_scheme= "uploader,commenter,reporter"
[storage:queuestore]
base_dir = %(here)s/user_dev/media/queue
diff --git a/mediagoblin/auth/__init__.py b/mediagoblin/auth/__init__.py
index be5d0eed..f518a09d 100644
--- a/mediagoblin/auth/__init__.py
+++ b/mediagoblin/auth/__init__.py
@@ -25,7 +25,6 @@ def create_user(register_form):
results = hook_runall("auth_create_user", register_form)
return results[0]
-
def extra_validation(register_form):
from mediagoblin.auth.tools import basic_extra_validation
diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py
index 88716e1c..191a2b9d 100644
--- a/mediagoblin/auth/tools.py
+++ b/mediagoblin/auth/tools.py
@@ -132,11 +132,7 @@ def register_user(request, register_form):
user = auth.create_user(register_form)
# give the user the default privileges
- default_privileges = [
- Privilege.query.filter(Privilege.privilege_name==u'commenter').first(),
- Privilege.query.filter(Privilege.privilege_name==u'uploader').first(),
- Privilege.query.filter(Privilege.privilege_name==u'reporter').first()]
- user.all_privileges += default_privileges
+ user.all_privileges += get_default_privileges(user)
user.save()
# log the user in
@@ -151,6 +147,14 @@ def register_user(request, register_form):
return None
+def get_default_privileges(user):
+ instance_privilege_scheme = mg_globals.app_config['user_privilege_scheme']
+ default_privileges = [Privilege.query.filter(
+ Privilege.privilege_name==privilege_name).first()
+ for privilege_name in instance_privilege_scheme.split(',')]
+ default_privileges = [privilege for privilege in default_privileges if not privilege == None]
+
+ return default_privileges
def check_login_simple(username, password):
user = auth.get_user(username=username)
diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index cc1ac637..a29b481e 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -89,6 +89,9 @@ upload_limit = integer(default=None)
# Max file size (in Mb)
max_file_size = integer(default=None)
+# Privilege scheme
+user_privilege_scheme = string(default="")
+
[jinja2]
# Jinja2 supports more directives than the minimum required by mediagoblin.
# This setting allows users creating custom templates to specify a list of
From f59d8bbef1d5ea492ae9898c0f7b5fdd94662f15 Mon Sep 17 00:00:00 2001
From: tilly-Q
Date: Mon, 28 Apr 2014 16:40:02 -0400
Subject: [PATCH 07/10] Fixed some minor whitespace issues
---
mediagoblin.ini | 2 +-
mediagoblin/auth/tools.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mediagoblin.ini b/mediagoblin.ini
index 216cfc43..4f94b6e4 100644
--- a/mediagoblin.ini
+++ b/mediagoblin.ini
@@ -35,7 +35,7 @@ allow_reporting = true
## If you want the terms of service displayed, you can uncomment this
# show_tos = true
-user_privilege_scheme= "uploader,commenter,reporter"
+user_privilege_scheme = "uploader,commenter,reporter"
[storage:queuestore]
base_dir = %(here)s/user_dev/media/queue
diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py
index 191a2b9d..39df85af 100644
--- a/mediagoblin/auth/tools.py
+++ b/mediagoblin/auth/tools.py
@@ -150,7 +150,7 @@ def register_user(request, register_form):
def get_default_privileges(user):
instance_privilege_scheme = mg_globals.app_config['user_privilege_scheme']
default_privileges = [Privilege.query.filter(
- Privilege.privilege_name==privilege_name).first()
+ Privilege.privilege_name==privilege_name).first()
for privilege_name in instance_privilege_scheme.split(',')]
default_privileges = [privilege for privilege in default_privileges if not privilege == None]
From b55b1ad4ad05177e47913e5ba070994ad3b3b654 Mon Sep 17 00:00:00 2001
From: tilly-Q
Date: Tue, 29 Apr 2014 12:44:21 -0400
Subject: [PATCH 08/10] Added new template hooks to allow for plugin-added
moderation powers
---
mediagoblin/templates/mediagoblin/base.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html
index b4c7eb8b..28b9c63c 100644
--- a/mediagoblin/templates/mediagoblin/base.html
+++ b/mediagoblin/templates/mediagoblin/base.html
@@ -165,6 +165,7 @@
{%- trans %}Report management panel{% endtrans -%}
+ {% template_hook("moderation_powers") %}
{% endif %}
{% include 'mediagoblin/fragments/header_notifications.html' %}
From ce26346a4c17a6e0b81ddd12046f67c4beaa8143 Mon Sep 17 00:00:00 2001
From: tilly-Q
Date: Thu, 1 May 2014 14:21:25 -0400
Subject: [PATCH 09/10] Changed the default permission scheme to be the same as
the scheme we use in master so that if admins have not set their
mediagoblin_local.ini to include this new option, they will notice no
difference in use.
---
mediagoblin/config_spec.ini | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index a29b481e..ba2b4519 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -90,7 +90,7 @@ upload_limit = integer(default=None)
max_file_size = integer(default=None)
# Privilege scheme
-user_privilege_scheme = string(default="")
+user_privilege_scheme = string(default="uploader,commenter,reporter")
[jinja2]
# Jinja2 supports more directives than the minimum required by mediagoblin.
From cabbd95a0d4a96a7a1022da0d5e0ac96c8d97a8c Mon Sep 17 00:00:00 2001
From: Jessica Tallon
Date: Mon, 5 May 2014 17:24:32 +0100
Subject: [PATCH 10/10] Add lib64/ directory to .gitignore file.
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index b2189f82..2524739f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
/build/
/eggs/
/lib/
+/lib64
/local/
/include/
/parts/