MARKUPWIKI_EDITOR/MODERATOR_TEST_FUNC options
This commit is contained in:
parent
85f2bac6fd
commit
20a483e754
@ -8,9 +8,15 @@ from markupfield.fields import MarkupField
|
|||||||
from markupfield import markup
|
from markupfield import markup
|
||||||
from markupwiki.utils import wikify_markup_wrapper
|
from markupwiki.utils import wikify_markup_wrapper
|
||||||
|
|
||||||
DEFAULT_MARKUP_TYPE = getattr(settings, 'MARKUPWIKI_DEFAULT_MARKUP_TYPE', 'markdown')
|
DEFAULT_MARKUP_TYPE = getattr(settings, 'MARKUPWIKI_DEFAULT_MARKUP_TYPE',
|
||||||
|
'markdown')
|
||||||
WRITE_LOCK_SECONDS = getattr(settings, 'MARKUPWIKI_WRITE_LOCK_SECONDS', 300)
|
WRITE_LOCK_SECONDS = getattr(settings, 'MARKUPWIKI_WRITE_LOCK_SECONDS', 300)
|
||||||
MARKUP_TYPES = getattr(settings, 'MARKUPWIKI_MARKUP_TYPES', markup.DEFAULT_MARKUP_TYPES)
|
MARKUP_TYPES = getattr(settings, 'MARKUPWIKI_MARKUP_TYPES',
|
||||||
|
markup.DEFAULT_MARKUP_TYPES)
|
||||||
|
EDITOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_EDITOR_TEST_FUNC',
|
||||||
|
lambda u: u.is_authenticated())
|
||||||
|
MODERATOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_MODERATOR_TEST_FUNC',
|
||||||
|
lambda u: u.is_staff)
|
||||||
|
|
||||||
# add make_wiki_links to MARKUP_TYPES
|
# add make_wiki_links to MARKUP_TYPES
|
||||||
WIKI_MARKUP_TYPES = []
|
WIKI_MARKUP_TYPES = []
|
||||||
@ -56,9 +62,9 @@ class Article(models.Model):
|
|||||||
|
|
||||||
def is_editable_by_user(self, user):
|
def is_editable_by_user(self, user):
|
||||||
if self.status in (LOCKED, DELETED):
|
if self.status in (LOCKED, DELETED):
|
||||||
return user.is_staff
|
return MODERATOR_TEST_FUNC(user)
|
||||||
else:
|
else:
|
||||||
return user.is_authenticated()
|
return EDITOR_TEST_FUNC(user)
|
||||||
|
|
||||||
def get_write_lock(self, user, release=False):
|
def get_write_lock(self, user, release=False):
|
||||||
cache_key = 'markupwiki_articlelock_%s' % self.id
|
cache_key = 'markupwiki_articlelock_%s' % self.id
|
||||||
|
@ -14,6 +14,11 @@ from markupwiki.forms import ArticleForm, StaffModerationForm, ArticleRenameForm
|
|||||||
CREATE_MISSING_ARTICLE = getattr(settings,
|
CREATE_MISSING_ARTICLE = getattr(settings,
|
||||||
'MARKUPWIKI_CREATE_MISSING_ARTICLES', True)
|
'MARKUPWIKI_CREATE_MISSING_ARTICLES', True)
|
||||||
|
|
||||||
|
EDITOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_EDITOR_TEST_FUNC',
|
||||||
|
lambda u: u.is_authenticated())
|
||||||
|
MODERATOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_MODERATOR_TEST_FUNC',
|
||||||
|
lambda u: u.is_staff)
|
||||||
|
|
||||||
def title_check(view):
|
def title_check(view):
|
||||||
def new_view(request, title, *args, **kwargs):
|
def new_view(request, title, *args, **kwargs):
|
||||||
newtitle = title.replace(' ', '_')
|
newtitle = title.replace(' ', '_')
|
||||||
@ -72,7 +77,7 @@ def view_article(request, title, n=None):
|
|||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
@title_check
|
@title_check
|
||||||
@login_required
|
@user_passes_test(EDITOR_TEST_FUNC)
|
||||||
def edit_article(request, title):
|
def edit_article(request, title):
|
||||||
''' edit (or create) an article
|
''' edit (or create) an article
|
||||||
|
|
||||||
@ -143,7 +148,7 @@ def edit_article(request, title):
|
|||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@user_passes_test(lambda u: u.is_staff)
|
@user_passes_test(MODERATOR_TEST_FUNC)
|
||||||
@title_check
|
@title_check
|
||||||
def article_status(request, title):
|
def article_status(request, title):
|
||||||
''' POST-only view to update article status (staff-only)
|
''' POST-only view to update article status (staff-only)
|
||||||
@ -155,7 +160,7 @@ def article_status(request, title):
|
|||||||
return redirect(article)
|
return redirect(article)
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@user_passes_test(lambda u: u.is_staff)
|
@user_passes_test(MODERATOR_TEST_FUNC)
|
||||||
@title_check
|
@title_check
|
||||||
def revert(request, title):
|
def revert(request, title):
|
||||||
''' POST-only view to revert article to a specific revision
|
''' POST-only view to revert article to a specific revision
|
||||||
@ -171,7 +176,7 @@ def revert(request, title):
|
|||||||
return redirect(article)
|
return redirect(article)
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@user_passes_test(lambda u: u.is_staff)
|
@user_passes_test(MODERATOR_TEST_FUNC)
|
||||||
@title_check
|
@title_check
|
||||||
def rename(request, title):
|
def rename(request, title):
|
||||||
''' POST-only view to rename article '''
|
''' POST-only view to rename article '''
|
||||||
|
Loading…
Reference in New Issue
Block a user