Permalink
Browse files

Removed all uses of the CMS_MODERATOR flag

Fixed tests to ensure that public and draft pages are used in the proper places.
  • Loading branch information...
1 parent 74bdf0a commit b76641be80782925f70cd67f30e5aaba3b793d18 @adaptivelogic adaptivelogic committed Oct 5, 2012
Showing with 513 additions and 757 deletions.
  1. +4 −43 cms/admin/change_list.py
  2. +0 −13 cms/admin/dialog/forms.py
  3. +4 −18 cms/admin/dialog/views.py
  4. +20 −63 cms/admin/pageadmin.py
  5. +1 −9 cms/admin/permissionadmin.py
  6. +22 −42 cms/api.py
  7. +5 −10 cms/appresolver.py
  8. +6 −16 cms/cms_toolbar.py
  9. +1 −1 cms/conf/__init__.py
  10. +0 −4 cms/conf/global_settings.py
  11. +3 −5 cms/forms/utils.py
  12. +2 −7 cms/management/commands/publisher_publish.py
  13. +18 −4 cms/management/commands/subcommands/moderator.py
  14. +2 −1 cms/menu.py
  15. +3 −10 cms/models/managers.py
  16. +0 −2 cms/models/metaclasses.py
  17. +43 −54 cms/models/pagemodel.py
  18. +0 −1 cms/models/permissionmodels.py
  19. +0 −2 cms/models/query.py
  20. +1 −1 cms/plugins/inherit/cms_plugins.py
  21. +1 −1 cms/sitemaps/cms_sitemap.py
  22. +1 −7 cms/templates/admin/cms/page/change_form.html
  23. +1 −1 cms/templatetags/cms_admin.py
  24. +1 −1 cms/templatetags/cms_tags.py
  25. +0 −1 cms/test_utils/cli.py
  26. +3 −3 cms/test_utils/fixtures/menus.py
  27. +1 −1 cms/test_utils/fixtures/navextenders.py
  28. +1 −1 cms/test_utils/fixtures/templatetags.py
  29. +23 −63 cms/tests/admin.py
  30. +39 −38 cms/tests/apphooks.py
  31. +28 −31 cms/tests/forms.py
  32. +1 −7 cms/tests/menu.py
  33. +0 −2 cms/tests/menu_page_viewperm.py
  34. +0 −1 cms/tests/menu_page_viewperm_staff.py
  35. +1 −2 cms/tests/multilingual.py
  36. +1 −2 cms/tests/navextender.py
  37. +3 −3 cms/tests/nested_plugins.py
  38. +23 −27 cms/tests/nonroot.py
  39. +98 −77 cms/tests/page.py
  40. +57 −75 cms/tests/permmod.py
  41. +2 −2 cms/tests/placeholder.py
  42. +40 −37 cms/tests/plugins.py
  43. +1 −11 cms/tests/publisher.py
  44. +0 −1 cms/tests/rendering.py
  45. +0 −1 cms/tests/templatetags.py
  46. +3 −11 cms/tests/toolbar.py
  47. +1 −2 cms/tests/views.py
  48. +0 −2 cms/utils/admin.py
  49. +13 −16 cms/utils/moderator.py
  50. +1 −2 cms/utils/page.py
  51. +30 −18 cms/utils/page_resolver.py
  52. +4 −4 cms/utils/permissions.py
View
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from cms.exceptions import NoHomeFound
-from cms.models import Title, Page, PageModerator
-from cms.models.moderatormodels import MASK_PAGE, MASK_CHILDREN, \
- MASK_DESCENDANTS, PageModeratorState
+from cms.models import Title, Page
from cms.utils.permissions import get_user_sites_queryset
from django.conf import settings
from django.contrib.admin.views.main import ChangeList, ALL_VAR, IS_POPUP_VAR, \
@@ -120,27 +118,7 @@ def set_items(self, request):
if perm_edit_ids and perm_edit_ids != Page.permissions.GRANT_ALL:
pages = pages.filter(pk__in=perm_edit_ids)
#pages = pages.filter(pk__in=perm_change_list_ids)
-
- if settings.CMS_MODERATOR:
- # get all ids of public instances, so we can cache them
- # TODO: add some filtering here, so the set is the same like page set...
- published_public_page_id_set = Page.objects.public().filter(published=True).values_list('id', flat=True)
-
- # get all moderations for current user and all pages
- pages_moderator_set = PageModerator.objects \
- .filter(user=request.user, page__site=self._current_site) \
- .values_list('page', 'moderate_page', 'moderate_children', 'moderate_descendants')
- # put page / moderations into singe dictionary, where key is page.id
- # and value is sum of moderations, so if he can moderate page and descendants
- # value will be MASK_PAGE + MASK_DESCENDANTS
- page_moderator = map(lambda item: (item[0], item[1] * MASK_PAGE + item[2] * MASK_CHILDREN + item[3] * MASK_DESCENDANTS), pages_moderator_set)
- page_moderator = dict(page_moderator)
-
- # page moderator states
- pm_qs = PageModeratorState.objects.filter(page__site=self._current_site)
- pm_qs.query.group_by = ['page_id']
- pagemoderator_states_id_set = pm_qs.values_list('page', flat=True)
-
+
ids = []
root_pages = []
pages = list(pages)
@@ -156,7 +134,6 @@ def set_items(self, request):
cache_tree_children(pages)
for page in pages:
-
children = list(page.get_children())
@@ -176,23 +153,7 @@ def set_items(self, request):
page.permission_publish_cache = perm_publish_ids == Page.permissions.GRANT_ALL or page.pk in perm_publish_ids
page.permission_advanced_settings_cache = perm_advanced_settings_ids == Page.permissions.GRANT_ALL or page.pk in perm_advanced_settings_ids
page.permission_user_cache = request.user
-
- if settings.CMS_MODERATOR:
- # set public instance existence state
- page.public_published_cache = page.publisher_public_id in published_public_page_id_set
-
- # moderation for current user
- moderation_value = 0
- try:
- moderation_value = page_moderator[page.pk]
- except:
- pass
- page._moderation_value_cache = moderation_value
- page._moderation_value_cache_for_user_id = request.user.pk
-
- #moderation states
- page._has_moderator_state_cache = page.pk in pagemoderator_states_id_set
-
+
if page.root_node or self.is_filtered():
page.last = True
if len(children):
@@ -222,7 +183,7 @@ def set_items(self, request):
page.childrens = []
else:
page.childrens = children
-
+
# TODO: OPTIMIZE!!
titles = Title.objects.filter(page__in=ids)
for page in all_pages:# add the title and slugs and some meta data
View
@@ -9,16 +9,3 @@ class PermissionForm(forms.Form):
copy_permissions = forms.BooleanField(label=_('Copy permissions'),
required=False, initial=True)
-class ModeratorForm(forms.Form):
- '''
- Holds the specific field for moderator
- '''
- copy_moderation = forms.BooleanField(label=_('Copy moderation'),
- required=False, initial=True)
-
-class PermissionAndModeratorForm(PermissionForm, ModeratorForm):
- '''
- Subclass of both ModeratorForm AND PermissionForm, thus it inherits both
- fields
- '''
- pass
View
@@ -1,40 +1,26 @@
# -*- coding: utf-8 -*-
-from cms.admin.dialog.forms import PermissionAndModeratorForm, PermissionForm, ModeratorForm
+from cms.admin.dialog.forms import PermissionForm
from cms.models import Page
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.http import Http404, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
-def _form_class_selector():
- '''
- This replaces the magic that used to happen in forms, where a dynamic
- class was generated at runtime. Now it's a bit cleaner...
- '''
- form_class = None
- if settings.CMS_PERMISSION and settings.CMS_MODERATOR:
- form_class = PermissionAndModeratorForm
- elif settings.CMS_PERMISSION:
- form_class = PermissionForm
- elif settings.CMS_MODERATOR:
- form_class = ModeratorForm
- return form_class
-
@staff_member_required
def get_copy_dialog(request, page_id):
- if not (settings.CMS_PERMISSION or settings.CMS_MODERATOR):
+ if not settings.CMS_PERMISSION:
return HttpResponse('')
page = get_object_or_404(Page, pk=page_id)
target = get_object_or_404(Page, pk=request.REQUEST['target'])
if not page.has_change_permission(request) or \
- not target.has_add_permission(request): # pragma: no cover
+ not target.has_add_permission(request):
raise Http404
context = {
'dialog_id': 'dialog-copy',
- 'form': _form_class_selector()(), # class needs to be instanciated
+ 'form': PermissionForm(), # class needs to be instantiated
'callback': request.REQUEST['callback'],
}
return render_to_response("admin/cms/page/dialog/copy.html", context)
View
@@ -20,10 +20,8 @@
from cms.utils.i18n import get_language_dict, get_language_list, get_language_tuple, get_language_object
from cms.utils.page_resolver import is_valid_url
from cms.utils.admin import jsonify_request
-from cms.utils.permissions import has_plugin_permission
from copy import deepcopy
from distutils.version import LooseVersion
-from django import template
from django.conf import settings
from django.contrib import admin
from django.contrib.admin.options import IncorrectLookupParameters
@@ -35,7 +33,7 @@
from django.db import router, transaction, models
from django.forms import CharField
from django.http import (HttpResponseRedirect, HttpResponse, Http404,
- HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed, HttpResponseServerError)
+ HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed)
from django.shortcuts import render_to_response, get_object_or_404
from django.template.context import RequestContext
from django.template.defaultfilters import (title, escape, force_escape,
@@ -88,8 +86,6 @@ def contribute_fieldsets(cls):
general_fields.append('publication_date')
elif settings.CMS_SHOW_END_DATE:
general_fields.append( 'publication_end_date')
- if settings.CMS_MODERATOR:
- additional_hidden_fields += ['moderator_state', 'moderator_message']
if settings.CMS_SEO_FIELDS:
seo_fields = ['page_title', 'meta_description', 'meta_keywords']
if not settings.CMS_URL_OVERWRITE:
@@ -137,8 +133,6 @@ def contribute_fieldsets(cls):
def contribute_list_filter(cls):
list_filter = ['published', 'in_navigation', 'template', 'changed_by']
- if settings.CMS_MODERATOR:
- list_filter.append('moderator_state')
if settings.CMS_SOFTROOT:
list_filter.append('soft_root')
setattr(cls, 'list_filter', list_filter)
@@ -211,7 +205,6 @@ def get_urls(self):
pat(r'^([0-9]+)/permissions/$', self.get_permissions),
pat(r'^([0-9]+)/moderation-states/$', self.get_moderation_states),
pat(r'^([0-9]+)/change-moderation/$', self.change_moderation),
- pat(r'^([0-9]+)/approve/$', self.approve_page), # approve page
pat(r'^([0-9]+)/publish/$', self.publish_page), # publish page
pat(r'^([0-9]+)/remove-delete-state/$', self.remove_delete_state),
pat(r'^([0-9]+)/dialog/copy/$', get_copy_dialog), # copy dialog
@@ -489,15 +482,6 @@ def get_formsets(self, request, obj=None):
def add_view(self, request, form_url='', extra_context=None):
extra_context = extra_context or {}
- if settings.CMS_MODERATOR and 'target' in request.GET and 'position' in request.GET:
- moderation_required = moderator.will_require_moderation(
- request.GET['target'], request.GET['position']
- )
- extra_context.update({
- 'moderation_required': moderation_required,
- 'moderation_level': _('higher'),
- 'show_save_and_continue':True,
- })
language = get_language_from_request(request)
extra_context.update({
'language': language,
@@ -517,10 +501,9 @@ def change_view(self, request, object_id, extra_context=None):
obj = None
else:
selected_template = get_template_from_request(request, obj)
- moderation_level, moderation_required = moderator.get_test_moderation_level(obj, request.user)
# if there is a delete request for this page
- moderation_delete_request = (settings.CMS_MODERATOR and
+ moderation_delete_request = (
obj.pagemoderatorstate_set.get_delete_actions(
).count())
@@ -530,14 +513,8 @@ def change_view(self, request, object_id, extra_context=None):
'placeholders': self.get_fieldset_placeholders(selected_template),
'page': obj,
'CMS_PERMISSION': settings.CMS_PERMISSION,
- 'CMS_MODERATOR': settings.CMS_MODERATOR,
'ADMIN_MEDIA_URL': settings.STATIC_URL,
'has_change_permissions_permission': obj.has_change_permissions_permission(request),
- 'has_moderate_permission': obj.has_moderate_permission(request),
- 'moderation_level': moderation_level,
- 'moderation_required': moderation_required,
- 'moderator_should_approve': moderator.moderator_should_approve(request, obj),
- 'moderation_delete_request': moderation_delete_request,
'show_delete_translation': len(obj.get_languages()) > 1,
'current_site_id': settings.SITE_ID,
}
@@ -585,10 +562,9 @@ def response_change(self, request, obj):
some new stuff, which should be published after all other objects on page
are collected.
"""
- if settings.CMS_MODERATOR:
- # save the object again, so all the related changes to page model
- # can be published if required
- obj.save()
+ # save the object again, so all the related changes to page model
+ # can be published if required
+ obj.save()
return super(PageAdmin, self).response_change(request, obj)
def has_add_permission(self, request):
@@ -690,7 +666,6 @@ def changelist_view(self, request, extra_context=None):
'CMS_MEDIA_URL': settings.CMS_MEDIA_URL,
'softroot': settings.CMS_SOFTROOT,
'CMS_PERMISSION': settings.CMS_PERMISSION,
- 'CMS_MODERATOR': settings.CMS_MODERATOR,
'has_recover_permission': 'reversion' in settings.INSTALLED_APPS and self.has_recover_permission(request),
'DEBUG': settings.DEBUG,
'site_languages': languages,
@@ -832,7 +807,6 @@ def copy_page(self, request, page_id, extra_context=None):
try:
kwargs = {
'copy_permissions': request.REQUEST.get('copy_permissions', False),
- 'copy_moderation': request.REQUEST.get('copy_moderation', False),
}
page.copy_page(target, site, position, **kwargs)
return jsonify_request(HttpResponse("ok"))
@@ -842,50 +816,31 @@ def copy_page(self, request, page_id, extra_context=None):
return HttpResponseRedirect('../../')
def get_moderation_states(self, request, page_id):
- """Returns moderation messsages. Is loaded over ajax to inline-group
+ """Returns moderation messages. Is loaded over ajax to inline-group
element in change form view.
"""
page = get_object_or_404(Page, id=page_id)
- if not page.has_moderate_permission(request):
- raise Http404()
-
context = {
'page': page,
}
return render_to_response('admin/cms/page/moderation_messages.html', context)
@transaction.commit_on_success
- def approve_page(self, request, page_id):
- """Approve changes on current page by user from request.
- """
- #TODO: change to POST method !! get is not safe
+ def publish_page(self, request, page_id):
page = get_object_or_404(Page, id=page_id)
- if not page.has_moderate_permission(request):
- raise Http404()
-
- moderator.approve_page(request, page)
+ # ensure user has permissions to publish this page
+ if not page.has_publish_permission(request):
+ return HttpResponseForbidden("Denied")
+ page.publish()
# Django SQLite bug. Does not convert to string the lazy instances
from django.utils.translation import ugettext as _
- self.message_user(request, _('Page was successfully approved.'))
+ self.message_user(request, _('Page was successfully published.'))
if 'node' in request.REQUEST:
# if request comes from tree..
return admin_utils.render_admin_menu_item(request, page)
- referer = request.META.get('HTTP_REFERER', reverse('admin:cms_page_changelist'))
- path = '../../'
- if 'admin' not in referer:
- path = '%s?edit-off' % referer.split('?')[0]
- return HttpResponseRedirect( path )
-
- @transaction.commit_on_success
- def publish_page(self, request, page_id):
- page = get_object_or_404(Page, id=page_id)
- # ensure user has permissions to publish this page
- if not page.has_moderate_permission(request):
- return HttpResponseForbidden("Denied")
- page.publish()
referer = request.META.get('HTTP_REFERER', '')
path = '../../'
# TODO: use admin base here!
@@ -895,15 +850,15 @@ def publish_page(self, request, page_id):
def delete_view(self, request, object_id, *args, **kwargs):
- """If page is under modaretion, just mark this page for deletion = add
+ """If page is under moderation, just mark this page for deletion = add
delete action to page states.
"""
page = get_object_or_404(Page, id=object_id)
if not self.has_delete_permission(request, page):
raise PermissionDenied
- if page.is_under_moderation():
+ if page.published:
# don't perform a delete action, just mark page for deletion
page.force_moderation_action = PageModeratorState.ACTION_DELETE
page.moderator_state = Page.MODERATOR_NEED_DELETE_APPROVEMENT
@@ -1395,17 +1350,19 @@ def remove_plugin(self, request):
placeholder = plugin.placeholder
page = placeholder.page if placeholder else None
- if page and not page.has_change_permission(request):
- raise Http404
+ if page:
+ if not page.publisher_is_draft:
+ raise Http404
+ if not page.has_change_permission(request):
+ raise HttpResponseForbidden(ugettext("You have no permission to remove a plugin"))
- if page and settings.CMS_MODERATOR and page.is_under_moderation():
# delete the draft version of the plugin
plugin.delete()
# set the page to require approval and save
page.moderator_state = Page.MODERATOR_NEED_APPROVEMENT
page.save()
else:
- plugin.delete_with_public()
+ plugin.delete()
plugin_name = unicode(plugin_pool.get_plugin(plugin.plugin_type).name)
comment = ugettext(u"%(plugin_name)s plugin at position %(position)s in %(placeholder)s was deleted.") % {
@@ -78,8 +78,6 @@ def get_formset(self, request, obj=None, **kwargs):
exclude.append('can_change_advanced_settings')
if not obj.has_move_page_permission(request):
exclude.append('can_move_page')
- if not settings.CMS_MODERATOR or not obj.has_moderate_permission(request):
- exclude.append('can_moderate')
formset_cls = super(PagePermissionInlineAdmin, self
).get_formset(request, obj=None, exclude=exclude, *kwargs)
qs = self.queryset(request)
@@ -96,7 +94,7 @@ class ViewRestrictionInlineAdmin(PagePermissionInlineAdmin):
exclude = [
'can_add', 'can_change', 'can_delete', 'can_view',
'can_publish', 'can_change_advanced_settings', 'can_move_page',
- 'can_moderate', 'can_change_permissions'
+ 'can_change_permissions'
]
def get_formset(self, request, obj=None, **kwargs):
@@ -133,12 +131,6 @@ class GlobalPagePermissionAdmin(admin.ModelAdmin):
list_display.append('can_change_advanced_settings')
list_filter.append('can_change_advanced_settings')
-
- if settings.CMS_MODERATOR:
- list_display.append('can_moderate')
- list_filter.append('can_moderate')
- else:
- exclude.append('can_moderate')
class GenericCmsPermissionAdmin(object):
Oops, something went wrong.

0 comments on commit b76641b

Please sign in to comment.